コード例 #1
0
        public static void LoadScriptFromFile(out MethodParamCollection script, string fileName)
        {
            script = new MethodParamCollection();
            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                file.ReadBegin(fileName);

                if (file.ReadBlock() == "Script")
                {
                    int count = -1;
                    count = int.Parse(file.ReadLine());

                    script._methods = new MethodParamPair[count];

                    for (int i = 0; i < count; i++)
                    {
                        MethodParamPair method;
                        string          methodName = file.ReadBlock();
                        int             paramNum   = int.Parse(file.ReadLine());
                        string[]        tempParams = new string[paramNum];
                        for (int j = 0; j < paramNum; j++)
                        {
                            tempParams[j] = file.ReadLine();
                        }
                        int      exitNum   = int.Parse(file.ReadLine());
                        string[] tempExits = new string[exitNum];
                        for (int j = 0; j < exitNum; j++)
                        {
                            tempExits[j] = file.ReadLine();
                        }
                        file.ReadEndBlock();
                        method = EngineGlobals.GenerateMethodFromArgs(methodName, tempParams, tempExits);
                        method.PostExecuteHandler += script.MethodExecuted;
                        script._methods[i]         = method;
                    }
                    file.ReadEndBlock();
                    file.ReadEnd();
                }
                else
                {
                    throw new EngineException("Could not load script " + fileName, false);
                }
            }
        }
コード例 #2
0
        public static void LoadScriptFromFile(out MethodParamCollection script, string fileName)
        {
            script = new MethodParamCollection();
            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                file.ReadBegin(fileName);

                if (file.ReadBlock() == "Script")
                {
                    int count = -1;
                    count = int.Parse(file.ReadLine());

                    script._methods = new MethodParamPair[count];

                    for (int i = 0; i < count; i++)
                    {
                        MethodParamPair method;
                        string methodName = file.ReadBlock();
                        int paramNum = int.Parse(file.ReadLine());
                        string[] tempParams = new string[paramNum];
                        for (int j = 0; j < paramNum; j++)
                        {
                            tempParams[j] = file.ReadLine();
                        }
                        int exitNum = int.Parse(file.ReadLine());
                        string[] tempExits = new string[exitNum];
                        for (int j = 0; j < exitNum; j++)
                        {
                            tempExits[j] = file.ReadLine();
                        }
                        file.ReadEndBlock();
                        method = EngineGlobals.GenerateMethodFromArgs(methodName, tempParams, tempExits);
                        method.PostExecuteHandler += script.MethodExecuted;
                        script._methods[i] = method;

                    }
                    file.ReadEndBlock();
                    file.ReadEnd();
                }
                else
                    throw new EngineException("Could not load script " + fileName, false);
            }
        }
コード例 #3
0
        public static void LoadList(out TextureLoadList list, string file)
        {
            list = new TextureLoadList();
            try
            {
                using (Utilities.FormattedFile formatFile = new Utilities.FormattedFile())
                {
                    formatFile.ReadBegin(@"Data\LoadLists\" + file + LOAD_EXTENSION);
                    if (formatFile.ReadBlock() != "LoadList")
                        throw new Data.Exceptions.EngineException("Missing correct block header, should be \"LoadList\"", true);
                    int entries = int.Parse(formatFile.ReadLine());
                    try
                    {
                        for (int i = 0; i < entries; i++)
                        {
                            string type = formatFile.ReadBlock();
                            string name = formatFile.ReadLine();
                            string path = "";
                            object extra = null;
                            switch (type)
                            {
                                #region Atlas Loading
                                case "Atlas":
                                    {
                                        int x, y, w, h;
                                        string atlasName;
                                        path = formatFile.ReadBlock();
                                        int atlastEntries = int.Parse(formatFile.ReadLine());
                                        Dictionary<string, Data.Scenes.Rectangle> _areas = new Dictionary<string, Data.Scenes.Rectangle>();

                                        for (int j = 0; j < atlastEntries; j++)
                                        {
                                            Data.Scenes.Rectangle rect;
                                            atlasName = formatFile.ReadBlock();
                                            string raw = formatFile.ReadLine();
                                            formatFile.ReadEndBlock();
                                            var temp = raw.Split(',');
                                            if (temp.Length != 4)
                                                throw new Data.Exceptions.EngineException("Invalid atlas entry", true);
                                            x = int.Parse(temp[0]);
                                            y = int.Parse(temp[1]);
                                            w = int.Parse(temp[2]);
                                            h = int.Parse(temp[3]);
                                            rect = new Data.Scenes.Rectangle(x, y, w, h);
                                            _areas[atlasName] = rect;
                                        }
                                        extra = _areas;
                                        formatFile.ReadEndBlock();
                                    }
                                    break;
                                case "Target":
                                    {
                                        int w, h;
                                        string raw = formatFile.ReadLine();
                                        var temp = raw.Split(',');
                                        w = int.Parse(temp[0]);
                                        h = int.Parse(temp[1]);
                                        extra = new int[] { w, h };
                                    }
                                    break;
                                case "Texture":
                                    path = formatFile.ReadLine();
                                    break;
                                #endregion
                            }

                            formatFile.ReadEndBlock();
                            if (type == "Target" || type == "Atlas")
                                list._entries[name] = new object[] { path, type, extra };
                            else
                                list._entries[name] = new object[] { path, type };

                        }
                    }
                    catch(System.Exception ex)
                    {

                    }
                    formatFile.ReadEndBlock();
                    formatFile.ReadEnd();
                }
                list._ready = true;
            }
            catch
            {
                list._ready = false;
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                throw new Exception("Invalid params passed");
            }

            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                string temp = "";
                Dictionary <int, object[]> _methodsRaw = new Dictionary <int, object[]>();

                //Read in the .ell script format to compile to a .ecs file
                file.ReadBegin(args[0] + ".ell");

                temp = file.ReadLine(); //Read in the version
                if (temp != "1.0.0.0")
                {
                    throw new Exception("Script is not for this version of the compiler");
                }

                temp = file.ReadBlock(); //Read in the header

                if (temp != "ElegyScript")
                {
                    throw new Exception("Invalid header tag");
                }

                int entries = int.Parse(file.ReadLine());

                for (int i = 0; i < entries; i++)
                {
                    temp = file.ReadBlock();    //Read in the method name

                    switch (temp)
                    {
                    case "ShowMessageBox":
                    {
                        int      lines      = int.Parse(file.ReadLine());
                        string[] methodArgs = new string[lines];

                        for (int l = 0; l < lines; l++)
                        {
                            methodArgs[l] = file.ReadLine();
                        }

                        _methodsRaw[i]    = new object[2];
                        _methodsRaw[i][0] = temp;
                        _methodsRaw[i][1] = methodArgs;
                        break;
                    }

                    case "SetVariable":
                    {
                        string name, val;
                        name              = file.ReadLine();
                        val               = file.ReadLine();
                        _methodsRaw[i]    = new object[3];
                        _methodsRaw[i][0] = temp;
                        _methodsRaw[i][1] = name;
                        _methodsRaw[i][2] = val;
                        break;
                    }

                    case "SetSwitch":
                    {
                        string name;
                        string rawVal;
                        bool   val = false;
                        name   = file.ReadLine();
                        rawVal = file.ReadLine();
                        if (rawVal == "ON")
                        {
                            val = true;
                        }
                        else if (rawVal == "OFF")
                        {
                            val = false;
                        }
                        _methodsRaw[i]    = new object[3];
                        _methodsRaw[i][0] = temp;
                        _methodsRaw[i][1] = name;
                        _methodsRaw[i][2] = val;
                        break;
                    }

                    case "ToggleSwitch":
                    case "AddGold":
                    case "Wait":
                    {
                        string name;
                        name              = file.ReadLine();
                        _methodsRaw[i]    = new object[2];
                        _methodsRaw[i][0] = temp;
                        _methodsRaw[i][1] = name;
                        break;
                    }

                    case "Conditional":
                    {
                        break;
                    }

                    case "OpenSaveScreen":
                    case "StartBattle":
                    case "DamageActor":

                    //Audio
                    case "SetBgm":
                    case "SetSfx":
                        break;

                    case "ChangeBattleBgm":
                        break;

                    default:
                        throw new Exception("No such method exists or is implemented");
                    }


                    file.ReadEndBlock();
                }

                file.ReadEndBlock();

                file.ReadEnd();

                using (System.IO.BinaryWriter bw = new BinaryWriter(File.Create(args[1] + ".esl")))
                {
                    foreach (var kvp in _methodsRaw)
                    {
                        bw.Write(kvp.Key);
                        bw.Write(_methodIndexes[kvp.Value[0].ToString()]);
                        switch (kvp.Value[0].ToString())
                        {
                        case "ShowMessageBox":
                        {
                            string[] lines = (string[])kvp.Value[1];
                            bw.Write((byte)lines.Length);
                            for (byte i = 0; i < lines.Length; i++)
                            {
                                bw.Write(lines[i]);
                            }
                        }
                        break;

                        case "SetVariable":
                        case "SetSwitch":
                        case "ToggleSwitch":
                        case "AddGold":
                        case "Wait":
                        case "Conditional":
                        case "OpenSaveScreen":
                        case "StartBattle":
                        case "DamageActor":

                        //Audio
                        case "SetBgm":
                        case "SetSfx":
                        case "ChangeBattleBgm":
                            break;
                        }
                    }
                }
            }
        }
コード例 #5
0
        public static void LoadList(out TextureLoadList list, string file)
        {
            list = new TextureLoadList();
            try
            {
                using (Utilities.FormattedFile formatFile = new Utilities.FormattedFile())
                {
                    formatFile.ReadBegin(@"Data\LoadLists\" + file + LOAD_EXTENSION);
                    if (formatFile.ReadBlock() != "LoadList")
                    {
                        throw new EngineException("Missing correct block header, should be \"LoadList\"", true);
                    }
                    int entries = int.Parse(formatFile.ReadLine());
                    for (int i = 0; i < entries; i++)
                    {
                        string type  = formatFile.ReadBlock();
                        string name  = formatFile.ReadLine();
                        string path  = "";
                        object extra = null;
                        switch (type)
                        {
                            #region Atlas Loading
                        case "Atlas":
                        {
                            int    x, y, w, h;
                            string atlasName;
                            path = formatFile.ReadBlock();
                            int atlastEntries = int.Parse(formatFile.ReadLine());
                            Dictionary <string, Data.Scenes.Rectangle> _areas = new Dictionary <string, Data.Scenes.Rectangle>();

                            for (int j = 0; j < atlastEntries; j++)
                            {
                                Data.Scenes.Rectangle rect;
                                atlasName = formatFile.ReadBlock();
                                string raw = formatFile.ReadLine();
                                formatFile.ReadEndBlock();
                                var temp = raw.Split(',');
                                if (temp.Length != 4)
                                {
                                    throw new EngineException("Invalid atlas entry", true);
                                }
                                x    = int.Parse(temp[0]);
                                y    = int.Parse(temp[1]);
                                w    = int.Parse(temp[2]);
                                h    = int.Parse(temp[3]);
                                rect = new Data.Scenes.Rectangle(x, y, w, h);
                                _areas[atlasName] = rect;
                            }
                            extra = _areas;
                            formatFile.ReadEndBlock();
                        }
                        break;

                        case "Target":
                        {
                            int    w, h;
                            string raw  = formatFile.ReadLine();
                            var    temp = raw.Split(',');
                            w     = int.Parse(temp[0]);
                            h     = int.Parse(temp[1]);
                            extra = new int[] { w, h };
                        }
                        break;

                        case "Texture":
                            path = formatFile.ReadLine();
                            break;
                            #endregion
                        }

                        formatFile.ReadEndBlock();
                        if (type == "Target" || type == "Atlas")
                        {
                            list._entries[name] = new object[] { path, type, extra }
                        }
                        ;
                        else
                        {
                            list._entries[name] = new object[] { path, type }
                        };
                    }
                    formatFile.ReadEndBlock();
                    formatFile.ReadEnd();
                }
                list._ready = true;
            }
            catch
            {
                list._ready = false;
            }
        }
コード例 #6
0
        private void SaveGame()
        {
            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                if (!System.IO.Directory.Exists("SavedGame"))
                    System.IO.Directory.CreateDirectory("SavedGame");

                file.WriteBegin(@"SavedGame\save.egs");
                file.WriteLine(EquestriEngine.VERSION_NUMBER);
                file.WriteBlock("SavedGame");

                file.WriteBlock("PartyData");
                file.WriteLine(0);
                file.WriteEndBlock();

                file.WriteBlock("ItemData");
                file.WriteLine(0);
                file.WriteEndBlock();

                file.WriteBlock("VariableStates");
                file.WriteLine(_variables.Count);
                foreach (var kvp in _variables)
                {
                    file.WriteLine(string.Format("{0};{1}", kvp.Key, kvp.Value.Value));
                }
                file.WriteEndBlock();

                file.WriteBlock("SwitchStates");
                file.WriteLine(_switches.Count);
                foreach (Switch s in _switches.Values)
                {
                    file.WriteLine(string.Format("{0};{1}", s.Name, s.Value));
                }
                file.WriteEndBlock();

                file.WriteBlock("AchievementData");

                var unlocked = new System.Collections.Generic.List<Achievement>();

                for (int i = 0; i < achievements.Length; i++)
                {
                    if (achievements[i].Unlocked)
                        unlocked.Add(achievements[i]);
                }

                if (unlocked.Count > 0)
                    foreach (var achievement in unlocked)
                    {
                        file.WriteLine(achievement.DataName + ";" + achievement.Unlocked);
                    }

                file.WriteEndBlock();

                file.WriteEndBlock();
                file.WriteEnd();
            }
        }
コード例 #7
0
        private void SaveGame()
        {
            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                if (!System.IO.Directory.Exists("SavedGame"))
                {
                    System.IO.Directory.CreateDirectory("SavedGame");
                }

                file.WriteBegin(@"SavedGame\save.egs");
                file.WriteLine(EquestriEngine.VERSION_NUMBER);
                file.WriteBlock("SavedGame");

                file.WriteBlock("PartyData");
                file.WriteLine(0);
                file.WriteEndBlock();

                file.WriteBlock("ItemData");
                file.WriteLine(0);
                file.WriteEndBlock();

                file.WriteBlock("VariableStates");
                file.WriteLine(_variables.Count);
                foreach (var kvp in _variables)
                {
                    file.WriteLine(string.Format("{0};{1}", kvp.Key, kvp.Value.Value));
                }
                file.WriteEndBlock();

                file.WriteBlock("SwitchStates");
                file.WriteLine(_switches.Count);
                foreach (Switch s in _switches.Values)
                {
                    file.WriteLine(string.Format("{0};{1}", s.Name, s.Value));
                }
                file.WriteEndBlock();

                file.WriteBlock("AchievementData");

                var unlocked = new System.Collections.Generic.List <Achievement>();

                for (int i = 0; i < achievements.Length; i++)
                {
                    if (achievements[i].Unlocked)
                    {
                        unlocked.Add(achievements[i]);
                    }
                }

                if (unlocked.Count > 0)
                {
                    foreach (var achievement in unlocked)
                    {
                        file.WriteLine(achievement.DataName + ";" + achievement.Unlocked);
                    }
                }

                file.WriteEndBlock();

                file.WriteEndBlock();
                file.WriteEnd();
            }
        }
コード例 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="file">An already open formatted file</param>
 /// <returns></returns>
 public static MethodParamCollection ReadScript(Utilities.FormattedFile file)
 {
     return(null);
 }
コード例 #9
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                throw new Exception("Invalid params passed");
            }

            using (Utilities.FormattedFile file = new Utilities.FormattedFile())
            {
                string temp = "";
                Dictionary<int, object[]> _methodsRaw = new Dictionary<int, object[]>();

                //Read in the .ell script format to compile to a .ecs file
                file.ReadBegin(args[0] + ".ell");

                temp = file.ReadLine(); //Read in the version
                if (temp != "1.0.0.0")
                    throw new Exception("Script is not for this version of the compiler");

                temp = file.ReadBlock(); //Read in the header

                if (temp != "ElegyScript")
                    throw new Exception("Invalid header tag");

                int entries = int.Parse(file.ReadLine());

                for (int i = 0; i < entries; i++)
                {
                    temp = file.ReadBlock();    //Read in the method name

                    switch (temp)
                    {
                        case "ShowMessageBox":
                            {
                                int lines = int.Parse(file.ReadLine());
                                string[] methodArgs = new string[lines];

                                for (int l = 0; l < lines; l++)
                                    methodArgs[l] = file.ReadLine();

                                _methodsRaw[i] = new object[2];
                                _methodsRaw[i][0] = temp;
                                _methodsRaw[i][1] = methodArgs;
                                break;
                            }
                        case "SetVariable":
                            {
                                string name, val;
                                name = file.ReadLine();
                                val = file.ReadLine();
                                _methodsRaw[i] = new object[3];
                                _methodsRaw[i][0] = temp;
                                _methodsRaw[i][1] = name;
                                _methodsRaw[i][2] = val;
                                break;
                            }
                        case "SetSwitch":
                            {
                                string name;
                                string rawVal;
                                bool val = false;
                                name = file.ReadLine();
                                rawVal = file.ReadLine();
                                if (rawVal == "ON")
                                    val = true;
                                else if (rawVal == "OFF")
                                    val = false;
                                _methodsRaw[i] = new object[3];
                                _methodsRaw[i][0] = temp;
                                _methodsRaw[i][1] = name;
                                _methodsRaw[i][2] = val;
                                break;
                            }
                        case "ToggleSwitch":
                        case "AddGold":
                        case "Wait":
                            {
                                string name;
                                name = file.ReadLine();
                                _methodsRaw[i] = new object[2];
                                _methodsRaw[i][0] = temp;
                                _methodsRaw[i][1] = name;
                                break;
                            }
                        case "Conditional":
                            {
                                break;
                            }
                        case "OpenSaveScreen":
                        case "StartBattle":
                        case "DamageActor":

                        //Audio
                        case "SetBgm":
                        case "SetSfx":
                            break;
                        case "ChangeBattleBgm":
                            break;
                        default:
                            throw new Exception("No such method exists or is implemented");
                    }

                    file.ReadEndBlock();
                }

                file.ReadEndBlock();

                file.ReadEnd();

                using (System.IO.BinaryWriter bw = new BinaryWriter(File.Create(args[1] + ".esl")))
                {
                    foreach (var kvp in _methodsRaw)
                    {
                        bw.Write(kvp.Key);
                        bw.Write(_methodIndexes[kvp.Value[0].ToString()]);
                        switch (kvp.Value[0].ToString())
                        {
                            case "ShowMessageBox":
                                {
                                    string[] lines = (string[])kvp.Value[1];
                                    bw.Write((byte)lines.Length);
                                    for (byte i = 0; i < lines.Length; i++)
                                    {
                                        bw.Write(lines[i]);
                                    }
                                }
                                break;
                            case "SetVariable":
                            case "SetSwitch":
                            case "ToggleSwitch":
                            case "AddGold":
                            case "Wait":
                            case "Conditional":
                            case "OpenSaveScreen":
                            case "StartBattle":
                            case "DamageActor":

                            //Audio
                            case "SetBgm":
                            case "SetSfx":
                            case "ChangeBattleBgm":
                                break;
                        }
                    }
                }
            }
        }