forked from Mirrors/openclonk
Add property to auto-save EditorProps in scenarios
parent
db1e9abbe3
commit
e39b314239
|
@ -526,6 +526,19 @@ func SaveScenarioObject(props)
|
|||
</row>
|
||||
</table>
|
||||
</text>
|
||||
<text>Properties published to the editor as EditorProps can also be saved automatically by setting the SaveAsCall property of the EditorProp to a string for the setter-function to call or setting SaveAsSet to true for saving directly to the property. These properties are atuomatically saved if they are different from their default value. E.g.:</text>
|
||||
<code>/* Define two properties that can be set in the editor */
|
||||
// foo is a property with a setter function
|
||||
local foo = 42;
|
||||
public func SetFoo(new_foo) { foo = new_foo; return true; }
|
||||
|
||||
// bar is just a property without setter
|
||||
local bar = 23;
|
||||
|
||||
local EditorProps = {
|
||||
foo = { Type="int", SaveAsCall="SetFoo" }; // saved as object->SetFoo(value); unless foo is 42.
|
||||
bar = { Type="int", SaveAsSet=true; } // saved as object.bar = value; unless bar is 23.
|
||||
};</code>
|
||||
<text>By default, effects are not saved in scenarios. To force saving of an effect, define the Fx*SaveScen callback. For example, the fire effect saves itself like this:</text>
|
||||
<code>global func FxFireSaveScen(object obj, proplist fx, proplist props)
|
||||
{
|
||||
|
|
|
@ -412,6 +412,30 @@ global func SaveScenarioObject(props)
|
|||
// Effects
|
||||
var fx; i=0;
|
||||
while (fx = GetEffect("*", this, i++)) EffectCall(this, fx, "SaveScen", props);
|
||||
// EditorProps
|
||||
if (this.EditorProps)
|
||||
{
|
||||
var all_prop_names = GetProperties(this.EditorProps), prop_save, prop_name, prop;
|
||||
for (prop_name in all_prop_names)
|
||||
{
|
||||
if ((prop=this.EditorProps[prop_name]))
|
||||
{
|
||||
if (GetType(prop) == C4V_PropList)
|
||||
{
|
||||
v = this[prop_name];
|
||||
var default_v = GetID()[prop_name];;
|
||||
if ((prop_save = prop.SaveAsCall))
|
||||
{
|
||||
if (!DeepEqual(v, default_v)) props->AddCall("EditorProp", this, prop_save, SaveScenarioValue2String(v));
|
||||
}
|
||||
else if (prop.SaveAsSet)
|
||||
{
|
||||
if (!DeepEqual(v, default_v)) props->AddSet("EditorProp", this, prop_name, SaveScenarioValue2String(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue