Ejemplo n.º 1
0
            private void LoadCommand(Element element, string attribute, string value)
            {
                value = value.Replace("(", @"\(").Replace(")", @"\)").Replace(".", @"\.").Replace("?", @"\?");
                value = m_regex.Replace(value, MatchReplace);

                if (value.Contains("#"))
                {
                    GameLoader.AddError(string.Format("Invalid command pattern '{0}.{1} = {2}'", element.Name, attribute, value));
                }

                // Now split semi-colon separated command patterns
                string[] patterns = Utility.ListSplit(value);
                string   result   = string.Empty;

                foreach (string pattern in patterns)
                {
                    if (result.Length > 0)
                    {
                        result += "|";
                    }
                    result += "^" + pattern + "$";
                }

                element.Fields.Set(attribute, result);
            }
            protected override void AddResultToDictionary(IDictionary <string, object> dictionary, string key, XElement xmlValue)
            {
                string type  = xmlValue.Attribute("type").Value;
                var    value = GameLoader.ReadXmlValue(type, xmlValue);

                dictionary.Add(key, value);
            }
Ejemplo n.º 3
0
            private Element AddDelegate(XmlReader reader)
            {
                Dictionary <string, string> data = GameLoader.GetRequiredAttributes(reader, RequiredAttributes);
                Element del = WorldModel.AddDelegate(data["name"]);

                SetupProcedure(del, data["type"], GameLoader.GetTemplateContents(reader), data["name"], data["parameters"]);
                return(del);
            }
Ejemplo n.º 4
0
            private Element AddProcedure(XmlReader reader)
            {
                Dictionary <string, string> data = GameLoader.GetRequiredAttributes(reader, RequiredAttributes);
                Element proc = ElementFactory.CreateFunction(data["name"]);

                SetupProcedure(proc, data["type"], GameLoader.GetTemplateContents(reader), data["name"], data["parameters"]);
                return(proc);
            }
Ejemplo n.º 5
0
 public ElementFactory(GameLoader loader)
 {
     m_loader = loader;
     m_defaultTypeNames.Add(ObjectType.Object, "defaultobject");
     m_defaultTypeNames.Add(ObjectType.Exit, "defaultexit");
     m_defaultTypeNames.Add(ObjectType.Command, "defaultcommand");
     m_defaultTypeNames.Add(ObjectType.Game, "defaultgame");
     m_defaultTypeNames.Add(ObjectType.TurnScript, "defaultturnscript");
 }
Ejemplo n.º 6
0
 public Expression(string expression, GameLoader loader)
 {
     m_expression = expression;
     m_gameLoader = loader;
     if (loader == null)
     {
         throw new ArgumentNullException();
     }
 }
Ejemplo n.º 7
0
 public ElementFactory(GameLoader loader)
 {
     m_loader = loader;
     m_defaultTypeNames.Add(ObjectType.Object, "defaultobject");
     m_defaultTypeNames.Add(ObjectType.Exit, "defaultexit");
     m_defaultTypeNames.Add(ObjectType.Command, "defaultcommand");
     m_defaultTypeNames.Add(ObjectType.Game, "defaultgame");
     m_defaultTypeNames.Add(ObjectType.TurnScript, "defaultturnscript");
 }
Ejemplo n.º 8
0
            public override object Load(XmlReader reader, ref Element current)
            {
                Element jsRef = ElementFactory.CreateElement(ElementType.Javascript, ElementFactory.GetUniqueID());

                jsRef.Fields[FieldDefinitions.Anonymous] = true;
                string file = GameLoader.GetTemplateAttribute(reader, "src");

                jsRef.Fields[FieldDefinitions.Src] = file;
                return(jsRef);
            }
Ejemplo n.º 9
0
            public override object Load(XmlReader reader, ref Element current)
            {
                Element resourceRef = WorldModel.GetElementFactory(ElementType.Resource).Create();

                resourceRef.Fields[FieldDefinitions.Anonymous] = true;
                string file = GameLoader.GetTemplateAttribute(reader, "src");

                resourceRef.Fields[FieldDefinitions.Src] = file;

                return(resourceRef);
            }
Ejemplo n.º 10
0
            public override void Load(Element element, string attribute, string value)
            {
                int num;

                if (int.TryParse(value, out num))
                {
                    element.Fields.Set(attribute, num);
                }
                else
                {
                    GameLoader.AddError(string.Format("Invalid number specified '{0}.{1} = {2}'", element.Name, attribute, value));
                }
            }
Ejemplo n.º 11
0
            protected object Load(XmlReader reader, ref Element current, string defaultName)
            {
                Dictionary <string, string> data = GameLoader.GetRequiredAttributes(reader, m_requiredAttributes);

                string pattern  = data["pattern"];
                string name     = data["name"];
                string template = data["template"];

                bool anonymous = false;

                if (string.IsNullOrEmpty(name))
                {
                    name = defaultName;
                }
                if (string.IsNullOrEmpty(name))
                {
                    anonymous = true;
                    name      = GetUniqueCommandID(pattern);
                }

                Element newCommand = WorldModel.ObjectFactory.CreateCommand(name);

                if (anonymous)
                {
                    newCommand.Fields[FieldDefinitions.Anonymous] = true;
                }

                if (current != null)
                {
                    newCommand.Parent = (Element)current;
                }

                if (pattern != null)
                {
                    newCommand.Fields[FieldDefinitions.Pattern] = pattern;
                }

                if (template != null)
                {
                    LoadTemplate(newCommand, template);
                }

                string unresolved = data["unresolved"];

                if (!string.IsNullOrEmpty(unresolved))
                {
                    newCommand.Fields[FieldDefinitions.Unresolved] = unresolved;
                }

                return(newCommand);
            }
Ejemplo n.º 12
0
        private Dictionary <string, string> GetSubstitutionText(GameLoader loader, string profile)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();

            result.Add("BUILD", string.Format("{0:HH}{0:mm}{0:dd}{0:MM}{0:yy}", DateTime.Now));
            result.Add("PROFILE", profile);

            foreach (string field in loader.GetSubstitutionFieldNames())
            {
                result.Add(field, loader.GetSubstitutionText(field));
            }

            return(result);
        }
Ejemplo n.º 13
0
        public ScriptFactory(GameLoader loader)
        {
            m_gameLoader = loader;

            // Use Reflection to create instances of all IScriptConstructors
            foreach (Type t in TextAdventures.Utility.Classes.GetImplementations(System.Reflection.Assembly.GetExecutingAssembly(),
                                                                                 typeof(IScriptConstructor)))
            {
                AddConstructor((IScriptConstructor)Activator.CreateInstance(t));
            }

            m_setConstructor  = (SetScriptConstructor)InitScriptConstructor(new SetScriptConstructor());
            m_procConstructor = (FunctionCallScriptConstructor)InitScriptConstructor(new FunctionCallScriptConstructor());
        }
Ejemplo n.º 14
0
            private QuestList <object> LoadQuestList(XElement xml)
            {
                var result = new QuestList <object>();

                foreach (var xmlValue in xml.Elements("value"))
                {
                    var    typeAttr = xmlValue.Attribute("type");
                    string type     = typeAttr != null ? typeAttr.Value : null;
                    var    value    = GameLoader.ReadXmlValue(type, xmlValue);

                    result.Add(value);
                }
                return(result);
            }
Ejemplo n.º 15
0
        public ScriptFactory(GameLoader loader)
        {
            m_gameLoader = loader;

            // Use Reflection to create instances of all IScriptConstructors
            foreach (Type t in TextAdventures.Utility.Classes.GetImplementations(System.Reflection.Assembly.GetExecutingAssembly(),
                typeof(IScriptConstructor)))
            {
                AddConstructor((IScriptConstructor)Activator.CreateInstance(t));
            }

            m_setConstructor = (SetScriptConstructor)InitScriptConstructor(new SetScriptConstructor());
            m_procConstructor = (FunctionCallScriptConstructor)InitScriptConstructor(new FunctionCallScriptConstructor());
        }
Ejemplo n.º 16
0
            protected override AttributeLoadResult GetValueFromString(string s, string errorSource)
            {
                double num;

                if (double.TryParse(s, System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowLeadingSign, System.Globalization.CultureInfo.InvariantCulture, out num))
                {
                    return(new AttributeLoadResult {
                        IsValid = true, Value = num
                    });
                }

                GameLoader.AddError(string.Format("Invalid number specified '{0} = {1}'", errorSource, s));
                return(new AttributeLoadResult {
                    IsValid = false
                });
            }
Ejemplo n.º 17
0
            protected override AttributeLoadResult GetValueFromString(string s, string errorSource)
            {
                int num;

                if (int.TryParse(s, out num))
                {
                    return(new AttributeLoadResult {
                        IsValid = true, Value = num
                    });
                }

                GameLoader.AddError(string.Format("Invalid number specified '{0} = {1}'", errorSource, s));
                return(new AttributeLoadResult {
                    IsValid = false
                });
            }
Ejemplo n.º 18
0
            public void StartElement(XmlReader reader, ref Element current)
            {
                object createdObject = Load(reader, ref current);

                if (createdObject != null && createdObject is Element)
                {
                    GameLoader.AddedElement((Element)createdObject);
                }

                if (CanContainNestedAttributes)
                {
                    if (createdObject != null && !reader.IsEmptyElement)
                    {
                        current = (Element)createdObject;
                    }
                }
            }
Ejemplo n.º 19
0
            public override void Load(Element element, string attribute, string value)
            {
                switch (value)
                {
                case "":
                case "true":
                    element.Fields.Set(attribute, true);
                    break;

                case "false":
                    element.Fields.Set(attribute, false);
                    break;

                default:
                    GameLoader.AddError(string.Format("Invalid boolean specified '{0}.{1} = {2}'", element.Name, attribute, value));
                    break;
                }
            }
            private QuestList <object> LoadQuestList(XElement xml)
            {
                var result = new QuestList <object>();

                foreach (var xmlValue in xml.Elements("value"))
                {
                    var typeAttribute = xmlValue.Attribute("type");
                    if (typeAttribute == null)
                    {
                        throw new Exception("Type not specified for value " + xmlValue);
                    }
                    string type  = typeAttribute.Value;
                    var    value = GameLoader.ReadXmlValue(type, xmlValue);

                    result.Add(value);
                }
                return(result);
            }
Ejemplo n.º 21
0
            public override object Load(XmlReader reader, ref Element current)
            {
                Element jsRef = WorldModel.GetElementFactory(ElementType.Javascript).Create();

                jsRef.Fields[FieldDefinitions.Anonymous] = true;
                string file = GameLoader.GetTemplateAttribute(reader, "src");

                if (file.Length == 0)
                {
                    return(null);
                }
                if (WorldModel.Version == WorldModelVersion.v500)
                {
                    // Quest 5.0 would incorrectly save a full path name. We only want the filename.
                    file = System.IO.Path.GetFileName(file);
                }

                jsRef.Fields[FieldDefinitions.Src] = file;

                return(jsRef);
            }
Ejemplo n.º 22
0
            public override object Load(XmlReader reader, ref Element current)
            {
                string file = GameLoader.GetTemplateAttribute(reader, "ref");

                if (file.Length == 0)
                {
                    return(null);
                }
                string    path      = WorldModel.GetExternalPath(file);
                XmlReader newReader = XmlReader.Create(path);

                while (newReader.NodeType != XmlNodeType.Element && !newReader.EOF)
                {
                    newReader.Read();
                }
                if (newReader.Name != "library")
                {
                    RaiseError(string.Format("Included file '{0}' is not a library", file));
                }
                LoadXML(path, newReader);
                return(LoadInternal(file));
            }
Ejemplo n.º 23
0
            protected IDictionary <string, T> LoadDictionaryFromXElement(XElement xml, string errorSource)
            {
                var result = new Dictionary <string, T>();

                var items = xml.Elements("item");

                foreach (var item in items)
                {
                    var key   = item.Element("key");
                    var value = item.Element("value");

                    if (key == null)
                    {
                        GameLoader.AddError(string.Format("Missing key in dictionary for '{0}'", errorSource));
                    }
                    else if (value == null)
                    {
                        GameLoader.AddError(string.Format("Missing value in dictionary for '{0}'", errorSource));
                    }
                    else if (result.ContainsKey(key.Value))
                    {
                        GameLoader.AddError(string.Format("Duplicate key '{1}' in dictionary for '{0}'", errorSource, key.Value));
                    }
                    else
                    {
                        try
                        {
                            AddResultToDictionary(result, key.Value, value);
                        }
                        catch (Exception ex)
                        {
                            GameLoader.AddError(string.Format("Error adding key '{1}' to dictionary for '{0}': {2}",
                                                              errorSource, key.Value, ex.Message));
                        }
                    }
                }

                return(result);
            }
Ejemplo n.º 24
0
            protected override AttributeLoadResult GetValueFromString(string s, string errorSource)
            {
                switch (s)
                {
                case "":
                case "true":
                    return(new AttributeLoadResult {
                        IsValid = true, Value = true
                    });

                case "false":
                    return(new AttributeLoadResult {
                        IsValid = true, Value = false
                    });

                default:
                    GameLoader.AddError(string.Format("Invalid boolean specified '{0} = {1}'", errorSource, s));
                    return(new AttributeLoadResult {
                        IsValid = false
                    });
                }
            }
Ejemplo n.º 25
0
            public override void Load(Element element, string attribute, string value)
            {
                Dictionary <string, string> result = new Dictionary <string, string>();

                string[] values = Utility.ListSplit(value);
                foreach (string pair in values)
                {
                    if (pair.Length > 0)
                    {
                        string trimmedPair = pair.Trim();
                        int    splitPos    = trimmedPair.IndexOf('=');
                        if (splitPos == -1)
                        {
                            GameLoader.AddError(string.Format("Missing '=' in dictionary element '{0}' in '{1}.{2}'", trimmedPair, element.Name, attribute));
                            return;
                        }
                        string key       = trimmedPair.Substring(0, splitPos).Trim();
                        string dictValue = trimmedPair.Substring(splitPos + 1).Trim();
                        result.Add(key, dictValue);
                    }
                }

                element.Fields.LazyFields.AddObjectDictionary(attribute, result);
            }
Ejemplo n.º 26
0
 void loader_LoadStatus(object sender, GameLoader.LoadStatusEventArgs e)
 {
     if (LoadStatus != null)
     {
         LoadStatus(this, new LoadStatusEventArgs(e.Status));
     }
 }
Ejemplo n.º 27
0
            protected override void AddResultToDictionary(IDictionary <string, string> dictionary, string key, XElement xmlValue)
            {
                string value = GameLoader.GetTemplate(xmlValue.Value);

                dictionary.Add(key, value);
            }
Ejemplo n.º 28
0
        private bool InitialiseInternal(GameLoader loader)
        {
            if (m_state != GameState.NotStarted)
            {
                throw new Exception("Game already initialised");
            }
            loader.FilenameUpdated += loader_FilenameUpdated;
            loader.LoadStatus += loader_LoadStatus;
            m_state = GameState.Loading;

            bool success;
            if (m_data != null)
            {
                success = loader.Load(data: m_data);
            }
            else
            {
                success = m_filename == null || loader.Load(m_filename);
            }

            DebugEnabled = !loader.IsCompiledFile;
            m_state = success ? GameState.Running : GameState.Finished;
            m_errors = loader.Errors;
            m_saver = new GameSaver(this);
            if (Version <= WorldModelVersion.v530)
            {
                m_legacyOutputLogger = new LegacyOutputLogger(this);
                m_outputLogger = m_legacyOutputLogger;
            }
            else
            {
                m_outputLogger = new OutputLogger(this);
            }
            return success;
        }
Ejemplo n.º 29
0
 public Element(ElementType type, GameLoader loader)
 {
     ElemType = type;
     m_loader = loader;
 }
Ejemplo n.º 30
0
 public Expression(string expression, GameLoader loader)
 {
     m_expression = expression;
     m_gameLoader = loader;
     if (loader == null) throw new ArgumentNullException();
 }
Ejemplo n.º 31
0
        public CompilerResults Compile(CompileOptions compileOptions)
        {
            CompilerResults result = new CompilerResults();
            GameLoader loader = new GameLoader();
            UpdateStatus(string.Format("Compiling {0} to {1}", compileOptions.Filename, compileOptions.OutputFolder));
            if (!loader.Load(compileOptions.Filename))
            {
                result.Errors = loader.Errors;
            }
            else
            {
                UpdateStatus("Loaded successfully");
                result.Warnings = loader.Warnings;
                result.Success = true;
                var substitutionText = GetSubstitutionText(loader, compileOptions.Profile);
                UpdateStatus("Copying dependencies");
                result.IndexHtml = CopyDependenciesToOutputFolder(compileOptions.OutputFolder, substitutionText, compileOptions.DebugMode, compileOptions.Profile, compileOptions.Minify, loader, compileOptions);

                string saveData = string.Empty;

                UpdateStatus("Saving");
                GameSaver saver = new GameSaver(loader.Elements);
                saver.Progress += saver_Progress;
                saveData = saver.Save();

                UpdateStatus("Copying resources");
                CopyResourcesToOutputFolder(loader.ResourcesFolder, compileOptions.OutputFolder);

                saveData += GetEmbeddedHtmlFileData(loader.ResourcesFolder);
                string saveJs = System.IO.Path.Combine(compileOptions.OutputFolder, "game.js");

                saveData = System.IO.File.ReadAllText(saveJs) + saveData;

                if (compileOptions.Minify)
                {
                    var minifier = new Microsoft.Ajax.Utilities.Minifier();
                    saveData = minifier.MinifyJavaScript(saveData, new Microsoft.Ajax.Utilities.CodeSettings
                    {
                        MacSafariQuirks = true,
                        RemoveUnneededCode = true,
                        LocalRenaming = Microsoft.Ajax.Utilities.LocalRenaming.CrunchAll
                    });

                    var encoding = (Encoding)Encoding.ASCII.Clone();
                    encoding.EncoderFallback = new Microsoft.Ajax.Utilities.JSEncoderFallback();
                    using (var writer = new System.IO.StreamWriter(saveJs, false, encoding))
                    {
                        writer.Write(saveData);
                    }
                }
                else
                {
                    System.IO.File.WriteAllText(saveJs, saveData);
                }

                UpdateStatus("Finished");
            }
            return result;
        }
Ejemplo n.º 32
0
        // TO DO: Different profiles have different dependencies, so want to only copy the required files

        private string CopyDependenciesToOutputFolder(string outputFolder, Dictionary <string, string> substitutionText, bool debugMode, string profile, bool minify, GameLoader loader, CompileOptions options)
        {
            string indexHtm = Copy("index.htm", _resourcesFolder, outputFolder, options, loader, substitutionText, debugMode: debugMode, outputFilename: "index.html");

            Copy("style.css", _resourcesFolder, outputFolder, options, loader, substitutionText);
            Copy("jquery-ui-1.8.16.custom.css", _resourcesFolder, outputFolder, options, loader, substitutionText);
            Copy("game.js", _resourcesFolder, outputFolder, options, loader, substitutionText, debugMode);
            string jsFolder       = System.IO.Path.Combine(_resourcesFolder, "js");
            string outputJsFolder = System.IO.Path.Combine(outputFolder, "js");

            System.IO.Directory.CreateDirectory(outputJsFolder);
            Copy("jquery.min.js", jsFolder, outputJsFolder, options, loader);
            Copy("jquery-ui*.js", jsFolder, outputJsFolder, options, loader);
            Copy("xregexp*.js", jsFolder, outputJsFolder, options, loader);
            Copy("jjmenu.js", jsFolder, outputJsFolder, options, loader);
            Copy("bootstrap*.js", jsFolder, outputJsFolder, options, loader);
            Copy("*.css", jsFolder, outputJsFolder, options, loader);
            Copy("bootstrap*.css", _resourcesFolder, outputFolder, options, loader, substitutionText);
            string imagesFolder       = System.IO.Path.Combine(_resourcesFolder, "images");
            string outputImagesFolder = System.IO.Path.Combine(outputFolder, "images");

            System.IO.Directory.CreateDirectory(outputImagesFolder);
            Copy("*.png", imagesFolder, outputImagesFolder, options, loader, binary: true);
            return(indexHtm);
        }
Ejemplo n.º 33
0
 private string Copy(string filename, string sourceFolder, string outputFolder, CompileOptions options, GameLoader loader, Dictionary<string, string> substitutionText = null, bool debugMode = false, string outputFilename = null, bool binary = false)
 {
     if (filename.Contains("*"))
     {
         string[] files = System.IO.Directory.GetFiles(sourceFolder, filename);
         foreach (string file in files)
         {
             string resultPath = System.IO.Path.Combine(outputFolder, System.IO.Path.GetFileName(file));
             CopyInternal(file, resultPath, substitutionText, debugMode, binary, options.Profile, loader, options.Gamebook);
         }
         return null;
     }
     else
     {
         if (outputFilename == null) outputFilename = filename;
         string sourcePath = System.IO.Path.Combine(sourceFolder, filename);
         string resultPath = System.IO.Path.Combine(outputFolder, outputFilename);
         return CopyInternal(sourcePath, resultPath, substitutionText, debugMode, binary, options.Profile, loader, options.Gamebook);
     }
 }
Ejemplo n.º 34
0
            public override object Load(XmlReader reader, ref Element current)
            {
                string attribute = reader.Name;

                if (attribute == "attr")
                {
                    attribute = reader.GetAttribute("name");
                }
                string type = reader.GetAttribute("type");

                WorldModel.AddAttributeName(attribute);

                if (type == null)
                {
                    string currentElementType = current.Fields.GetString("type");
                    if (string.IsNullOrEmpty(currentElementType))
                    {
                        // the type property is the object type, so is not set for other element types.
                        currentElementType = current.Fields.GetString("elementtype");
                    }
                    type = GameLoader.m_implicitTypes.Get(currentElementType, attribute);
                }

                // map old to new type names if necessary (but not in included library files)
                if (type != null && WorldModel.Version <= WorldModelVersion.v530 && !current.MetaFields[MetaFieldDefinitions.Library] && s_legacyTypeMappings.ContainsKey(type))
                {
                    type = s_legacyTypeMappings[type];
                }

                if (type != null && GameLoader.ExtendedAttributeLoaders.ContainsKey(type))
                {
                    GameLoader.ExtendedAttributeLoaders[type].Load(reader, current);
                }
                else
                {
                    string value;

                    try
                    {
                        value = GameLoader.GetTemplateContents(reader);
                    }
                    catch (XmlException)
                    {
                        RaiseError(string.Format("Error loading XML data for '{0}.{1}' - ensure that it contains no nested XML", current.Name, attribute));
                        return(null);
                    }

                    if (type == null)
                    {
                        if (value.Length > 0)
                        {
                            type = "string";
                        }
                        else
                        {
                            type = "boolean";
                        }
                    }

                    if (GameLoader.AttributeLoaders.ContainsKey(type))
                    {
                        GameLoader.AttributeLoaders[type].Load(current, attribute, value);
                    }
                    else
                    {
                        Element del;
                        if (WorldModel.Elements.TryGetValue(ElementType.Delegate, type, out del))
                        {
                            Element proc = WorldModel.GetElementFactory(ElementType.Delegate).Create();
                            proc.MetaFields[MetaFieldDefinitions.DelegateImplementation] = true;
                            proc.Fields.LazyFields.AddScript(FieldDefinitions.Script.Property, value);
                            current.Fields.Set(attribute, new DelegateImplementation(type, del, proc));
                        }
                        else
                        {
                            RaiseError(string.Format("Unrecognised attribute type '{0}' in '{1}.{2}'", type, current.Name, attribute));
                        }
                    }
                }
                return(null);
            }
Ejemplo n.º 35
0
            public override void SetText(string text, ref Element current)
            {
                string contents = GameLoader.GetTemplate(text);

                current.Fields[FieldDefinitions.DefaultText] = contents;
            }
Ejemplo n.º 36
0
 private string Copy(string filename, string sourceFolder, string outputFolder, CompileOptions options, GameLoader loader, Dictionary <string, string> substitutionText = null, bool debugMode = false, string outputFilename = null, bool binary = false)
 {
     if (filename.Contains("*"))
     {
         string[] files = System.IO.Directory.GetFiles(sourceFolder, filename);
         foreach (string file in files)
         {
             string resultPath = System.IO.Path.Combine(outputFolder, System.IO.Path.GetFileName(file));
             CopyInternal(file, resultPath, substitutionText, debugMode, binary, options.Profile, loader, options.Gamebook);
         }
         return(null);
     }
     else
     {
         if (outputFilename == null)
         {
             outputFilename = filename;
         }
         string sourcePath = System.IO.Path.Combine(sourceFolder, filename);
         string resultPath = System.IO.Path.Combine(outputFolder, outputFilename);
         return(CopyInternal(sourcePath, resultPath, substitutionText, debugMode, binary, options.Profile, loader, options.Gamebook));
     }
 }
Ejemplo n.º 37
0
        private string CopyInternal(string sourcePath, string resultPath, Dictionary<string, string> substitutionText, bool debugMode, bool binary, string profile, GameLoader loader, bool gamebook)
        {
            if (binary)
            {
                System.IO.File.Copy(sourcePath, resultPath, true);
                return resultPath;
            }

            string text = System.IO.File.ReadAllText(sourcePath);

            if (substitutionText != null)
            {
                foreach (var item in substitutionText)
                {
                    text = text.Replace(string.Format("$${0}$$", item.Key), item.Value);
                }
            }
            if (gamebook)
            {
                text = s_textAdventureModeRegex.Replace(text, "");
            }
            else
            {
                text = s_gamebookModeRegex.Replace(text, "");
            }
            if (!debugMode)
            {
                text = s_debugModeRegex.Replace(text, "");
            }
            foreach (var profileRegex in s_profileSpecificTextRegexes)
            {
                // remove all profile-specific scripts, apart from the script specific to the current profile
                if (!IsProfileRegexValidForProfile(profileRegex.Key, profile))
                {
                    text = profileRegex.Value.Replace(text, "");
                }
            }
            foreach (var minMaxRegex in MinMaxRegexes)
            {
                if (loader.Version > minMaxRegex.Key)
                {
                    text = minMaxRegex.Value.Max.Replace(text, "");
                }
                if (loader.Version < minMaxRegex.Key)
                {
                    text = minMaxRegex.Value.Min.Replace(text, "");
                }
            }
            System.IO.File.WriteAllText(resultPath, text);
            return resultPath;
        }
Ejemplo n.º 38
0
 public bool Initialise(IPlayer player, bool? isCompiled = null)
 {
     m_editMode = false;
     m_playerUI = player;
     GameLoader loader = new GameLoader(this, GameLoader.LoadMode.Play, isCompiled);
     bool result = InitialiseInternal(loader);
     if (result)
     {
         m_walkthroughs = new Walkthroughs(this);
     }
     return result;
 }
Ejemplo n.º 39
0
        private Dictionary<string, string> GetSubstitutionText(GameLoader loader, string profile)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            result.Add("BUILD", string.Format("{0:HH}{0:mm}{0:dd}{0:MM}{0:yy}", DateTime.Now));
            result.Add("PROFILE", profile);

            foreach (string field in loader.GetSubstitutionFieldNames())
            {
                result.Add(field, loader.GetSubstitutionText(field));
            }

            return result;
        }
Ejemplo n.º 40
0
 public bool InitialiseEdit()
 {
     m_editMode = true;
     GameLoader loader = new GameLoader(this, GameLoader.LoadMode.Edit);
     return InitialiseInternal(loader);
 }
Ejemplo n.º 41
0
 public override void SetText(string text, ref Element current)
 {
     current.Fields.LazyFields.AddScript("script", GameLoader.GetTemplate(text));
 }
Ejemplo n.º 42
0
 // TO DO: Different profiles have different dependencies, so want to only copy the required files
 private string CopyDependenciesToOutputFolder(string outputFolder, Dictionary<string, string> substitutionText, bool debugMode, string profile, bool minify, GameLoader loader, CompileOptions options)
 {
     string indexHtm = Copy("index.htm", _resourcesFolder, outputFolder, options, loader, substitutionText, debugMode: debugMode, outputFilename: "index.html");
     Copy("style.css", _resourcesFolder, outputFolder, options, loader, substitutionText);
     Copy("jquery-ui-1.8.16.custom.css", _resourcesFolder, outputFolder, options, loader, substitutionText);
     Copy("game.js", _resourcesFolder, outputFolder, options, loader, substitutionText, debugMode);
     string jsFolder = System.IO.Path.Combine(_resourcesFolder, "js");
     string outputJsFolder = System.IO.Path.Combine(outputFolder, "js");
     System.IO.Directory.CreateDirectory(outputJsFolder);
     Copy("jquery.min.js", jsFolder, outputJsFolder, options, loader);
     Copy("jquery-ui*.js", jsFolder, outputJsFolder, options, loader);
     Copy("xregexp*.js", jsFolder, outputJsFolder, options, loader);
     Copy("jjmenu.js", jsFolder, outputJsFolder, options, loader);
     Copy("bootstrap*.js", jsFolder, outputJsFolder, options, loader);
     Copy("*.css", jsFolder, outputJsFolder, options, loader);
     Copy("bootstrap*.css", _resourcesFolder, outputFolder, options, loader, substitutionText);
     string imagesFolder = System.IO.Path.Combine(_resourcesFolder, "images");
     string outputImagesFolder = System.IO.Path.Combine(outputFolder, "images");
     System.IO.Directory.CreateDirectory(outputImagesFolder);
     Copy("*.png", imagesFolder, outputImagesFolder, options, loader, binary: true);
     return indexHtm;
 }
Ejemplo n.º 43
0
        private string CopyInternal(string sourcePath, string resultPath, Dictionary <string, string> substitutionText, bool debugMode, bool binary, string profile, GameLoader loader, bool gamebook)
        {
            if (binary)
            {
                System.IO.File.Copy(sourcePath, resultPath, true);
                return(resultPath);
            }

            string text = System.IO.File.ReadAllText(sourcePath);

            if (substitutionText != null)
            {
                foreach (var item in substitutionText)
                {
                    text = text.Replace(string.Format("$${0}$$", item.Key), item.Value);
                }
            }
            if (gamebook)
            {
                text = s_textAdventureModeRegex.Replace(text, "");
            }
            else
            {
                text = s_gamebookModeRegex.Replace(text, "");
            }
            if (!debugMode)
            {
                text = s_debugModeRegex.Replace(text, "");
            }
            foreach (var profileRegex in s_profileSpecificTextRegexes)
            {
                // remove all profile-specific scripts, apart from the script specific to the current profile
                if (!IsProfileRegexValidForProfile(profileRegex.Key, profile))
                {
                    text = profileRegex.Value.Replace(text, "");
                }
            }
            foreach (var minMaxRegex in MinMaxRegexes)
            {
                if (loader.Version > minMaxRegex.Key)
                {
                    text = minMaxRegex.Value.Max.Replace(text, "");
                }
                if (loader.Version < minMaxRegex.Key)
                {
                    text = minMaxRegex.Value.Min.Replace(text, "");
                }
            }
            System.IO.File.WriteAllText(resultPath, text);
            return(resultPath);
        }