Ejemplo n.º 1
0
 public GameLoader(WorldModel worldModel, LoadMode mode)
 {
     m_worldModel = worldModel;
     m_scriptFactory = new ScriptFactory(worldModel);
     m_scriptFactory.ErrorHandler += AddError;
     AddLoaders(mode);
     AddExtendedAttributeLoaders(mode);
     AddXMLLoaders(mode);
 }
Ejemplo n.º 2
0
        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(e => IsScriptEditor(e)))
            {
                string appliesTo = editor.Fields.GetString("appliesto");
                m_scriptData.Add(appliesTo, new EditableScriptData(editor));
            }
        }
Ejemplo n.º 3
0
        public bool Initialise(string filename)
        {
            m_filename = filename;
            m_worldModel = new WorldModel(filename, 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;

            bool ok = m_worldModel.InitialiseEdit();

            // 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 (ok)
            {
                UpdateTree();
            }
            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(message);
            }

            return ok;
        }