public GameLoader(WorldModel worldModel, LoadMode mode) { m_worldModel = worldModel; m_scriptFactory = new ScriptFactory(worldModel); m_scriptFactory.ErrorHandler += AddError; AddLoaders(mode); AddExtendedAttributeLoaders(mode); AddXMLLoaders(mode); }
public GameLoader() { m_elementFactory = new ElementFactory(this); m_scriptFactory = new ScriptFactory(this); m_scriptFactory.ErrorHandler += AddError; AddLoaders(); AddExtendedAttributeLoaders(); AddXMLLoaders(); }
public GameLoader(WorldModel worldModel, LoadMode mode, bool? isCompiled = null) { IsCompiledFile = isCompiled ?? false; m_worldModel = worldModel; m_scriptFactory = new ScriptFactory(worldModel); m_scriptFactory.ErrorHandler += AddError; AddLoaders(mode); AddExtendedAttributeLoaders(mode); AddXMLLoaders(mode); }
public GameLoader(WorldModel worldModel, LoadMode mode, bool?isCompiled = null) { IsCompiledFile = isCompiled ?? false; m_worldModel = worldModel; m_scriptFactory = new ScriptFactory(worldModel); m_scriptFactory.ErrorHandler += AddError; AddLoaders(mode); AddExtendedAttributeLoaders(mode); AddXMLLoaders(mode); }
public void Setup() { m_worldModel = new WorldModel(); m_scriptFactory = new ScriptFactory(m_worldModel); m_constructor = new SwitchScriptConstructor(); m_constructor.WorldModel = m_worldModel; m_constructor.ScriptFactory = m_scriptFactory; scriptContext = new ScriptContext(m_worldModel); }
internal EditableScriptFactory(EditorController controller, ScriptFactory factory, WorldModel worldModel) { m_controller = controller; m_scriptFactory = factory; m_worldModel = worldModel; foreach (Element editor in worldModel.Elements.GetElements(ElementType.Editor).Where(IsScriptEditor)) { string appliesTo = editor.Fields.GetString("appliesto"); m_scriptData.Add(appliesTo, new EditableScriptData(editor, worldModel)); } }
private void ResolveObjectDictionary(QuestDictionary <object> dictionary, ScriptFactory scriptFactory) { var copy = new Dictionary <string, object>(dictionary); foreach (var item in copy) { object replacement; var replace = ReplaceValue(item.Value, scriptFactory, out replacement); if (replace) { dictionary[item.Key] = replacement; } } }
private void ResolveObjectList(QuestList <object> list, ScriptFactory scriptFactory) { for (int i = 0; i < list.Count; i++) { var value = list[i]; object replacement; var replace = ReplaceValue(value, scriptFactory, out replacement); if (replace) { list.RemoveAt(i); list.Insert(i, replacement); } } }
public bool Initialise(string filename, string libFolder = null) { m_filename = filename; m_worldModel = new WorldModel(filename, libFolder, null); m_scriptFactory = new ScriptFactory(m_worldModel); m_worldModel.ElementFieldUpdated += m_worldModel_ElementFieldUpdated; m_worldModel.ElementRefreshed += m_worldModel_ElementRefreshed; m_worldModel.ElementMetaFieldUpdated += m_worldModel_ElementMetaFieldUpdated; m_worldModel.UndoLogger.TransactionsUpdated += UndoLogger_TransactionsUpdated; m_worldModel.Elements.ElementRenamed += Elements_ElementRenamed; m_worldModel.LoadStatus += m_worldModel_LoadStatus; bool ok = m_worldModel.InitialiseEdit(); if (ok) { if (m_worldModel.Game.Fields.Get("_editorstyle") as string == "gamebook") { m_editorStyle = EditorStyle.GameBook; m_ignoredTypes.Add(ElementType.Template); m_ignoredTypes.Add(ElementType.ObjectType); } // need to initialise the EditableScriptFactory after we've loaded the game XML above, // as the editor definitions contain the "friendly" templates for script commands. m_editableScriptFactory = new EditableScriptFactory(this, m_scriptFactory, m_worldModel); m_initialised = true; m_worldModel.ObjectsUpdated += m_worldModel_ObjectsUpdated; foreach (Element e in m_worldModel.Elements.GetElements(ElementType.Editor)) { EditorDefinition def = new EditorDefinition(m_worldModel, e); if (def.AppliesTo != null) { // Normal editor definition for editing an element or a script command m_editorDefinitions.Add(def.AppliesTo, def); } else if (def.Pattern != null) { // Editor definition for an expression template in the "if" editor m_expressionDefinitions.Add(def.Pattern, def); } } if (m_worldModel.Version == WorldModelVersion.v500) { m_worldModel.Elements.Get("game").Fields.Set("gameid", GetNewGameId()); } } else { string message = "Failed to load game due to the following errors:" + Environment.NewLine; foreach (string error in m_worldModel.Errors) { message += "* " + error + Environment.NewLine; } ShowMessage(this, new ShowMessageEventArgs { Message = message }); } return ok; }
public void Resolve(ScriptFactory factory) { LazyFields.Resolve(factory); }
private bool ReplaceValue(object value, ScriptFactory scriptFactory, out object replacement) { replacement = null; var genericList = value as QuestList <object>; if (genericList != null) { ResolveObjectList(genericList, scriptFactory); return(false); } var genericDictionary = value as QuestDictionary <object>; if (genericDictionary != null) { ResolveObjectDictionary(genericDictionary, scriptFactory); return(false); } var objRef = value as Types.LazyObjectReference; if (objRef != null) { replacement = m_worldModel.Elements.Get(objRef.ObjectName); return(true); } var objList = value as Types.LazyObjectList; if (objList != null) { replacement = new QuestList <Element>(objList.Objects.Select(o => m_worldModel.Elements.Get(o))); return(true); } var objDictionary = value as Types.LazyObjectDictionary; if (objDictionary != null) { var newDictionary = new QuestDictionary <Element>(); foreach (var kvp in objDictionary.Dictionary) { newDictionary.Add(kvp.Key, m_worldModel.Elements.Get(kvp.Value)); } replacement = newDictionary; return(true); } var script = value as Types.LazyScript; if (script != null) { replacement = scriptFactory.CreateScript(script.Script); return(true); } var scriptDictionary = value as Types.LazyScriptDictionary; if (scriptDictionary != null) { replacement = ConvertToScriptDictionary(scriptDictionary.Dictionary, scriptFactory); return(true); } return(false); }
private QuestDictionary <IScript> ConvertToScriptDictionary(IDictionary <string, string> dictionary, ScriptFactory scriptFactory) { QuestDictionary <IScript> newDictionary = new QuestDictionary <IScript>(); foreach (var item in dictionary) { IScript newScript = scriptFactory.CreateScript(item.Value); newDictionary.Add(item.Key, newScript); } return(newDictionary); }
public void Resolve(ScriptFactory scriptFactory) { CheckNotResolved(); foreach (string typename in m_defaultTypes) { // It is legitimate for a default type not to exist if (m_worldModel.Elements.ContainsKey(ElementType.ObjectType, typename)) { m_fields.AddType(m_worldModel.GetObjectType(typename)); } } m_defaultTypes = null; foreach (string typename in m_types) { try { m_fields.AddType(m_worldModel.GetObjectType(typename)); } catch (Exception ex) { throw new Exception(string.Format("Error adding type '{0}' to element '{1}': {2}", typename, m_fields.Get("name"), ex.Message), ex); } } m_types = null; foreach (string property in m_objectFields.Keys) { try { m_fields.Set(property, m_worldModel.Elements.Get(m_objectFields[property])); } catch (Exception ex) { throw new Exception(string.Format("Error adding attribute '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex); } } m_objectFields = null; foreach (string property in m_scripts.Keys) { try { m_fields.Set(property, scriptFactory.CreateScript(m_scripts[property])); } catch (Exception ex) { throw new Exception(string.Format("Error adding script attribute '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex); } } m_scripts = null; foreach (string property in m_scriptDictionaries.Keys) { try { m_fields.Set(property, ConvertToScriptDictionary(m_scriptDictionaries[property], scriptFactory)); } catch (Exception ex) { throw new Exception(string.Format("Error adding script dictionary '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex); } } m_scriptDictionaries = null; foreach (string property in m_objectLists.Keys) { try { m_fields.Set(property, new QuestList <Element>(m_objectLists[property].Select(n => m_worldModel.Elements.Get(n)))); } catch (Exception ex) { throw new Exception(string.Format("Error adding object list '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex); } } m_objectLists = null; foreach (string property in m_objectDictionaries.Keys) { try { m_fields.Set(property, ConvertToObjectDictionary(m_objectDictionaries[property])); } catch (Exception ex) { throw new Exception(string.Format("Error adding object dictionary '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex); } } m_objectDictionaries = null; foreach (Action action in m_actions) { action(); } m_actions = null; foreach (var field in m_fields.FieldNames) { var attribute = m_fields.Get(field); var objectList = attribute as QuestList <object>; if (objectList != null) { ResolveObjectList(objectList, scriptFactory); } var objectDictionary = attribute as QuestDictionary <object>; if (objectDictionary != null) { ResolveObjectDictionary(objectDictionary, scriptFactory); } } m_resolved = true; }