| 1 | [KEEP IN SYNC WITH SYNCHEDJSOBJECT.H] |
| 2 | |
| 3 | Author: Simon Brenner <simon.brenner@home.se> |
| 4 | |
| 5 | |
| 6 | = Description = |
| 7 | A helper class for [wiki:!ScriptableObject CJSObject] that enables a callback to be called whenever an attribute of the class changes and enables all (synched) properties to be set and retrieved as strings for network sync. |
| 8 | |
| 9 | All string conversions are performed by specific functions that use a strictly (hrm) defined format - or at least a format that is specific for the type in question (which is why JSParseString can't be used - the JS interface's !ToString function is also not usable since it often produces a human-readable format that doesn't parse well and might change outside the control of the network protocol). |
| 10 | |
| 11 | This replaces CAttributeMap for both player and game attributes. |
| 12 | |
| 13 | |
| 14 | = Usage = |
| 15 | First you must create your subclass, make it inherit from CSynchedJSObject and implement the pure virtual method Update (see prototype below). |
| 16 | |
| 17 | Then you may use it just like [wiki:!ScriptableObject CJSObject] - with one exception: Any property you want to be synchronized (i.e. have the new property functionality including the update callback) is added using the !AddSynchedProperty method instead: !AddSynchedProperty(name, &m_Property). |
| 18 | |
| 19 | The extra arguments that exist in the !AddProperty method haven't been implemented. (if you by any chance would need to, just do it ;-) |
| 20 | |
| 21 | |
| 22 | = CSynchedJSObject Methods = |
| 23 | |
| 24 | |
| 25 | == Update == |
| 26 | * '''Overview:''' |
| 27 | * Called every time a property changes. |
| 28 | * '''Syntax:''' |
| 29 | * void Update(CStrW name, ISynchedJSProperty* property) |
| 30 | * '''Parameters:''' |
| 31 | * name [CStrW], property [ISynchedJSProperty*] |
| 32 | * '''Returns:''' |
| 33 | * |
| 34 | * '''Notes:''' |
| 35 | * This is where the individual callbacks are dispatched from. |
| 36 | |
| 37 | |
| 38 | == !AddSynchedProperty == |
| 39 | * '''Overview:''' |
| 40 | * Add a property to the object; if desired, a callback is called every time it changes. |
| 41 | * '''Example:''' |
| 42 | * !AddSynchedProperty(L"numSlots", &m_NumSlots, &CGameAttributes::!OnNumSlotsUpdate); |
| 43 | * '''Parameters:''' |
| 44 | * name [CStrW], native [templated], update callback [!UpdateFn] (optional) |
| 45 | * '''Returns:''' |
| 46 | * |
| 47 | * '''Notes:''' |
| 48 | * Replaces CJSObject's !AddProperty. |