Exemplo n.º 1
0
        public void Generate(string inputFileName)
        {
            if (!inputFileName.EndsWith(".def"))
            {
                Console.WriteLine("Input file name must ends with .def");
                return;
            }

            string outputFileName = inputFileName.Replace(".def", ".json");

            string content = string.Empty;

            using (StreamReader reader = new StreamReader(inputFileName))
            {
                content = reader.ReadToEnd();
            }

            StageDefinition stage = JsonConvert.DeserializeObject <StageDefinition>(content);

            stage.Poem.Title  = EncodeCharactersToUnicode(stage.Poem.Title);
            stage.Poem.Author = EncodeCharactersToUnicode(stage.Poem.Author);

            for (int line = 0; line < stage.Poem.Content.Count; line++)
            {
                List <int> uncoveredInLine = new List <int>();
                stage.Poem.Content[line] = EncodeCharactersInContent(stage.Poem.Content[line], uncoveredInLine);

                if (uncoveredInLine.Count > 0)
                {
                    for (int lineIndex = 0; lineIndex < stage.Puzzle.SelectedLines.Count; lineIndex++)
                    {
                        if (stage.Puzzle.SelectedLines[lineIndex] == line)
                        {
                            int lineStart = lineIndex * stage.Poem.ColumnCount;
                            foreach (int uncovered in uncoveredInLine)
                            {
                                stage.Puzzle.UncoveredCharacters.Add(lineStart + uncovered);
                            }
                        }
                    }
                }
            }

            stage.Puzzle.NoiseCharacters = EncodeCharactersToUnicode(stage.Puzzle.NoiseCharacters);

            for (int line = 0; line < stage.Formulas.Count; line++)
            {
                stage.Formulas[line] = EncodeCharactersToUnicode(stage.Formulas[line]);
            }

            using (StreamWriter writer = new StreamWriter(outputFileName))
            {
                writer.Write(JsonConvert.SerializeObject(stage, Formatting.Indented));
            }
        }
        public void EnumerateFolder(string folderPath, string resourceCharsFolder, string outputFile)
        {
            Dictionary <string, string> missingChars = new Dictionary <string, string>();

            foreach (string inputFileName in Directory.EnumerateFiles(folderPath, "*.def"))
            {
                string content = string.Empty;
                using (StreamReader reader = new StreamReader(inputFileName))
                {
                    content = reader.ReadToEnd();
                }

                StageDefinition stage = JsonConvert.DeserializeObject <StageDefinition>(content);
                foreach (int line in stage.Puzzle.SelectedLines)
                {
                    foreach (string character in stage.Poem.Content[line])
                    {
                        CheckCharacter(character, resourceCharsFolder, missingChars);
                    }
                }

                foreach (string character in stage.Puzzle.NoiseCharacters)
                {
                    CheckCharacter(character, resourceCharsFolder, missingChars);
                }

                foreach (var formula in stage.Formulas)
                {
                    foreach (string formulaCh in formula)
                    {
                        CheckCharacter(formulaCh, resourceCharsFolder, missingChars);
                    }
                }
            }

            // Write to output file
            using (StreamWriter sw = new StreamWriter(outputFile))
            {
                foreach (string unicode in missingChars.Keys)
                {
                    sw.WriteLine(string.Format(@"{0}    {1}", unicode, missingChars[unicode]));
                }
            }
        }
Exemplo n.º 3
0
        public void Generate(string inputFileName)
        {
            if (!inputFileName.EndsWith(".def"))
            {
                Console.WriteLine("Input file name must ends with .def");
                return;
            }

            string outputFileName = inputFileName.Replace(".def", ".json");

            string content = string.Empty;

            using (StreamReader reader = new StreamReader(inputFileName))
            {
                content = reader.ReadToEnd();
            }

            StageDefinition stage = JsonConvert.DeserializeObject <StageDefinition>(content);

            stage.Poem.Title  = EncodeCharactersToUnicode(stage.Poem.Title);
            stage.Poem.Author = EncodeCharactersToUnicode(stage.Poem.Author);

            for (int line = 0; line < stage.Poem.Content.Count; line++)
            {
                stage.Poem.Content[line] = EncodeCharactersToUnicode(stage.Poem.Content[line]);
            }

            stage.Puzzle.NoiseCharacters = EncodeCharactersToUnicode(stage.Puzzle.NoiseCharacters);

            for (int line = 0; line < stage.Formulas.Count; line++)
            {
                stage.Formulas[line] = EncodeCharactersToUnicode(stage.Formulas[line]);
            }


            using (StreamWriter writer = new StreamWriter(outputFileName))
            {
                writer.Write(JsonConvert.SerializeObject(stage, Formatting.Indented));
            }
        }