예제 #1
0
 private void GenerateFromPattern(StringBuilder stream, PatternList patterns)
 {
     int which = rand.Next(0, patterns.Patterns.Length);
     string rawPattern = patterns.Patterns[which];
     GenerateFromPattern(stream, rawPattern);
 }
예제 #2
0
        public void Mount(string addonPath)
        {
            using (BinaryReader reader = new BinaryReader(File.Open(addonPath, FileMode.Open), Encoding.ASCII))
            {
                int p = 0;
                if (reader.ReadUInt32() != magic)
                {
                    throw new InvalidDataException("File is corrupt.");
                }

                reader.ReadLongString();
                reader.ReadLongString();
                reader.ReadLongString();

                if (reader.ReadBoolean()) // macros
                {
                    LoadMacroList(reader.ReadStringArray());
                }
                if (reader.ReadBoolean()) // globals
                {
                    LoadGlobalList(reader.ReadStringArray());
                }

                if (reader.ReadBoolean()) // outlines
                {
                    if (reader.ReadBoolean())
                    {
                        oIntros.AddRange(reader.ReadStringArray());
                    }
                    if (reader.ReadBoolean())
                    {
                        oBodies.AddRange(reader.ReadStringArray());
                    }
                    if (reader.ReadBoolean())
                    {
                        oEndings.AddRange(reader.ReadStringArray());
                    }
                }

                if (reader.ReadBoolean()) // vocab
                {
                    int c = reader.ReadInt32();

                    for(int i = 0; i < c; i++)
                    {
                        reader.ReadLongString(); // filename
                        int bufferLength = reader.ReadInt32(); // data length - skipping because we can just load right off the stream
                        int bufferEnd = bufferLength + (int)reader.BaseStream.Position;
                        var list = new WordList(reader, ref p);
                        reader.BaseStream.Position = bufferEnd;

                        if (wordBank.ContainsKey(list.Symbol))
                        {
                            wordBank[list.Symbol].Merge(list);
                        }
                        else
                        {
                            wordBank.Add(list.Symbol, list);
                        }
                    }
                }

                if (reader.ReadBoolean())
                {
                    int c = reader.ReadInt32();

                    for(int i = 0; i < c; i++)
                    {
                        reader.ReadLongString(); // dir name
                        char sc = reader.ReadChar();
                        string symbol = sc.ToString(); // symbol
                        string title = reader.ReadLongString(); // title

                        var list = new PatternList(title, sc, reader.ReadStringArray());

                        if (patternBank.ContainsKey(symbol))
                        {
                            patternBank[symbol].Merge(list);
                        }
                        else
                        {
                            patternBank.Add(symbol, list);
                        }
                    }
                }
            }
        }
예제 #3
0
        public bool Merge(PatternList list)
        {
            if (list.Symbol != this.Symbol)
            {
                return false;
            }
            int o = this.Patterns.Length;
            int s = this.Patterns.Length + list.Patterns.Length;

            if (o == s)
            {
                return true;
            }

            Array.Resize<string>(ref this.Patterns, s);

            Array.Copy(list.Patterns, 0, this.Patterns, o, list.Patterns.Length);

            return true;
        }