Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var input       = new AntlrInputStream(Console.In);
            var lexer       = new GraphicsLexer(input);
            var tokenStream = new CommonTokenStream(lexer);
            var p           = new GraphicsParser(tokenStream);

            p.file();
        }
Exemplo n.º 2
0
        public void Parse_gfx_ending_edge_case_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"bitmapfonts = {");
            sb.AppendLine(@"	bitmapfont = {");
            sb.AppendLine(@"		name = ""GFX_text_military_size_1""");
            sb.AppendLine(@"		texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_1.dds"" } }");

            var sb2 = new StringBuilder();

            sb2.AppendLine(@"bitmapfonts = {");
            sb2.AppendLine(@"	bitmapfont = {");
            sb2.AppendLine(@"		name = ""GFX_text_military_size_1""");
            sb2.AppendLine(@"		texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_1.dds""");
            sb2.AppendLine(@"    }");
            sb2.AppendLine(@"}");


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "gfx\\gfx.gfx",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(1);
            for (int i = 0; i < 1; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("gfx\\gfx.gfx");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("GFX_text_military_size_1");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("gfx\\gfx");
            }
        }
Exemplo n.º 3
0
        public void CanParse_gui_should_be_false_then_true()
        {
            var args = new CanParseArgs()
            {
                File = "common\\gamerules\\test.txt",
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);

            parser.CanParse(args).Should().BeFalse();
            args.File = "gui\\gui.gui";
            parser.CanParse(args).Should().BeTrue();
        }
Exemplo n.º 4
0
        public void Parse_gui_ending_edge_case_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"guiTypes = {	");
            sb.AppendLine(@"	containerWindowType = { ");
            sb.AppendLine(@"		name = ""test"" }}");

            var sb2 = new StringBuilder();

            sb2.AppendLine(@"guiTypes = {");
            sb2.AppendLine(@"    containerWindowType = {");
            sb2.AppendLine(@"        name = ""test""");
            sb2.AppendLine(@"    }");
            sb2.AppendLine(@"}");



            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "gui\\gui.gui",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(1);
            for (int i = 0; i < 1; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("gui\\gui.gui");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("test");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("gui\\gui");
            }
        }
Exemplo n.º 5
0
        public void Parse_gfx_replace_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"spriteTypes = {");
            sb.AppendLine(@"	spriteType = {");
            sb.AppendLine(@"		name = ""GFX_dmm_mod_1""");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");

            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "interface\\replace\\gfx.gfx",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(1);
            for (int i = 0; i < 1; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("interface\\replace\\gfx.gfx");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("GFX_dmm_mod_1");
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("interface\\gfx");
                result[i].VirtualPath.Should().Be("interface\\gfx.gfx");
            }
        }
Exemplo n.º 6
0
        public void Parse_gui_variable_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"@sort_button_height = 80");
            sb.AppendLine(@"guiTypes = {");
            sb.AppendLine(@"	@entry_info_height = 17");
            sb.AppendLine(@"	# Button in the lower right of the main view, opening the Alliance View.");
            sb.AppendLine(@"	containerWindowType = {");
            sb.AppendLine(@"	    @why_am_i_here = 17");
            sb.AppendLine(@"		name = ""alliance_button_window""");
            sb.AppendLine(@"		position = { x = -458 y = 43 }");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "gui\\gui.gui",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(4);
            for (int i = 0; i < 4; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("gui\\gui.gui");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("@sort_button_height");
                    result[i].CodeTag.Should().BeNullOrWhiteSpace();
                    result[i].ValueType.Should().Be(ValueType.Variable);
                    break;

                case 1:
                    result[i].Id.Should().Be("@entry_info_height");
                    result[i].CodeTag.Should().Be("guiTypes");
                    result[i].ValueType.Should().Be(ValueType.Variable);
                    break;

                case 2:
                    result[i].Id.Should().Be("alliance_button_window");
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;

                case 3:
                    result[i].Id.Should().Be("@why_am_i_here");
                    result[i].CodeTag.Should().Be("guiTypes");
                    result[i].ValueType.Should().Be(ValueType.Variable);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("gui\\gui");
            }
        }
Exemplo n.º 7
0
        public void Parse_gfx_bitmap_type_override_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"bitmapfonts = {");
            sb.AppendLine(@"	 bitmapfont_override = {");
            sb.AppendLine(@"		name = ""large_title_font""");
            sb.AppendLine(@"        ttf_font = ""Easter_bigger""");
            sb.AppendLine(@"        ttf_size = ""30""");
            sb.AppendLine(@"		languages = { ""l_russian"" ""l_polish"" }");
            sb.AppendLine(@"	 }	");
            sb.AppendLine(@"	 bitmapfont_override = {");
            sb.AppendLine(@"		name = ""large_title_font""");
            sb.AppendLine(@"        ttf_font = ""Easter_bigger""");
            sb.AppendLine(@"        ttf_size = ""30""");
            sb.AppendLine(@"		languages = { ""l_russian"" ""l_polish"" }");
            sb.AppendLine(@"	 }	");
            sb.AppendLine(@"}");


            var sb2 = new StringBuilder();

            sb2.AppendLine(@"bitmapfonts = {");
            sb2.AppendLine(@"	bitmapfont_override = {");
            sb2.AppendLine(@"		name = ""large_title_font""");
            sb2.AppendLine(@"		ttf_font = ""Easter_bigger""");
            sb2.AppendLine(@"		ttf_size = ""30""");
            sb2.AppendLine(@"		languages = {");
            sb2.AppendLine(@"			""l_russian""");
            sb2.AppendLine(@"			""l_polish""");
            sb2.AppendLine(@"		}");
            sb2.AppendLine(@"	}");
            sb2.AppendLine(@"}");


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "gfx\\gfx.gfx",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(2);
            for (int i = 0; i < 2; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("gfx\\gfx.gfx");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("l_polish-l_russian-large_title_font");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;

                case 1:
                    result[i].Id.Should().Be("l_polish-l_russian-large_title_font");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("gfx\\gfx");
            }
        }