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

Author Topic: Advanced Spec Oracle Property Editor Tutorial  (Read 2084 times)


  • General Accounts
  • *
  • Posts: 24
    • View Profile
Advanced Spec Oracle Property Editor Tutorial
« on: Jan 04, 15, 06:41:33 PM »

This tutorial will allow you to create a spec oracle property editor that supports spec selector fields and list of custom class fields. These controls are often necessary components of a sophisticated and flexible system design. If you have not yet learned how to create a spec oracle with spec decorators, make sure to master that first.

*See the 10 Step Spec Checklist and the 10 Step Spec Dec Checklist first!

Advanced Spec Oracle Property Editor Tutorial

This tutorial assumes that you have created a working spec (FooSpec) with:
* a decorator class (FooBarDec) with a field (FooBarList) that is a list of a class (FooBarItem) which is composed of non-class fields (FooBarItemField1-5)
* a decorator class (FooBar2Dec) with fields (FooBar2Field1-2)

The hierarchy for the default system should look like this:
___*FooSpec (spec)
______*FooBarDec (spec decorator containing custom class list)
_________*FooBarList (list of class FooBarItem)
____________*FooBarItem (class)
_______________*FooBarItemField1 (id, for spec dropdown)
_______________*FooBarItemField2 (string, for spec dropdown)
_______________*FooBarItemField3 (enum Field3Enum)
_______________*FooBarItemField4 (float)
_______________*FooBarItemField5 (enum Field5Enum)
______*FooBar2Dec (spec decorator invoking spec selector)
_________*FooBar2Field1 (id)
_________*FooBar2Field2 (name)
______*FooBar3Dec (simple spec decorator)
_________*FooBar3Field1 (float)
_________*FooBar3Field2 (timerinterval)
_________*FooBar3Field3 (string)
______etc (more decorators)
___*FooSpecOraclePropertyEditor (property editor)
______*Foo1Foo2SpecList (list of string, Foo1 is just Foo from above)

From HJRef
Follow this section once per world:
1. Copy the following clientside scripts from HJRef: GUIutils, GUIFormHandling
2. Copy the following clientside classes (and ALL of their unique fields) from HJRef: GUIForm, GUIFormData, GUIFormRow, selectBoxItem
4. Copy the following guicontrols from HJRef: form, _submitButton (remove the animation property to prevent a script error)

Your World
Follow this section for each spec oracle that you create (rinse and repeat):
1. Create FooSpecOraclePropertyEditor(C) as guicontrol data type with parent as SpecOraclePropertyEditor(C).
2. Make a GUI prototype using the following XML which inherits from the SpecOraclePropertyEditor prototype but uses the FooSpecOraclePropertyEditor class
Code: [Select]
<createControlType inheritFrom='SpecOraclePropertyEditor' type='FooSpecOraclePropertyEditor' description='Property editor for foo spec' treePath='BuildingBlocks\Windows' name="FooSpecOraclePropertyEditor" glomClass="FooSpecOraclePropertyEditor">
3. Add a Foo1Foo2SpecList list of string field to your FooSpecOraclePropertyEditor (this caches the spec names and id’s for your field which invokes the spec selector, hence the Foo1Foo2, e.g. if you have an Effect spec that grabs a Stat spec, it would be EffectStatSpecList)
4. Copy the clientside template class method scripts below to your FooSpec(C) and FooSpecOraclePropertyEditor(C) classes
5. Replace all strings containing ‘REPLACE’ with yours. E.g. REPLACEDefault1Helper1 with FooBar, REPLACEDefault1Helper1ItemField1 with FooBarItem<yourfield>, etc (see the instructions at the top of each script for more detailed instructions on replacement).
6. Go function by function and follow the commented instructions above each function to customize your property editor to your spec structure

Default Spec Prototype (optional)
Follow this section if you want the spec property editor to pre-populate with a set of default values upon adding a new spec entry (rinse and repeat for each spec dec):
1. For each spec decorator, you must create a new prototype with the name FooSpecDecOnGLOMDefaultValues. This is a special name that will be checked by the engine before GLOM’ing the dec to the spec entry
2. To do this type into the console (*spaces are important):
___a. \cpfc FooSpecDec, FooSpecDecOnGLOMDefaultValues; description=”Default values prototype for FooSpecDec”
___b. \mp FooSpecDecOnGLOMDefaultValues; Field1=”myvalue” Field2=45 Field3=FALSE
3. Tailor the above commands to your spec decorator's field structure. Repeat these commands with ‘|’ to add the values to the client as well.
4. To set up default values for a custom class, add a list of string field named FooSpecListDefaults to the server and clientside spec decorator class. You can use the \MLP command to modify this custom class' defaults list. See the MLP command. The syntax is "\mlp FooSpecDecOnGLOMDefaultValues FooSpecListDefaults;insert 1 "2:Fireball,harmful,5", for example, if your custom class references the 2nd spec entry named Fireball which is harmful and has a damage of 5. These obviously depend on the custom class structure you've setup. This FooSpecListDefaults list must be parsed when your spec decorator is GLOM'd and requires that you add the following code snippet to your FooSpecDecClassMethods script and change the strings to fit your custom class:

Code: [Select]
shared function _OnGlomClass( n as NodeRef ) //Add default values from FooSpecListDefaults
  where n is kindof FooSpecDec
    foreach itemString in n.FooSpecListDefaults
      if itemString <> ""
        itemFields as List of String
        SplitBy( itemString, ",", itemFields )
        i as Integer
        foreach itemField in itemFields
          specSeparator as Integer = FindString( itemField, ":" )
          if specSeparator > 0
            specFields as List of String
            SplitBy( itemField, ":", specFields )
            remove itemFields at i
            insert specFields[2] to itemFields at i //Name
            insert specFields[1] to itemFields at i //ID
        item as Class FooSpecItem //Make sure to modify these to fit your custom class structure
        item.FooSpecItemSpecID = itemFields[1]
        item.FooSpecItemSpecName = itemFields[2]
        item.FooSpecItemType = itemFields[3]
        item.FooSpecItemDmg = itemFields[4]
        add back item to n.FooSpecList //Note this is different from the FooSpecListDefaults list


-->Download (update3)<--
« Last Edit: May 27, 15, 02:50:51 PM by _Omzy_ »
Odyssey of Ydris