Ejemplo n.º 1
0
        static void Init()
        {
            Screen.ClearColor = 0x1e4e50ff;

            Texture.DefaultMinFilter = TextureFilter.Nearest;
            Texture.DefaultMagFilter = TextureFilter.Nearest;

            var builder = new AtlasBuilder(1024);

            //Pack a font
            var font   = new Font("Assets/NotoSans-Regular.ttf", FontCharSet.BasicLatin);
            var size32 = new FontSize(font, 32);

            builder.AddFont("font", size32, true);

            //Pack a bunch of icons
            builder.AddTiles("Assets/icons.png", 16, 16, true, true);

            atlas = builder.Build(1);
            if (atlas == null)
            {
                throw new Exception("Failed to build the atlas.");
            }

            icons = atlas.GetTiles("icons");

            batch = new DrawBatch2D();
        }
Ejemplo n.º 2
0
        static void Init()
        {
            var font = new Font("Assets/NotoSans-Regular.ttf", FontCharSet.BasicLatin);
            var size = new FontSize(font, 128f);

            var builder = new AtlasBuilder(2048);

            builder.AddBitmap("Assets/star.png", true, true);
            builder.AddBitmap("Assets/face.png", true, true);
            builder.AddBitmap("Assets/maritte.png", true, true);
            builder.AddFont("font", size, true);

            atlas = builder.Build(1);
            if (atlas == null)
            {
                throw new Exception("Failed to build atlas.");
            }

            batch  = new DrawBatch2D();
            shader = new Shader(Shader.Basic2D);

            view = new GuiView(shader, Screen.DrawWidth, Screen.DrawHeight, LayoutMode.Horizontal);
            view.BackgroundColor = Color4.Grey;
            view.Spacing         = 16;
            view.SetPadding(16);

            var left = view.AddChild(new GuiContainer());

            left.BackgroundColor = Color4.Black * 0.25f;
            left.FlexX           = left.FlexY = true;
            left.Spacing         = 16;

            var right = view.AddChild(new GuiContainer());

            right.BackgroundColor = Color4.Blue;
            right.FlexX           = right.FlexY = true;

            var items = left.AddChild(new GuiContainer());

            items.BackgroundColor = Color4.Black * 0.25f;
            items.FlexX           = items.FlexY = true;
            items.Spacing         = 1;
            items.ScrollableY     = true;

            var padding = left.AddChild(new GuiContainer(100, 100, LayoutMode.Vertical));

            padding.BackgroundColor = Color4.White * 0.25f;
            padding.FlexX           = true;
            padding.FlexY           = false;

            for (int i = 0; i < 50; ++i)
            {
                var item = items.AddChild(new GuiElement(16, 40));
                item.FlexY     = false;
                item.OnRender += b => b.DrawRect(item.RectX, item.RectY, item.RectW, item.RectH, Color4.Red);
            }

            Screen.ClearColor = Color4.Black;
            Screen.OnResized += () => view.SetSize(Screen.DrawWidth, Screen.DrawHeight);
        }
Ejemplo n.º 3
0
        //private static void BuildAppConfigFile(string root_path, AppProject project)
        //{
        //    GameProperties props = new GameProperties()
        //    {
        //        Title = project.Title,
        //        FrameRate = project.FrameRate,
        //        CanvasWidth = project.CanvasWidth,
        //        CanvasHeight = project.CanvasHeight,
        //        Fullscreen = project.StartFullscreen,
        //        PreloadResourcePaks = project.PreloadPaks
        //    };

        //    File.WriteAllBytes(Path.Combine(root_path, "Config.json"),
        //        JsonSerializer.PrettyPrintByteArray(JsonSerializer.Serialize(props)));

        //}

        private static List <ResourcePak> BuildProjectResources(GameAssetsManifest manifest)
        {
            var resource_groups = manifest.Resources;

            var results = new List <ResourcePak>();

            foreach (var(groupKey, group) in resource_groups)
            {
                var pak = new ResourcePak(groupKey);

                Console.WriteLine($"Creating resource Pak: {pak.Name}");

                if (group.Images != null)
                {
                    foreach (var image_info in group.Images)
                    {
                        var pixmap_data = ImageBuilder.Build(image_info.Id, image_info.Path);

                        pak.Images.Add(image_info.Id, pixmap_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Image: {pixmap_data.Id}");
                    }
                }

                if (group.Shaders != null)
                {
                    foreach (var shader_info in group.Shaders)
                    {
                        var shader_data = ShaderBuilder.Build(shader_info.Id, shader_info.VsPath, shader_info.FsPath);

                        pak.Shaders.Add(shader_info.Id, shader_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Shader: {shader_data.Id}");
                    }
                }

                if (group.Fonts != null)
                {
                    foreach (var font_info in group.Fonts)
                    {
                        var build_params = new FontBuildParams()
                        {
                            Id          = font_info.Id,
                            LineSpacing = font_info.LineSpacing,
                            Spacing     = font_info.Spacing,
                            DefaultChar = font_info.DefaultChar,
                            Faces       = font_info.Faces.Select(f => new FontFace()
                            {
                                CharRanges = f.CharRanges.Select(CharRange.GetFromKey).ToList(),
                                Path       = f.Path,
                                Size       = f.Size,
                            }).ToList()
                        };

                        var font_data = FontBuilder.Build(build_params);

                        pak.Fonts.Add(font_info.Id, font_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Font: {font_data.Id}");
                    }
                }

                if (group.Atlases != null)
                {
                    foreach (var atlas_info in group.Atlases)
                    {
                        var atlas_data = AtlasBuilder.Build(atlas_info.Id, atlas_info.Path, atlas_info.Regions);

                        pak.Atlases.Add(atlas_data.Id, atlas_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Atlas: {atlas_data.Id}");
                    }
                }

                if (group.TextFiles != null)
                {
                    foreach (var text_file_info in group.TextFiles)
                    {
                        var text_file_data = TextBuilder.Build(text_file_info.Id, text_file_info.Path);
                        pak.TextFiles.Add(text_file_info.Id, text_file_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added TextFile: {text_file_data.Id}");
                    }
                }

                results.Add(pak);
                Console.WriteLine($"Built PAK with {pak.TotalResourcesCount} resources.");
            }

            return(results);
        }
Ejemplo n.º 4
0
        //private static void BuildAppConfigFile(string root_path, AppProject project)
        //{
        //    GameProperties props = new GameProperties()
        //    {
        //        Title = project.Title,
        //        FrameRate = project.FrameRate,
        //        CanvasWidth = project.CanvasWidth,
        //        CanvasHeight = project.CanvasHeight,
        //        Fullscreen = project.StartFullscreen,
        //        PreloadResourcePaks = project.PreloadPaks
        //    };

        //    File.WriteAllBytes(Path.Combine(root_path, "Config.json"),
        //        JsonSerializer.PrettyPrintByteArray(JsonSerializer.Serialize(props)));

        //}

        private static List <ResourcePak> BuildProjectResources(GameAssetsManifest manifest)
        {
            var resource_groups = manifest.Resources;

            var results = new List <ResourcePak>();

            foreach (var resource_group in resource_groups)
            {
                var pak = new ResourcePak(resource_group.Key);

                Console.WriteLine($"Creating resource Pak: {pak.Name}");

                if (resource_group.Value.Images != null)
                {
                    foreach (var image_info in resource_group.Value.Images)
                    {
                        var pixmap_data = ImageBuilder.Build(image_info.Id, image_info.Path);

                        pak.Images.Add(image_info.Id, pixmap_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Image: {pixmap_data.Id}");
                    }
                }

                if (resource_group.Value.Shaders != null)
                {
                    foreach (var shader_info in resource_group.Value.Shaders)
                    {
                        var shader_data = ShaderBuilder.Build(shader_info.Id, shader_info.VsPath, shader_info.FsPath);

                        pak.Shaders.Add(shader_info.Id, shader_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Shader: {shader_data.Id}");
                    }
                }

                if (resource_group.Value.Fonts != null)
                {
                    foreach (var font_info in resource_group.Value.Fonts)
                    {
                        var build_params = new FontBuildParams()
                        {
                            Id             = font_info.Id,
                            Path           = font_info.Path,
                            Size           = font_info.Size,
                            CharRangeLevel = font_info.CharRangeLevel,
                            PaddingLeft    = font_info.Padding != null ? font_info.Padding[0] : 0,
                            PaddingRight   = font_info.Padding != null ? font_info.Padding[1] : 0,
                            PaddingUp      = font_info.Padding != null ? font_info.Padding[2] : 0,
                            PaddingDown    = font_info.Padding != null ? font_info.Padding[3] : 0,
                            DropShadow     = font_info.DropShadow,
                            ShadowOffsetX  = font_info.ShadowOffsetX,
                            ShadowOffsetY  = font_info.ShadowOffsetY,
                            ShadowColor    = font_info.ShadowColor != null?Color.FromHex(font_info.ShadowColor) : Color.Black
                        };

                        var font_data = FontBuilder.Build(build_params);

                        pak.Fonts.Add(font_info.Id, font_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Font: {font_data.Id}");
                    }
                }

                if (resource_group.Value.Atlases != null)
                {
                    foreach (var atlas_info in resource_group.Value.Atlases)
                    {
                        var atlas_data = AtlasBuilder.Build(atlas_info.Id, atlas_info.Path, atlas_info.Regions);

                        pak.Atlases.Add(atlas_data.Id, atlas_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added Atlas: {atlas_data.Id}");
                    }
                }

                if (resource_group.Value.TextFiles != null)
                {
                    foreach (var text_file_info in resource_group.Value.TextFiles)
                    {
                        var text_file_data = TextBuilder.Build(text_file_info.Id, text_file_info.Path);
                        pak.TextFiles.Add(text_file_info.Id, text_file_data);

                        pak.TotalResourcesCount++;

                        Console.WriteLine($"Added TextFile: {text_file_data.Id}");
                    }
                }

                results.Add(pak);
                Console.WriteLine($"Built PAK with {pak.TotalResourcesCount} resources.");
            }

            return(results);
        }