Exemplo n.º 1
0
        public static List <Animation> LoadNewLayeredAnimationFormat(String Path)
        {
            if (!Animations.ContainsKey(Path))
            {
                try
                {
                    var anims = FileUtils.LoadJsonListFromMultipleSources <NewAnimationDescriptor>(Path, null, a => a.Name)
                                .Select(a => a.CreateAnimation()).ToList();
                    Animations.Add(Path, anims);
                }
                catch
                {
                    var errorAnimations = new List <Animation>();

                    errorAnimations.Add(
                        new Animation()
                    {
                        SpriteSheet = new SpriteSheet(ContentPaths.Error, 32),
                        Frames      = new List <Point> {
                            Point.Zero
                        },
                        Name = "ERROR"
                    });


                    Animations.Add(Path, errorAnimations);
                }
            }

            return(Animations[Path]);
        }
Exemplo n.º 2
0
        public static void InitializeDefaultLibrary()
        {
            TypeList  = FileUtils.LoadJsonListFromMultipleSources <GrassType>(ContentPaths.grass_types, null, g => g.Name);
            emptyType = TypeList[0];

            byte ID = 0;

            foreach (var type in TypeList)
            {
                type.ID = ID;
                ++ID;

                Types[type.Name] = type;

                if (type.FringeTiles != null)
                {
                    type.FringeTransitionUVs = CreateFringeUVs(type.FringeTiles);
                }

                if (type.InitialDecayValue > VoxelConstants.MaximumGrassDecay)
                {
                    type.InitialDecayValue = VoxelConstants.MaximumGrassDecay;
                    Console.WriteLine("Grass type " + type.Name + " with invalid InitialDecayValue");
                }
            }

            if (ID > 16)
            {
                Console.WriteLine("Allowed number of grass types exceeded. Limit is " + VoxelConstants.MaximumGrassTypes);
            }
        }
Exemplo n.º 3
0
        private static void InitializeEquipmentSlotTypes()
        {
            if (EquipmentSlotsInitialized)
            {
                return;
            }
            EquipmentSlotsInitialized = true;

            EquipmentSlotTypes = FileUtils.LoadJsonListFromMultipleSources <EquipmentSlotType>("Entities/Dwarf/ToolIcons/slot-types.json", null, p => p.Name);
        }
Exemplo n.º 4
0
        private static void InitializeCategoryIcons()
        {
            if (CategoryIconsInitialized)
            {
                return;
            }
            CategoryIconsInitialized = true;

            CategoryIcons = FileUtils.LoadJsonListFromMultipleSources <GameStates.CategoryIcon>("category-icons.json", null, (i) => i.Category);

            Console.WriteLine("Loaded Category Icon Library.");
        }
Exemplo n.º 5
0
        public InstanceRenderer(GraphicsDevice Device, ContentManager Content)
        {
            var instanceGroups = FileUtils.LoadJsonListFromMultipleSources <InstanceGroup>(ContentPaths.instance_groups, null, g => g.Name);

            foreach (var group in instanceGroups)
            {
                group.Initialize();
                InstanceTypes.Add(group.Name, group);
            }

            InstancesDrawn = 0;
        }
Exemplo n.º 6
0
        public static void InitializeStatics()
        {
            Biomes = FileUtils.LoadJsonListFromMultipleSources <BiomeData>(ContentPaths.World.biomes, null, b => b.Name);

            byte id = 0;

            foreach (var biome in Biomes)
            {
                biome.Biome = id;
                id++;
            }
        }
Exemplo n.º 7
0
        private static void LoadRaces()
        {
            if (Races != null)
            {
                return;
            }

            Races = new Dictionary <string, Race>();
            foreach (var race in FileUtils.LoadJsonListFromMultipleSources <Race>(ContentPaths.World.races, null, r => r.Name))
            {
                Races.Add(race.Name, race);
            }
        }
Exemplo n.º 8
0
        public static void AddClasses(string file)
        {
            if (!staticClassInitialized)
            {
                InitializeClassStatics();
            }

            List <EmployeeClassDef> defs = FileUtils.LoadJsonListFromMultipleSources <EmployeeClassDef>(file, null, c => c.Name);

            foreach (EmployeeClassDef empClass in defs)
            {
                Classes[empClass.Name] = new EmployeeClass(empClass);
            }
        }
Exemplo n.º 9
0
        public static void InitializeDefaultLibrary()
        {
            TypeList  = FileUtils.LoadJsonListFromMultipleSources <DecalType>(ContentPaths.decal_types, null, (dt) => dt.Name);
            emptyType = TypeList[0];

            byte ID = 0;

            foreach (var type in TypeList)
            {
                type.ID = ID;
                ++ID;

                Types[type.Name] = type;
            }
        }
Exemplo n.º 10
0
        public static void InitializeDefaultLibrary()
        {
            if (CraftItems != null)
            {
                return;
            }

            var craftList = FileUtils.LoadJsonListFromMultipleSources <CraftItem>(ContentPaths.craft_items, null, c => c.Name);

            CraftItems = new Dictionary <string, CraftItem>();

            foreach (var type in craftList)
            {
                CraftItems.Add(type.Name, type);
            }
        }
Exemplo n.º 11
0
        public static void InitializeDefaultLibrary(GraphicsDevice graphics)
        {
            if (TypeList != null)
            {
                return;
            }

            var cubeTexture = AssetManager.GetContentTexture(ContentPaths.Terrain.terrain_tiles);

            TypeList        = FileUtils.LoadJsonListFromMultipleSources <VoxelType>(ContentPaths.voxel_types, null, v => v.Name);
            emptyType       = TypeList[0];
            DesignationType = TypeList[1];

            short ID = 0;

            foreach (VoxelType type in TypeList)
            {
                type.ID = ID;
                ++ID;

                Types[type.Name]   = type;
                PrimitiveMap[type] = type.ID == 0 ? null : CreatePrimitive(graphics, cubeTexture, 32, 32, type.Top, type.Bottom, type.Sides);

                if (type.HasTransitionTextures)
                {
                    type.TransitionTextures = CreateTransitionUVs(graphics, cubeTexture, 32, 32, type.TransitionTiles, type.Transitions);
                }

                type.ExplosionSound = SoundSource.Create(type.ExplosionSoundResource);
                type.HitSound       = SoundSource.Create(type.HitSoundResources);
                if (type.ReleasesResource)
                {
                    if (ResourceLibrary.GetResourceByName(type.Name) == null)
                    {
                        var resource = new Resource(ResourceLibrary.GetResourceByName(type.ResourceToRelease))
                        {
                            Name      = type.Name,
                            ShortName = type.Name,
                            Tint      = type.Tint,
                            Generated = false
                        };
                        ResourceLibrary.Add(resource);
                        type.ResourceToRelease = resource.Name;
                    }
                }
            }
        }
Exemplo n.º 12
0
        public static void Initialize(GraphicsDevice graphics, ContentManager content)
        {
            Primitives = new Dictionary <string, GeometricPrimitive>();

            List <Matrix> treeTransforms = new List <Matrix> {
                Matrix.Identity, Matrix.CreateRotationY((float)Math.PI / 2.0f)
            };
            List <Color> treeTints = new List <Color> {
                Color.White, Color.White
            };

            var primitives = FileUtils.LoadJsonListFromMultipleSources <PrimitiveRecord>(ContentPaths.primitives, null, p => p.Name);

            foreach (var prim in primitives)
            {
                var spriteSheet = new NamedImageFrame(prim.Asset);
                int width       = spriteSheet.SafeGetImage().Width;
                int height      = spriteSheet.SafeGetImage().Height;
                switch (prim.Type)
                {
                case PrimitiveType.Box:
                    Primitives[prim.Name] = new OldBoxPrimitive(graphics, prim.BoxSize.X, prim.BoxSize.Y, prim.BoxSize.Z,
                                                                new OldBoxPrimitive.BoxTextureCoords(width, height,
                                                                                                     prim.BoxFaceData[0], prim.BoxFaceData[1], prim.BoxFaceData[2], prim.BoxFaceData[3], prim.BoxFaceData[4], prim.BoxFaceData[5])); // WTF
                    break;

                case PrimitiveType.Cross:
                    Primitives[prim.Name] = new BatchBillboardPrimitive(graphics, spriteSheet, width, height,
                                                                        new Point(0, 0), width / 32.0f, height / 32.0f, false, treeTransforms, treeTints, treeTints);
                    break;

                case PrimitiveType.Quad:
                    Primitives[prim.Name] = new BatchBillboardPrimitive(graphics, spriteSheet, width, height,
                                                                        new Point(0, 0), width / 32.0f, height / 32.0f, false,
                                                                        new List <Matrix> {
                        treeTransforms[0]
                    },
                                                                        new List <Color> {
                        treeTints[0]
                    },
                                                                        new List <Color> {
                        treeTints[0]
                    });
                    break;
                }
            }
        }
Exemplo n.º 13
0
        public static void Initialize()
        {
            if (IsInitialized)
            {
                return;
            }
            IsInitialized = true;
            string tileSheet = ContentPaths.Entities.Resources.resources;

            Resources = new Dictionary <ResourceType, Resource>();

            var resourceList = FileUtils.LoadJsonListFromMultipleSources <Resource>(ContentPaths.resource_items, null, r => r.Name);

            foreach (var resource in resourceList)
            {
                resource.Generated = false;
                Add(resource);
            }
        }
Exemplo n.º 14
0
        private static void InitializeRailLibrary()
        {
            if (RailInitialized)
            {
                return;
            }
            RailInitialized = true;

            RailPieces   = FileUtils.LoadJsonListFromMultipleSources <RailPiece>(ContentPaths.rail_pieces, null, p => p.Name);
            RailPatterns = FileUtils.LoadJsonListFromMultipleSources <JunctionPattern>(ContentPaths.rail_patterns, null, p => p.Name);

            RailCombinationTable = new CombinationTable();
            RailCombinationTable.LoadConfiguration(ContentPaths.rail_combinations);

            foreach (var piece in RailPieces)
            {
                piece.ComputeConnections();
            }

            for (var i = 0; i < RailPatterns.Count; ++i)
            {
                RailPatterns[i].Icon = i;
            }

            RailChainPatterns = RailPatterns
                                // Only pieces with well defined entrance and exits can be used in chains.
                                .Where(p => p.Entrance != null && p.Exit != null)
                                // We need them in every orientation - not worried about redundancies.
                                .SelectMany(p =>
            {
                return(new JunctionPattern[]
                {
                    p.Rotate(PieceOrientation.North),
                    p.Rotate(PieceOrientation.East),
                    p.Rotate(PieceOrientation.South),
                    p.Rotate(PieceOrientation.West)
                });
            })
                                // We need them with the endpoints switched as well.
                                .SelectMany(p =>
            {
                return(new JunctionPattern[]
                {
                    p,
                    new JunctionPattern
                    {
                        Pieces = p.Pieces,
                        Entrance = p.Exit,
                        Exit = p.Entrance,
                    }
                });
            })
                                // And they must be positioned so the entrance is at 0,0
                                .Select(p =>
            {
                if (p.Entrance.Offset.X == 0 && p.Entrance.Offset.Y == 0)
                {
                    return(p);
                }
                else
                {
                    return new JunctionPattern
                    {
                        Entrance = new JunctionPortal
                        {
                            Direction = p.Entrance.Direction,
                            Offset    = Point.Zero
                        },
                        Exit = new JunctionPortal
                        {
                            Direction = p.Exit.Direction,
                            Offset    = new Point(p.Exit.Offset.X - p.Entrance.Offset.X, p.Exit.Offset.Y - p.Entrance.Offset.Y)
                        },
                        Pieces = p.Pieces.Select(piece =>
                                                 new JunctionPiece
                        {
                            RailPiece   = piece.RailPiece,
                            Orientation = piece.Orientation,
                            Offset      = new Point(piece.Offset.X - p.Entrance.Offset.X, piece.Offset.Y - p.Entrance.Offset.Y)
                        }).ToList(),
                    }
                };
            })
                                .ToList();

            Console.WriteLine("Loaded Rail Library.");
        }