コード例 #1
0
        public Dicts InitializeAreaSheet(DefinitionParserData data)
        {
            Dicts d = new Dicts(true);

            interaction.InsertValue(new ExcelCellAddress(1, 1), "Spreadsheet for zone: " + interaction.currentSheet.Name);

            int[] rowOfEachGroup    = new int[data.groups.Length];
            int[] columnOfEachGroup = new int[data.groups.Length];
            int   groupcounter      = 0;

            foreach (string group in data.groups)
            {
                rowOfEachGroup[groupcounter]    = 2;
                columnOfEachGroup[groupcounter] = groupcounter * columnOffset + 1;
                ExcelCellAddress address = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter]);
                interaction.currentSheet.Select(new ExcelAddress(address.Row, address.Column, address.Row, address.Column + 2));
                ExcelRange r = interaction.currentSheet.SelectedRange;
                r.Merge = true;
                r.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
                interaction.InsertValue(address, group);
                groupcounter += 1;
                SpreadsheetInteraction.Group g = new SpreadsheetInteraction.Group(address, new ExcelCellAddress(address.Row + 1, address.Column),
                                                                                  new ExcelCellAddress(address.Row + 1, address.Column + 1),
                                                                                  new ExcelCellAddress(address.Row + 1, address.Column + 2));
                d.groups.Add(group, g);
            }
            foreach (DefinitionParserData.Item entry in data.entries)
            {
                SpreadsheetInteraction.Group g = d.groups[entry.group];
                g.totalEntries++;
                d.groups[entry.group] = g;
                for (int i = 0; i < data.groups.Length; i++)
                {
                    if (data.groups[i] == entry.group)
                    {
                        groupcounter = i;
                    }
                }
                rowOfEachGroup[groupcounter] += 1;
                ExcelCellAddress nameAddr  = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter]);
                ExcelCellAddress yangVal   = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter] + 1);
                ExcelCellAddress collected = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter] + 2);

                interaction.InsertValue(nameAddr, entry.mainPronounciation);
                interaction.InsertValue(yangVal, entry.yangValue);
                interaction.InsertValue(collected, 0);

                interaction.currentSheet.Cells[yangVal.Address].Style.Numberformat.Format = "###,###,###,###,###";
                d.addresses.Add(entry.mainPronounciation, collected);
            }
            interaction.Save();
            return(d);
        }
コード例 #2
0
        /// <summary>
        /// Parser for .definition files, constructor parses all .definition files in Definitions folder
        /// </summary>
        public DefinitionParser(Regex searchPattern)
        {
            instance = this;
            DirectoryInfo d = new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Definitions");

            FileInfo[] filesPresent = d.GetFiles("*.definition", SearchOption.AllDirectories).Where(path => searchPattern.IsMatch(path.Name)).ToArray();
            if (filesPresent.Length == 0)
            {
                throw new CustomException("Your program is missing voice recognition strings! Either redownload, or create your own *.definition text file.");
            }

            List <int> Mob_indexes = new List <int>();
            List <DefinitionParserData> definitions = new List <DefinitionParserData>();

            for (int i = 0; i < filesPresent.Length; i++)
            {
                if (filesPresent[i].Name.StartsWith("Mob_"))
                {
                    Mob_indexes.Add(i);
                    continue;
                }

                using (StreamReader s = filesPresent[i].OpenText()) {
                    DefinitionParserData data = new DefinitionParserData(filesPresent[i].Name.Split('.')[0], ParseHeader(s), ParseEntries(s));
                    data.ConstructGrammar();
                    definitions.Add(data);
                }
            }

            getDefinitions = definitions.ToArray();

            if (Mob_indexes.Count != 0)
            {
                getMobDefinitions = new MobParserData().Parse(d);
                for (int i = 0; i < getMobDefinitions.Length; i++)
                {
                    for (int j = 0; j < getDefinitions.Length; j++)
                    {
                        if (getMobDefinitions[i].ID == "Mob_" + getDefinitions[j].ID)
                        {
                            getDefinitions[j].hasEnemyCompanionGrammar = true;
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Parses spreadsheet
        /// </summary>
        /// <param name="book">Current WorkBook</param>
        /// <param name="sheetName">Name of the sheet as it appears in Excel</param>
        /// <param name="type">Spreadsheet type to determine parsing method</param>
        public static Dicts LoadSpreadsheet(ExcelWorkbook book, string sheetName, SpreadsheetTemplates.SpreadsheetPresetType type)
        {
            ExcelWorksheet sheet = book.Worksheets[sheetName];

            switch (type)
            {
            case SpreadsheetTemplates.SpreadsheetPresetType.MAIN: {
                return(default(Dicts));
            }

            case SpreadsheetTemplates.SpreadsheetPresetType.AREA: {
                Dicts d = new Dicts(true);
                DefinitionParserData data = DefinitionParser.instance.currentGrammarFile;
                int[] rowOfEachGroup      = new int[data.groups.Length];
                int[] columnOfEachGroup   = new int[data.groups.Length];
                int   columnOffset        = 4;
                int   groupcounter        = 0;
                foreach (string group in data.groups)
                {
                    rowOfEachGroup[groupcounter]    = 2;
                    columnOfEachGroup[groupcounter] = groupcounter * columnOffset + 1;
                    ExcelCellAddress address = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter]);
                    groupcounter += 1;
                    SpreadsheetInteraction.Group g = new SpreadsheetInteraction.Group(address, new ExcelCellAddress(address.Row + 1, address.Column),
                                                                                      new ExcelCellAddress(address.Row + 1, address.Column + 1),
                                                                                      new ExcelCellAddress(address.Row + 1, address.Column + 2));
                    d.groups.Add(group, g);
                }
                foreach (DefinitionParserData.Item entry in data.entries)
                {
                    SpreadsheetInteraction.Group g = d.groups[entry.group];
                    g.totalEntries++;
                    d.groups[entry.group] = g;
                    for (int i = 0; i < data.groups.Length; i++)
                    {
                        if (data.groups[i] == entry.group)
                        {
                            groupcounter = i;
                        }
                    }
                    rowOfEachGroup[groupcounter] += 1;
                    ExcelCellAddress collected = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter] + 2);

                    d.addresses.Add(entry.mainPronounciation, collected);
                }
                return(d);
            }

            case SpreadsheetTemplates.SpreadsheetPresetType.ENEMY: {
                Dicts d = new Dicts(true);
                // First item entry at A2
                ExcelCellAddress baseAddr = new ExcelCellAddress("A2");
                ExcelCellAddress current  = baseAddr;

                bool EOF = false;
                while (!EOF)
                {
                    if (sheet.Cells[current.Row, current.Column].Value == null)
                    {
                        current = new ExcelCellAddress(2, current.Column + 4);
                        if (sheet.Cells[current.Address].Value == null)
                        {
                            EOF = true;
                            continue;
                        }
                    }
                    d.addresses.Add(sheet.Cells[current.Row, current.Column].GetValue <string>(), new ExcelCellAddress(current.Row, current.Column + 2));
                    current = new ExcelCellAddress(current.Row + 1, current.Column);
                }
                return(d);
            }

            default: {
                throw new CustomException("Uncathegorized sheet entered!");
            }
            }
        }