private JSONObject GetBehaviorJSON(Perso perso, BehaviorOrMacro behavior, AIModel model, Behavior.BehaviorType?type, int index, bool includeScriptContents) { JSONObject behaviorJSON = new JSONObject(); string name; if (behavior is Macro) { Macro m = behavior as Macro; name = m.GetShortName(model, index); if (m.script == null) { name += " (null)"; } if (m.script != null) { behaviorJSON["script"] = GetScriptJSON(perso, m.script, includeScriptContents); } behaviorJSON["type"] = "Macro"; } else { Behavior b = behavior as Behavior; name = b.GetShortName(model, type.Value, index); JSONArray scripts = new JSONArray(); foreach (Script script in b.scripts) { if (script != null) { scripts.Add(GetScriptJSON(perso, script, includeScriptContents)); } } behaviorJSON["scripts"] = scripts; behaviorJSON["type"] = b.type.ToString(); if (b.firstScript != null) { behaviorJSON["firstScript"] = GetScriptJSON(perso, b.firstScript, includeScriptContents); } } behaviorJSON["name"] = name; return(behaviorJSON); }
public static Script Read(Reader reader, Pointer offset, BehaviorOrMacro behaviorOrMacro, bool single = false) { MapLoader l = MapLoader.Loader; Script s = new Script(offset); s.behaviorOrMacro = behaviorOrMacro; if (Settings.s.game == Settings.Game.R2Revolution && single) { s.off_script = Pointer.Current(reader); bool endReached = false; while (!endReached) { ScriptNode sn = ScriptNode.Read(reader, Pointer.Current(reader), s); s.scriptNodes.Add(sn); if (sn.indent == 0) { endReached = true; } } } else { s.off_script = Pointer.Read(reader); //l.print(s.off_script); Pointer.DoAt(ref reader, s.off_script, () => { bool endReached = false; while (!endReached) { ScriptNode sn = ScriptNode.Read(reader, Pointer.Current(reader), s); s.scriptNodes.Add(sn); if (sn.indent == 0) { endReached = true; } } }); } return(s); }