示例#1
0
        public void InitNorseDic()
        {
            try {
                Stream stm = NWResourceManager.LoadStream("Names.txt");
                using (BinaryReader bis = new BinaryReader(stm)) {
                    Parser aParser = new Parser(bis, StaticData.DefEncoding);
                    while (aParser.Token != Parser.сptEOF)
                    {
                        char token = aParser.Token;
                        if (token == Parser.сptSymbol)
                        {
                            string symName = aParser.TokenString();
                            aParser.NextToken();
                            aParser.CheckToken('=');
                            aParser.NextToken();

                            if ((symName != "femaleCount") && (symName != "maleCount"))
                            {
                                string engName = aParser.TokenString();
                                aParser.NextToken();
                                aParser.CheckToken(',');
                                aParser.NextToken();
                                string rusName = aParser.TokenString();
                                aParser.NextToken();

                                char g = symName[0];
                                //symName = symName.substring(1);
                                //TAuxUtils.StrToInt(symName);

                                DicRecord drec = new DicRecord();
                                drec.Name     = engName;
                                drec.Rus_name = rusName;

                                if (g != 'f')
                                {
                                    if (g == 'm')
                                    {
                                        Viking_m.Add(drec);
                                    }
                                }
                                else
                                {
                                    Viking_f.Add(drec);
                                }
                            }
                        }
                        else
                        {
                            aParser.NextToken();
                        }
                    }

                    aParser.Dispose();
                }
            } catch (Exception ex) {
                Logger.Write("TNWNameLib.InitNorseDic(): " + ex.Message);
            }
        }
        public static string GetTextFileByLang(string fileName)
        {
            string result;
            string ext = GlobalVars.nwrWin.LangExt;

            fileName = fileName + "." + ext;

            try {
                Stream stm = NWResourceManager.LoadStream(fileName);
                using (BinaryReader dis = new BinaryReader(stm)) {
                    result = StreamUtils.ReadText(dis, StaticData.DefEncoding);
                }
            } catch (Exception) {
                result = "";
            }

            return(result);
        }
示例#3
0
        public void LoadXML(string fileName)
        {
            try {
                FileHeader header = new FileHeader();
                Clear();

                Stream @is = NWResourceManager.LoadStream(fileName);

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(@is);

                XmlNode root = xmlDocument.DocumentElement;
                if (!root.Name.Equals("RDB"))
                {
                    throw new Exception("Its not RDB!");
                }

                XmlNode vers = root.SelectSingleNode("Version");
                if (vers == null)
                {
                    //throw new RuntimeException("Not found version!");
                }

                XmlNode entries = root.SelectSingleNode("Entries");
                if (entries == null)
                {
                    //throw new RuntimeException("Not found entries!");
                }

                fEntriesCount = Convert.ToInt32(entries.Attributes["Count"].InnerText);
                fEntries      = new DataEntry[fEntriesCount];

                XmlNodeList nl = entries.ChildNodes;
                for (int i = 0; i < nl.Count; i++)
                {
                    XmlNode el = nl[i];
                    if (el.Name.Equals("Entry"))
                    {
                        string val = "";
                        try {
                            sbyte kind = DataEntry.ParseEntryKind(el.Attributes["Kind"].InnerText);
                            int   id   = Convert.ToInt32(el.Attributes["GUID"].InnerText);

                            DataEntry entry = null;
                            if (kind != DataEntry.ek_Unknown)
                            {
                                entry      = CreateEntry(kind);
                                entry.Kind = kind;
                                entry.LoadXML(el, header.Version);
                            }
                            fEntries[id] = entry;
                        } catch (Exception ex) {
                            Logger.Write("LoadXML.1(" + val + "): " + ex.Message);
                        }
                    }
                }

                Logger.Write("dbLoad(): ok");
            } catch (Exception ex) {
                Logger.Write("LoadXML(): " + ex.Message);
            }
        }
示例#4
0
        public void LoadNamesData(string fileName)
        {
            try {
                TLineKind line_kind = TLineKind.lkInf;

                using (StreamReader isr = new StreamReader(NWResourceManager.LoadStream(fileName))) {
                    string line;
                    while ((line = isr.ReadLine()) != null)
                    {
                        if (line.Length > 0 && line[0] != '/')
                        {
                            if (line[0] == '[')
                            {
                                if (line.Contains("[inf]"))
                                {
                                    line_kind = TLineKind.lkInf;
                                }
                                else
                                {
                                    if (line.Contains("[first]"))
                                    {
                                        line_kind = TLineKind.lkFirst;
                                    }
                                    else
                                    {
                                        if (line.Contains("[mid]"))
                                        {
                                            line_kind = TLineKind.lkMid;
                                        }
                                        else
                                        {
                                            if (line.Contains("[final]"))
                                            {
                                                line_kind = TLineKind.lkFinal;
                                            }
                                            else
                                            {
                                                if (line.Contains("[end]") || line.Contains("[stop]"))
                                                {
                                                    line_kind = TLineKind.lkEnd;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (line_kind != TLineKind.lkFirst)
                                {
                                    if (line_kind != TLineKind.lkMid)
                                    {
                                        if (line_kind == TLineKind.lkFinal)
                                        {
                                            fFinalSlabs.Add(line);
                                        }
                                    }
                                    else
                                    {
                                        fMidSlabs.Add(line);
                                    }
                                }
                                else
                                {
                                    fFirstSlabs.Add(line);
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Logger.Write("TNWNameLib.LoadData(): " + ex.Message);
            }
        }
示例#5
0
        private void LoadTemplate()
        {
            Data = new FieldData();

            int[, ] varTiles = new int[StaticData.FieldHeight, StaticData.FieldWidth];
            string varFile = "/fields/" + Sign + ".var";

            if (NWResourceManager.HasStream(varFile))
            {
                try {
                    using (StreamReader isr = new StreamReader(NWResourceManager.LoadStream(varFile))) {
                        for (int y = 0; y < StaticData.FieldHeight; y++)
                        {
                            string   line  = isr.ReadLine().Trim();
                            string[] parts = line.Split(' ');

                            for (int x = 0; x < StaticData.FieldWidth; x++)
                            {
                                int @var = Convert.ToInt32(parts[x]);
                                varTiles[y, x] = @var;
                            }
                        }
                    }
                } catch (Exception ex) {
                    Logger.Write("FieldEntry.loadTemplate.2(): " + ex.Message);
                }
            }

            try {
                string tplFile = "fields/" + Sign + TemplateExt;
                using (StreamReader isr = new StreamReader(NWResourceManager.LoadStream(tplFile))) {
                    for (int y = 0; y < StaticData.FieldHeight; y++)
                    {
                        string line = isr.ReadLine();

                        for (int x = 0; x < StaticData.FieldWidth; x++)
                        {
                            char sym = line[x];

                            FDTile tile = new FDTile();
                            Data.Tiles[y, x] = tile;

                            int bg  = 0;
                            int fg  = 0;
                            int bgv = 0;
                            int fgv = 0;

                            switch (sym)
                            {
                            case '.':
                                bg = PlaceID.pid_Grass;
                                break;

                            case ',':
                                bg = PlaceID.pid_Floor;
                                break;

                            case '~':
                                bg = PlaceID.pid_Water;
                                break;

                            case '*':
                                bg = PlaceID.pid_Space;
                                break;

                            case '^':
                                bg = PlaceID.pid_Ground;
                                fg = PlaceID.pid_Mountain;
                                break;

                            case ':':
                                bg = PlaceID.pid_Floor;
                                break;

                            case 'x':
                                bg = PlaceID.pid_Ground;
                                fg = PlaceID.pid_Rock;
                                break;

                            case '+':
                                bg  = PlaceID.pid_Bifrost;
                                bgv = varTiles[y, x];
                                break;

                            case 'o':
                                bg  = PlaceID.pid_Grass;
                                fg  = PlaceID.pid_Ting;
                                fgv = varTiles[y, x];
                                break;

                            case '1':
                                bg = PlaceID.pid_cr_y;
                                break;

                            case '2':
                                bg = PlaceID.pid_cr_r;
                                break;

                            case '3':
                                bg = PlaceID.pid_cr_b;
                                break;

                            case '4':
                                bg = PlaceID.pid_cr_a;
                                break;

                            case '5':
                                bg = PlaceID.pid_cr_l;
                                break;

                            case '6':
                                bg = PlaceID.pid_cr_w;
                                break;

                            case '7':
                                bg = PlaceID.pid_cr_k;
                                break;

                            case '8':
                                bg = PlaceID.pid_cr_g;
                                break;

                            case '\\':
                            case '/':
                                bg = PlaceID.pid_Ground;
                                break;
                            }

                            tile.BackGround = BaseTile.GetVarID((byte)bg, (byte)bgv);
                            tile.ForeGround = BaseTile.GetVarID((byte)fg, (byte)fgv);
                        }
                    }
                }
            } catch (Exception ex) {
                Logger.Write("FieldEntry.loadTemplate.1(): " + ex.Message);
            }
        }