HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: 10 Step Spec Dec Checklist (A Summary)  (Read 1336 times)

_Omzy_

  • General Accounts
  • *
  • Posts: 24
    • View Profile
10 Step Spec Dec Checklist (A Summary)
« on: Dec 27, 14, 01:33:55 AM »

Volume 2/2, hope this helps more people understand the spec system enough to be able to use it. It really is logical and time efficient once you get going.

*Use the 10 Step Spec Checklist first!

10 Step Spec Dec Checklist
For your first spec, See Spec System - Basic Usage, Spec System - Advanced Usage, Creating a New Spec Oracle (Step by Step), HeroEngine Data Storage Tutorial - Spec System 3, and HeroEngine Data Storage Tutorial - Spec System 4

I highly suggest creating TemplateSpecDecoratorClassMethods, TemplateSpecDecoratorHelperClassMethods, TemplateSpecAnchorClassMethods, and TemplateSpecManagerClassMethods scripts after following the video series above.
1. (Optional) If you want to use the anchor<>manager setup as described in the videos, continue here. If not, jump to step 7.
2. Create the manager and anchor classes on both the server and client (FooManager and FooAnchor). You may choose to reflect both by setting Destination Classes
3. Create fooAnchorRef fields on the server and client as NodeRefs of Class FooAnchor
4. Add the fooAnchorRef field to the manager on server and client
5. Make FooManager a parent of the class that you wish to anchor Foo (this gives that node control of its own specDerivedObject and decorator helpers after instantiation)
6. Open both class methods scripts (s only) using the matching templates that you created from the videos. Fix default strings to include Foo, compile and submit

7. Using the DOM editor, create the spec decorator and decorator helper classes (FooBar for instantiated nodes only) on both the server and client (FooBarDec and FooBar)
8. Add FooBarDec as a parent of FooBar only if you want it to have access to FooBarDec’s immutable fields
9. Open both (or only FooBarDec’s) class methods scripts (s only) using the matching templates that you created from the videos. Fix default strings to include FooBar, ‘add back’ FooBarDec to getSpecDecoratorClasses() in FooSpecOracleClassMethods (s only), compile and submit
10. If you chose to give your decorator helper a shared OnActivate method, ensure that it is activated from your manager's AddFoo method if you have one

Happy system building!

*Move on to the Advanced Spec Oracle Property Editor Tutorial!

Edit: Bonus templates for all! ( thank Christopher for these, they are modified from his videos :D )
*Replace 'REPLACEDefault' with Foo, 'REPLACEdefault' with foo, 'Helper' with Bar*

TemplateSpecDecoratorClassMethods(s) (update1)
Code: [Select]
shared function OnInstantiationFromSpec( derivedObject as NodeRef )
// Shared function called in the base and decorator classes of a spec when an object is instantiated
//   do any initialization/setup required by the decorator class
  if not ( derivedObject is kindof REPLACEDefaultHelper )
    GlomClass( "REPLACEDefaultHelper", derivedObject )
    //other construction stuff here
    where derivedObject is kindof REPLACEDefaultHelper
      mySpec as NodeRef of Class REPLACEDefaultHelperDec = derivedObject.GetMySpec()
      //init mutable AND immutable values here
    .
  .
.

TemplateSpecDecoratorHelperClassMethods(s)
Code: [Select]
//Call this from scripts to actually engage the helper for the glommed character type
method ActivateREPLACEDefaultHelper()
  //This code runs every activator, use in conjunction with activation in manager if you wish
  //decorators as List of ScriptRef = QueryNodeScriptsWithFunction(me, "OnActivate")
 
  //foreach d in decorators
  //  d:OnActivate( me )
  //. Use the next line if not using this block
  OnActivate ( me )
.

//Implement in helper classes to respond to activation event
shared function OnActivate ( REPLACEdefault as NodeRef of Class REPLACEDefault )
  //Activation code
.

TemplateSpecAnchorClassMethods(s)
Code: [Select]
method AddREPLACEDefaultToAnchor (REPLACEdefault as NodeRef of Class REPLACEDefault) as Boolean
  if me.AnchorHasREPLACEDefault(REPLACEdefault.SpecKey) //Prevents duplicate
    ScriptError ( "Anchor already had REPLACEdefault!" )
    return false
  .
 
  AddAssociation( me, "base_hard_association", REPLACEdefault )
  return true
.

method RemoveREPLACEDefaultFromAnchor (REPLACEdefault as NodeRef of Class REPLACEDefault) as Boolean

  if not me.AnchorHasREPLACEDefault(REPLACEdefault.SpecKey)
    ScriptError ( "Anchor didn't have REPLACEdefault to remove" )
    return false
  .

//$CHAT.ChatArea("game" , "[Script] Removed REPLACEdefault with spec_key: " + REPLACEdefault.SpecKey + " from anchor " + me )   
  DestroyNode( REPLACEdefault )
  return true
.

method AnchorHasREPLACEDefault (spec_key as ID) as Boolean
  foreach REPLACEdefault in QueryAssociationTargetsByClass(me, "base_hard_association", "REPLACEDefault")
    where REPLACEdefault is kindof REPLACEDefault
      if REPLACEdefault.SpecKey = spec_key
        return true
      .
    .
  .
 
  return false
.

TemplateSpecManagerClassMethods(s) (update1)
Code: [Select]
method GetREPLACEDefaultAnchor() as NodeRef of Class REPLACEDefaultAnchor
  REPLACEdefault_anchor as NodeRef of Class REPLACEDefaultAnchor
 
  if me.REPLACEdefaultAnchorRef != None
    REPLACEdefault_anchor = me.REPLACEdefaultAnchorRef
  else
    REPLACEdefault_anchor = QueryAssociationOneTargetByClass( me, "base_hard_association", "REPLACEDefaultAnchor")
  .
 
  // none created, so create one
  if REPLACEdefault_anchor = None
    REPLACEdefault_anchor = CreateNodeFromClass ("REPLACEDefaultAnchor")
    AddAssociation(me, "base_hard_association", REPLACEdefault_anchor)
    me.REPLACEdefaultAnchorRef = REPLACEdefault_anchor
  .
 
  return REPLACEdefault_anchor
.

method AddREPLACEDefault ( spec_key as ID ) as NodeRef of Class REPLACEDefault
  REPLACEdefault as NodeRef of Class REPLACEDefault
  oracle as NodeRef of Class REPLACEDefaultSpecOracle = getprototype ("REPLACEDefaultSpecOracle")
  spec as NodeRef of Class REPLACEDefaultSpec = oracle.GetSpecByKey( spec_key )
 
  if spec != None
    REPLACEdefault = spec.CreateFromSpec()
  .
 
  REPLACEdefault_anchor as NodeRef of Class REPLACEDefaultAnchor = me.GetREPLACEDefaultAnchor()
  if not REPLACEdefault_anchor.AddREPLACEDefaultToAnchor( REPLACEdefault )
    ScriptError( "Unable to add REPLACEdefault!" )
  else
    where REPLACEdefault is kindof REPLACEDefaultHelper //Activatable Spec Decs here
      REPLACEdefault.ActivateREPLACEDefaultHelper()
    .   
  .
 
  return REPLACEdefault
.

method RemoveREPLACEDefault ( spec_key as ID ) as Boolean
  REPLACEdefault as NodeRef of Class REPLACEDefault = me.GetREPLACEDefaultByKey( spec_key )
  REPLACEdefault_anchor as NodeRef of Class REPLACEDefaultAnchor = me.GetREPLACEDefaultAnchor()
  if REPLACEdefault != None
     return REPLACEdefault_anchor.RemoveREPLACEDefaultFromAnchor ( REPLACEdefault )
  else
     ScriptError ( "Caller did not have REPLACEdefault to remove" )
     return false
  .
 
  ScriptError ( "Unable to remove REPLACEdefault!" )
  return false
.


//returns the REPLACEdefault if it exists or None
method GetREPLACEDefaultByKey ( spec_key as ID ) as NodeRef of Class REPLACEDefault
  REPLACEdefault_anchor as NodeRef of Class REPLACEDefaultAnchor = me.GetREPLACEDefaultAnchor()
  foreach REPLACEdefault in QueryAssociationTargetsByClass( REPLACEdefault_anchor, "base_hard_association", "REPLACEDefault")
    if REPLACEdefault.GetMySpecKey() = spec_key
      return REPLACEdefault
    .
  .
  return None
.
« Last Edit: Jan 05, 15, 08:30:24 PM by _Omzy_ »
Logged
-OMZY-
Odyssey of Ydris