예제 #1
0
        private Program()
        {
            fvi = Assembly.GetExecutingAssembly().GetVersionInfo();
            sprite = new SpriteDescriptor();
            charSets = new List<string>();
            fontSize = 24.0f;
            spacing = 1;
            alignment = GlyphAlignment.BestFit;
            forceSpace = true;
            maxSize = 2048;

            // create services
            services = new object[]
            {
                new XmlDocCreator(),
                new CharSetProvider(),
                new AtlasBuilder(this)
            };
        }
예제 #2
0
        private int Run(string[] args)
        {
            cmd = Command.None;

            opt = new OptionSet()
            {
                {"h|?|help", "show this message", v => cmd = Command.Help },
                {"f=|font=", "generate the specifed {font}", v => { fontName = v; cmd = Command.Build;} },
                {"o=|output=", "output atlas {file}[.atlas]", v => outFile = v },
                {"c=|char-set=", "character {set} to use", v => charSets.Add(v) },
                {"i=|image-path=", "directory {path} of png images to add", v => { imagePath = v; cmd = Command.Build; } },
                {"l|list-sets", "list available character sets", v => cmd = Command.List },
                {"v|verbose", "enable maximum verbosity", v => verbose = v != null },
                {"m|make-sprite", "make an associated sprite", v => makeSprite = v != null },
                {"p=|plugin", "execute module plugin in {assembly}", v => { pluginPath = v; cmd = Command.Plugin; } },
                {"C|console-mode", "run in interactive console mode", v => cmd = Command.Console },
                {"plugin-module=", "optional plugin module {name}", v => pluginName = v },
                {"power-two", "force atlas dimensions to be a power of 2", v => powTwo = v != null},
                {"max-size=", "maximum texture {size} in pixels [2048]", v => int.TryParse(v, out maxSize) },
                {"multi-texture", "enable multi-texture support", v => multiTexture = v != null},
                {"font-size=", "font {size}", v => float.TryParse(v, out fontSize) },
                {"font-bold", "use bold font", v => fontBold = v != null},
                {"font-italic", "use italic font", v => fontItalic = v != null},
                {"force-space", "force a space glyph", v => forceSpace = v != null},
                {"sprite-rate=", "sprite play back {speed} in frames per second", v => { float r; if (float.TryParse(v, out r)) sprite.Rate = r; }},
                {"sprite-overflow=", "sprite action after playing last {frame} (Hold|Loop)", v => sprite.Overflow = (OverflowAction)Enum.Parse(typeof(OverflowAction), v) },
                {"glyph-align=", "the {layout} of each glyph (BestFit|Grid)", v => alignment = (GlyphAlignment)Enum.Parse(typeof(GlyphAlignment), v) },
                {"glyph-space=", "the {space} between glyphs in pixels", v => int.TryParse(v, out spacing)},
                {"image-start=", "image starting {index}", v => int.TryParse(v, out startCode)},
                {"image-recurse", "search sub directories when adding images", v => recurseDir = v != null},
                {"image-center", "center all image glyphs", v => centerImages = v != null},
                {"image-origin=", "{\"x, y\"} offset of all image glyphs", v => imageOrigin = Transpose.FromString<Vec2f>(v)},
            };

            try
            {
                var param = opt.Parse(args);

                switch (cmd)
                {
                    case Command.List:
                        WriteSets();
                        return 0;

                    case Command.None:
                    case Command.Help:
                        WriteHelp();
                        return 1;

                    case Command.Plugin:
                        ExecutePlugin(param);
                        break;

                    case Command.Build:
                        Validate();
                        Process();
                        break;

                    case Command.Console:
                        new Interactive(this).Run();
                        break;
                }
            }
            catch (Exception e)
            {
                WriteError(e);
                return 2;
            }

            return 0;
        }