Exemplo n.º 1
0
        public TxtEntry[] Build(String name, String[] lines)
        {
            String          postfix = '$' + name + '_';
            List <TxtEntry> entries = new List <TxtEntry>(lines.Length);

            for (Int32 i = 0; i < lines.Length; i++)
            {
                String   key;
                String   line  = GetLine(lines, ref i);
                TxtEntry entry = new TxtEntry {
                    Index = entries.Count, Prefix = postfix
                };
                if (line == String.Empty)
                {
                    entry.Value = String.Empty;
                }
                else if (!Cache.TryGetValue(line, out key))
                {
                    key = StringsFormatter.FormatKeyIndex(postfix, entries.Count);
                    Cache.Add(line, key);
                    entry.Value = FormatValue(name, line);
                }
                else
                {
                    entry.Value = '{' + key + '}';
                }
                entries.Add(entry);
            }
            return(entries.ToArray());
        }
Exemplo n.º 2
0
 public static TxtEntry[] Build(String prefix, String[] characterNames)
 {
     TxtEntry[] names = new TxtEntry[characterNames.Length];
     for (Int32 i = 0; i < names.Length; i++)
         names[i] = new TxtEntry {Prefix = prefix, Value = characterNames[i]};
     return names;
 }
Exemplo n.º 3
0
        public void Write(String name, IList <TxtEntry> entries)
        {
            using (StreamWriter sw = new StreamWriter(_output, Encoding.UTF8, 4096))
            {
                if (_formatter is StringsFormatter) // TEMP
                {
                    sw.WriteLine("/*");
                    sw.WriteLine(name);
                    sw.WriteLine(entries.Count.ToString("D4", CultureInfo.InvariantCulture));
                    sw.WriteLine("*/");
                }
                else
                {
                    sw.WriteLine(name);
                    sw.WriteLine(entries.Count.ToString("D4", CultureInfo.InvariantCulture));
                }

                for (Int32 i = 0; i < entries.Count; i++)
                {
                    TxtEntry entry = entries[i];
                    entry.TryUpdateIndex(i);
                    _formatter.Write(sw, entry);
                }
            }
        }
Exemplo n.º 4
0
        public static void Fill(String filePath, TxtEntry[] entries, Dictionary <Int32, String> locationNames)
        {
            if (entries.IsNullOrEmpty())
            {
                return;
            }

            if (filePath.LastIndexOf("Names of Other", StringComparison.OrdinalIgnoreCase) > 0)
            {
                foreach (TxtEntry entry in entries)
                {
                    locationNames[entry.Index] = entry.Value;
                }
            }
            else
            {
                TxtEntry firstEntry = entries[0];
                locationNames[firstEntry.Index] = firstEntry.Value;

                String prefix = firstEntry.Value + '/';
                for (Int32 i = 1; i < entries.Length; i++)
                {
                    TxtEntry entry = entries[i];
                    locationNames[entry.Index] = prefix + entry.Value;
                }
            }
        }
Exemplo n.º 5
0
 public static TxtEntry[] Build(String prefix, String[] abilityNames, String[] abilityHelps)
 {
     TxtEntry[] abilities = new TxtEntry[Math.Max(abilityNames.Length, abilityHelps.Length)];
     for (Int32 i = 0; i < abilities.Length; i++)
     {
         String name = i < abilityNames.Length ? abilityNames[i] : String.Empty;
         String help = i < abilityHelps.Length ? abilityHelps[i] : String.Empty;
         abilities[i] = Build(prefix, name, help);
     }
     return(abilities);
 }
Exemplo n.º 6
0
 public static TxtEntry[] Build(String prefix, String[] itemNames, String[] itemHelps, String[] itemBattle)
 {
     TxtEntry[] abilities = new TxtEntry[Math.Max(itemNames.Length, itemHelps.Length)];
     for (Int32 i = 0; i < abilities.Length; i++)
     {
         String name = i < itemNames.Length ? itemNames[i] : String.Empty;
         String help = i < itemHelps.Length ? itemHelps[i] : String.Empty;
         String bttl = i < itemBattle.Length ? itemBattle[i] : String.Empty;
         abilities[i] = Build(prefix, name, help, bttl);
     }
     return(abilities);
 }
Exemplo n.º 7
0
 public static TxtEntry[] Build(String prefix, String[] value)
 {
     TxtEntry[] abilities = new TxtEntry[value.Length];
     for (Int32 i = 0; i < abilities.Length; i++)
     {
         abilities[i] = new TxtEntry {
             Prefix = prefix, Value = value[i]
         }
     }
     ;
     return(abilities);
 }
Exemplo n.º 8
0
 private static void AddEntry(String[] parts, Int32 index, LinkedList <TxtEntry> list)
 {
     if (parts.Length > 1)
     {
         TxtEntry entry = new TxtEntry {
             Prefix = Prefix, Index = index, Value = parts[1]
         };
         list.AddLast(entry);
     }
     else
     {
         list.First.Value.Prefix = Prefix;
         list.First.Value.Index  = index;
     }
 }
Exemplo n.º 9
0
        private TxtEntry[] Reverse(String[] general)
        {
            if (general == null)
            {
                return(null);
            }

            TxtEntry[] array = new TxtEntry[general.Length];
            for (Int32 i = 0; i < general.Length; i++)
            {
                array[i] = new TxtEntry {
                    Index = i, Prefix = '{' + general[i] + '}', Value = general[i]
                }
            }
            ;
            return(array);
        }
Exemplo n.º 10
0
        private static LinkedList <TxtEntry> GetList(Dictionary <String, LinkedList <TxtEntry> > dic, String fileName)
        {
            LinkedList <TxtEntry> list;

            if (dic.TryGetValue(fileName, out list))
            {
                return(list);
            }

            list = new LinkedList <TxtEntry>();
            dic.Add(fileName, list);

            TxtEntry entry = new TxtEntry {
                Prefix = RootPrefix, Index = dic.Count, Value = fileName
            };

            list.AddLast(entry);
            return(list);
        }
Exemplo n.º 11
0
        protected override TxtEntry[] PrepareEntries()
        {
            String symbol = EmbadedTextResources.CurrentSymbol ?? Localization.GetSymbol();

            SortedList <String, String> dic = Localization.Provider.ProvideDictionary(symbol);
            IList <String> keys             = dic.Keys;
            IList <String> values           = dic.Values;

            TxtEntry[] result = new TxtEntry[dic.Count];
            for (Int32 i = 0; i < result.Length; i++)
            {
                result[i] = new TxtEntry {
                    Prefix = keys[i], Value = values[i]
                }
            }
            ;

            return(result);
        }
    }
Exemplo n.º 12
0
        public static TxtEntry[] Build(String prefix, String[] itemNames, String[] itemHelps, String[] itemDescriptions)
        {
            List <TxtEntry> abilities = new List <TxtEntry>(80);

            for (Int32 i = 0; i < itemNames.Length; i++)
            {
                String name = i < itemNames.Length ? itemNames[i] : String.Empty;
                if (String.IsNullOrEmpty(name))
                {
                    continue;
                }

                String   help  = i < itemHelps.Length ? itemHelps[i] : String.Empty;
                String   desc  = i < itemDescriptions.Length ? itemDescriptions[i] : String.Empty;
                TxtEntry entry = Build(prefix, name, help, desc);
                entry.Index = i;
                abilities.Add(entry);
            }
            return(abilities.ToArray());
        }
Exemplo n.º 13
0
        public TxtEntry Read(StreamReader sr)
        {
            Int32    index  = -1;
            TxtEntry result = new TxtEntry();

            StringBuilder sb     = new StringBuilder(512);
            Boolean       key    = true;
            Boolean       block  = false;
            Boolean       escape = false;
            Int32         line   = 0;

            while (true)
            {
                Int32 value = sr.Read();
                if (value < 0)
                {
                    if (sb.Length == 0)
                    {
                        return(null);
                    }

                    throw new Exception("Unexpected end of stream.");
                }

                Char ch = (Char)value;
                switch (ch)
                {
                case '\\':
                {
                    if (!block)
                    {
                        continue;
                    }

                    if (escape)
                    {
                        AppendLines(ref line, sb);
                        sb.Append('\\');
                        escape = false;
                    }
                    else
                    {
                        escape = true;
                    }
                    break;
                }

                case '"':
                {
                    if (escape)
                    {
                        AppendLines(ref line, sb);
                        sb.Append('"');
                        escape = false;
                    }
                    else
                    {
                        if (block)
                        {
                            if (key)
                            {
                                if (sb.Length > 4)
                                {
                                    result.Prefix = sb.ToString(0, sb.Length - 4);
                                }

                                index = Int32.Parse(sb.ToString(sb.Length - 4, 4), CultureInfo.InvariantCulture);
                                key   = false;
                            }
                            else
                            {
                                result.Index = index;
                                result.Value = sb.ToString();
                                return(result);
                            }
                            block     = false;
                            sb.Length = 0;
                        }
                        else
                        {
                            block = true;
                        }
                    }
                    break;
                }

                case '\r':
                {
                    if (!block)
                    {
                        continue;
                    }

                    break;
                }

                case '\n':
                {
                    if (!block)
                    {
                        continue;
                    }

                    line++;
                    break;
                }

                default:
                {
                    if (!block)
                    {
                        continue;
                    }

                    if (escape)
                    {
                        sb.Append('\\');
                        escape = false;
                    }

                    AppendLines(ref line, sb);
                    sb.Append(ch);
                    break;
                }
                }
            }
        }
Exemplo n.º 14
0
 public void Write(StreamWriter sw, TxtEntry entry)
 {
     sw.WriteLine("\"{0}\" = \"{1}\";",
                  FormatKeyIndex(entry.Prefix, entry.Index),
                  entry.Value.Replace("\\", "\\\\").Replace("\"", "\\\""));
 }
Exemplo n.º 15
0
        public TxtEntry[] Read(out String name)
        {
            name = null;

            using (StreamReader sr = new StreamReader(_input, Encoding.UTF8, true, 4096))
            {
                String countStr = null;

                if (_formatter is StringsFormatter) // TEMP
                {
                    Boolean comment = false;
                    for (int i = 0; i < 2 || comment;)
                    {
                        String value = sr.ReadLine();
                        if (value.StartsWith("/*"))
                        {
                            comment = true;
                            value   = value.Substring(2);
                        }
                        if (value.EndsWith("*/"))
                        {
                            comment = false;
                            value   = value.Substring(0, value.Length - 2);
                        }
                        value = value.Trim();

                        if (!String.IsNullOrEmpty(value))
                        {
                            if (i == 0)
                            {
                                name = value;
                            }
                            else
                            {
                                countStr = value;
                            }

                            i++;
                        }
                    }
                }
                else
                {
                    name     = sr.ReadLine();
                    countStr = sr.ReadLine();
                }

                Int32      count  = Int32.Parse(countStr, CultureInfo.InvariantCulture);
                TxtEntry[] result = new TxtEntry[count];

                Int32 offset = 0;
                for (Int32 i = 0; i < count && !sr.EndOfStream; i++)
                {
                    TxtEntry entry;
                    try
                    {
                        entry = _formatter.Read(sr);
                    }
                    catch (Exception ex)
                    {
                        if (i > 0)
                        {
                            TxtEntry previous = result[i - 1];
                            throw new Exception($"Cannot read {i} entry from {name}.\r\nPrevious: [Index: {previous.Index}, Pefix: {previous.Prefix}, Value: {previous.Value}]", ex);
                        }
                        else
                        {
                            throw new Exception($"Cannot read {i} entry from {name}.", ex);
                        }
                    }
                    if (entry == null)
                    {
                        offset++;
                        continue;
                    }

                    if (String.IsNullOrEmpty(entry.Prefix))
                    {
                        Log.Warning("Invalid record [Line: {0}, Value: {1}] in the file: {2}", i, entry, name);
                        offset++;
                        continue;
                    }

                    result[i - offset] = entry;
                }

                return(result);
            }
        }