コード例 #1
0
        /// <summary>
        /// Gets the description of the specified language.
        /// </summary>
        /// <param name="language">The language.</param>
        /// <returns>The description.</returns>
        /// <exception cref="System.ArgumentException">Thrown when the specified language is invalid.</exception>
        public string GetDescription(StringTableLanguage language = StringTableLanguage.English)
        {
            if (!Enum.IsDefined(typeof(StringTableLanguage), language))
            {
                throw new ArgumentException("language", "Language does not exist");
            }

            return(descriptions[(int)language]);
        }
コード例 #2
0
        /// <summary>
        /// Sets the specified languages text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="language">The language.</param>
        /// <exception cref="System.ArgumentException">Thrown when the specified language is invalid.</exception>
        public void SetText(string text, StringTableLanguage language = StringTableLanguage.English)
        {
            if (!Enum.IsDefined(typeof(StringTableLanguage), language))
            {
                throw new ArgumentException("language", "Language does not exist");
            }

            this.text[(int)language] = text;
        }
コード例 #3
0
        /// <summary>
        /// Sets the specified languages end message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="language">The language.</param>
        /// <exception cref="System.ArgumentException">Thrown when the specified language is invalid.</exception>
        public void SetEndMessage(string message, StringTableLanguage language = StringTableLanguage.English)
        {
            if (!Enum.IsDefined(typeof(StringTableLanguage), language))
            {
                throw new ArgumentException("language", "Language does not exist");
            }

            endMessages[(int)language] = message;
        }
コード例 #4
0
        /// <summary>
        /// Sets the specified languages description.
        /// </summary>
        /// <param name="description">The description.</param>
        /// <param name="language">The language.</param>
        /// <exception cref="System.ArgumentException">Thrown when the specified language is invalid.</exception>
        public void SetDescription(string description, StringTableLanguage language = StringTableLanguage.English)
        {
            if (!Enum.IsDefined(typeof(StringTableLanguage), language))
            {
                throw new ArgumentException("language", "Language does not exist");
            }

            descriptions[(int)language] = description;
        }
コード例 #5
0
        /// <summary>
        /// Tests the save method using the specified file path.
        /// </summary>
        private void TestSaveMethod(string filePath)
        {
            StringTableFile stringTableFile = new StringTableFile();

            stringTableFile.Load(filePath);

            MemoryStream savedStream = new MemoryStream();

            stringTableFile.Save(savedStream);
            savedStream.Seek(0, SeekOrigin.Begin);

            StringTableFile savedStringTableFile = new StringTableFile();

            savedStringTableFile.Load(savedStream);
            savedStream.Close();

            Assert.AreEqual(stringTableFile.TableType, stringTableFile.TableType, "Table types do not match");
            Assert.AreEqual(stringTableFile.RowCount, stringTableFile.RowCount, "Row counts do not match");

            for (int i = 0; i < stringTableFile.RowCount; i++)
            {
                for (int j = 0; j < stringTableFile.LanguageCount; j++)
                {
                    StringTableLanguage language = (StringTableLanguage)j;

                    Assert.AreEqual(stringTableFile[i].GetText(language), savedStringTableFile[i].GetText(language), "Text values do not match");

                    if (stringTableFile.TableType == StringTableType.Item || stringTableFile.TableType == StringTableType.Quest)
                    {
                        Assert.AreEqual(stringTableFile[i].GetDescription(language), savedStringTableFile[i].GetDescription(language), "Description values do not match");

                        if (stringTableFile.TableType == StringTableType.Quest)
                        {
                            Assert.AreEqual(stringTableFile[i].GetStartMessage(language), savedStringTableFile[i].GetStartMessage(language), "Start message values do not match");
                            Assert.AreEqual(stringTableFile[i].GetEndMessage(language), savedStringTableFile[i].GetEndMessage(language), "End message values do not match");
                        }
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            string tableType = TableType.GetAttributeValue <StringTableTypeIdentifierAttribute, string>(x => x.Value);

            writer.Write(tableType);

            writer.Write(rows.Count);

            keys.ForEach(key => {
                writer.Write(key.Key);
                writer.Write(key.ID);
            });

            writer.Write(LanguageCount);

            long languageOffsets = stream.Position;

            for (int i = 0; i < LanguageCount; i++)
            {
                writer.Write(0);
            }

            long[] rowOffsetValues = new long[rows.Count];

            for (int i = 0; i < LanguageCount; i++)
            {
                StringTableLanguage language = (StringTableLanguage)i;

                long rowOffsets = stream.Position;

                for (int j = 0; j < rows.Count; j++)
                {
                    writer.Write(0);
                }

                for (int j = 0; j < rows.Count; j++)
                {
                    StringTableRow row = rows[j];
                    rowOffsetValues[j] = stream.Position;

                    writer.Write(row.GetText(language));

                    if (TableType == StringTableType.Item || TableType == StringTableType.Quest)
                    {
                        writer.Write(row.GetDescription(language));

                        if (TableType == StringTableType.Quest)
                        {
                            writer.Write(row.GetStartMessage(language));
                            writer.Write(row.GetEndMessage(language));
                        }
                    }
                }

                long position = stream.Position;
                stream.Seek(rowOffsets, SeekOrigin.Begin);

                for (int j = 0; j < rowOffsetValues.Length; j++)
                {
                    writer.Write((int)rowOffsetValues[j]);
                }

                stream.Seek(languageOffsets + (i * sizeof(int)), SeekOrigin.Begin);
                writer.Write((int)rowOffsets);

                stream.Seek(position, SeekOrigin.Begin);
            }
        }
コード例 #7
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            string typeValue = reader.ReadString();

            TableType = GetTableType(typeValue);

            int rowCount = reader.ReadInt32();

            for (int i = 0; i < rowCount; i++)
            {
                StringTableKey key = new StringTableKey();
                key.Key = reader.ReadString();
                key.ID  = reader.ReadInt32();

                keys.Add(key);
            }

            int languageCount = reader.ReadInt32();

            for (int j = 0; j < rowCount; j++)
            {
                StringTableRow row = new StringTableRow(languageCount);
                rows.Add(row);
            }

            for (int i = 0; i < languageCount; i++)
            {
                StringTableLanguage language = (StringTableLanguage)i;

                int  languageOffset     = reader.ReadInt32();
                long nextLanguageOffset = stream.Position;

                stream.Seek(languageOffset, SeekOrigin.Begin);

                for (int j = 0; j < rowCount; j++)
                {
                    int  rowOffset     = reader.ReadInt32();
                    long nextRowOffset = stream.Position;

                    stream.Seek(rowOffset, SeekOrigin.Begin);

                    StringTableRow row = rows[j];
                    row.SetText(reader.ReadString(), language);

                    if (TableType == StringTableType.Item || TableType == StringTableType.Quest)
                    {
                        row.SetDescription(reader.ReadString(), language);

                        if (TableType == StringTableType.Quest)
                        {
                            row.SetStartMessage(reader.ReadString(), language);
                            row.SetEndMessage(reader.ReadString(), language);
                        }
                    }

                    if (j < rowCount - 1)
                    {
                        stream.Seek(nextRowOffset, SeekOrigin.Begin);
                    }
                }

                if (i < languageCount - 1)
                {
                    stream.Seek(nextLanguageOffset, SeekOrigin.Begin);
                }
            }
        }