private static void InitializeDesignations() { lock (DesignationLock) { if (DesignationInitialized) { return; } DesignationInitialized = true; Designations = new Dictionary <DesignationType, DesignationTypeProperties>(); foreach (var des in FileUtils.LoadJsonListFromDirectory <DesignationTypeProperties>("World/Designations", null, r => r.Name)) { if (des.Name == "default") { DefaultDesignation = des; } else { Designations.Add((DesignationType)Enum.Parse(typeof(DesignationType), des.Name), des); } } Console.WriteLine("Loaded Designation Library."); } }
private static void InitializeZoneTypes() { if (ZoneTypesInitialized) { return; } ZoneTypesInitialized = true; ZoneTypes = FileUtils.LoadJsonListFromDirectory <ZoneType>(ContentPaths.room_types, null, d => d.Name); ZoneFactoryFunctions = new Dictionary <string, Func <String, WorldManager, Zone> >(); foreach (var method in AssetManager.EnumerateModHooks(typeof(ZoneFactoryAttribute), typeof(Zone), new Type[] { typeof(String), typeof(WorldManager) })) { var attribute = method.GetCustomAttributes(false).FirstOrDefault(a => a is ZoneFactoryAttribute) as ZoneFactoryAttribute; if (attribute == null) { continue; } ZoneFactoryFunctions[attribute.Name] = (data, world) => method.Invoke(null, new Object[] { data, world }) as Zone; } }
private static void InitializeStatics() { if (RoomTypes != null) { return; } RoomTypes = FileUtils.LoadJsonListFromDirectory <RoomData>(ContentPaths.room_types, null, d => d.Name); RoomFuncs = new Dictionary <string, Func <RoomData, Faction, WorldManager, Room> >(); foreach (var method in AssetManager.EnumerateModHooks(typeof(RoomFactoryAttribute), typeof(Room), new Type[] { typeof(RoomData), typeof(Faction), typeof(WorldManager) })) { var attribute = method.GetCustomAttributes(false).FirstOrDefault(a => a is RoomFactoryAttribute) as RoomFactoryAttribute; if (attribute == null) { continue; } RoomFuncs[attribute.Name] = (data, faction, world) => method.Invoke(null, new Object[] { data, faction, world }) as Room; } }
private static void InitializeResources() { if (ResourcesInitialized) { return; } ResourcesInitialized = true; Resources = new Dictionary <String, ResourceType>(); var resourceList = FileUtils.LoadJsonListFromDirectory <ResourceType>("World\\ResourceItems", null, r => r.TypeName); foreach (var resource in resourceList) { Resources[resource.TypeName] = resource; //if (resource.Tags.Contains("Money")) // EntityFactory.RegisterEntity(resource.TypeName + " Resource", (position, data) => new CoinPile(EntityFactory.World.ComponentManager, position) // { // Money = data.Has("Money") ? data.GetData<DwarfBux>("Money") : (DwarfBux)64m // }); //else // EntityFactory.RegisterEntity(resource.TypeName + " Resource", (position, data) => new ResourceEntity(EntityFactory.World.ComponentManager, new Resource(resource.TypeName), position)); } Console.WriteLine("Loaded Resource Library."); }
private static void InitializeVoxels() { if (VoxelsInitialized) { return; } VoxelsInitialized = true; var cubeTexture = AssetManager.GetContentTexture(ContentPaths.Terrain.terrain_tiles); VoxelTypeList = FileUtils.LoadJsonListFromDirectory <VoxelType>(ContentPaths.voxel_types, null, v => v.Name); short id = 2; foreach (VoxelType type in VoxelTypeList) { VoxelTypes[type.Name] = type; if (type.Name == "_empty") { _EmptyVoxelType = type; type.ID = 0; } else { VoxelPrimitives[type.Name] = CreateVoxelPrimitive(cubeTexture, 32, 32, type.Top, type.Bottom, type.Sides); if (type.Name == "_designation") { _DesignationVoxelType = type; type.ID = 1; } else { type.ID = id; id += 1; } } if (type.HasTransitionTextures) { type.TransitionTextures = CreateTransitionUVs(cubeTexture, 32, 32, type.TransitionTiles, type.Transitions); } type.ExplosionSound = SoundSource.Create(type.ExplosionSoundResource); type.HitSound = SoundSource.Create(type.HitSoundResources); } VoxelTypeList = VoxelTypeList.OrderBy(v => v.ID).ToList(); if (VoxelTypeList.Count > VoxelConstants.MaximumVoxelTypes) { throw new InvalidProgramException(String.Format("There can be only {0} voxel types.", VoxelConstants.MaximumVoxelTypes)); } Console.WriteLine("Loaded Voxel Library."); }
private static void Initialize() { if (Initialized) { return; } Initialized = true; Diseases = FileUtils.LoadJsonListFromDirectory <Disease>(ContentPaths.diseases, null, d => d.Name); Console.WriteLine("Loaded Disease Library."); }
public static void InitializeStatics() { Biomes = FileUtils.LoadJsonListFromDirectory <BiomeData>(ContentPaths.World.biomes, null, b => b.Name); byte id = 0; foreach (var biome in Biomes) { biome.Biome = id; id++; } }
private static void InitializeDifficulties() { if (DifficultiesInitialized) { return; } DifficultiesInitialized = true; Difficulties = FileUtils.LoadJsonListFromDirectory <Difficulty>("World/Difficulties", null, b => b.Name); Difficulties.Sort((a, b) => a.CombatModifier - b.CombatModifier); Console.WriteLine("Loaded Difficulty Library."); }
private static void InitializeGrassLibrary() { if (GrassLibraryInitialized) { return; } GrassLibraryInitialized = true; GrassTypeList = FileUtils.LoadJsonListFromDirectory <GrassType>(ContentPaths.grass_types, null, g => g.Name); byte ID = 1; foreach (var type in GrassTypeList) { if (type.Name == "_empty") { type.ID = 0; continue; } else { type.ID = ID; ++ID; } GrassTypes[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 > VoxelConstants.MaximumGrassTypes) { Console.WriteLine("Allowed number of grass types exceeded. Limit is " + VoxelConstants.MaximumGrassTypes); } GrassTypeList = GrassTypeList.OrderBy(v => v.ID).ToList(); Console.WriteLine("Loaded Grass Library."); }
private static void InitializeClasses() { if (ClassesInitialized) { return; } ClassesInitialized = true; var list = FileUtils.LoadJsonListFromDirectory <CreatureClass>("World\\Classes", null, c => c.Name); Classes = new Dictionary <String, CreatureClass>(); foreach (var item in list) { Classes.Add(item.Name, item); } }
private static void InitializeRaces() { if (RacesInitialized) { return; } RacesInitialized = true; Races = new Dictionary <string, Race>(); foreach (var race in FileUtils.LoadJsonListFromDirectory <Race>(ContentPaths.World.races, null, r => r.Name)) { Races.Add(race.Name, race); } Console.WriteLine("Loaded Race Library."); }
public static void InitializeDefaultLibrary() { if (CraftItems != null) { return; } var craftList = FileUtils.LoadJsonListFromDirectory <CraftItem>(ContentPaths.craft_items, null, c => c.Name); CraftItems = new Dictionary <string, CraftItem>(); foreach (var type in craftList) { type.InitializeStrings(); CraftItems.Add(type.Name, type); } }
private static void InitializeCraftLibrary() { if (CraftLibraryInitialized) { return; } CraftLibraryInitialized = true; var craftList = FileUtils.LoadJsonListFromDirectory <CraftItem>(ContentPaths.craft_items, null, c => c.Name); CraftItems = new Dictionary <string, CraftItem>(); foreach (var type in craftList.Where(c => !c.Disable)) { type.InitializeStrings(); CraftItems.Add(type.Name, type); } Console.WriteLine("Loaded Craft Library."); }
private static void InitializeResources() { if (ResourcesInitialized) { return; } ResourcesInitialized = true; Resources = new Dictionary <String, Resource>(); var resourceList = FileUtils.LoadJsonListFromDirectory <Resource>("World\\ResourceItems", null, r => r.Name); foreach (var resource in resourceList) { resource.Generated = false; AddResourceType(resource); } Console.WriteLine("Loaded Resource Library."); }
private static void InitializeBiomes() { if (BiomesInitialized) { return; } BiomesInitialized = true; Biomes = FileUtils.LoadJsonListFromDirectory <BiomeData>(ContentPaths.World.biomes, null, b => b.Name); byte id = 0; foreach (var biome in Biomes) { biome.Biome = id; id++; } Console.WriteLine("Loaded Biome Library."); }
private static void InitializeResources() { if (ResourcesInitialized) { return; } ResourcesInitialized = true; Resources = new Dictionary <String, ResourceType>(); var resourceList = FileUtils.LoadJsonListFromDirectory <ResourceType>("World\\ResourceItems", null, r => r.TypeName); foreach (var resource in resourceList) { Resources[resource.TypeName] = resource; } PossibleTags = resourceList.SelectMany(r => r.Tags).Distinct().OrderBy(t => t).ToList(); Console.WriteLine("Loaded Resource Library."); }
private static void InitializeDecalLibrary() { if (DecalLibraryInitialized) { return; } DecalLibraryInitialized = true; var decals = FileUtils.LoadJsonListFromDirectory <DecalType>("World/DecalTypes", null, g => g.Name); byte ID = 1; foreach (var type in decals) { if (type.Name == "_empty") { type.ID = 0; continue; } else { type.ID = ID; ++ID; } DecalTypes[type.Name] = type; } if (ID > VoxelConstants.MaximumDecalTypes) { Console.WriteLine("Allowed number of decal types exceeded. Limit is " + VoxelConstants.MaximumDecalTypes); } DecalTypeList = decals.OrderBy(v => v.ID).ToList(); Console.WriteLine("Loaded Grass Library."); }
public static void InitializeDefaultLibrary(GraphicsDevice graphics) { if (TypeList != null) { return; } var cubeTexture = AssetManager.GetContentTexture(ContentPaths.Terrain.terrain_tiles); TypeList = FileUtils.LoadJsonListFromDirectory <VoxelType>(ContentPaths.voxel_types, null, v => v.Name); emptyType = TypeList.FirstOrDefault(v => v.Name == "_empty"); DesignationType = TypeList.FirstOrDefault(v => v.Name == "_designation"); // Todo: Stabalize ids across save games. short id = 2; foreach (VoxelType type in TypeList) { Types[type.Name] = type; if (type.Name == "_empty") { emptyType = type; type.ID = 0; } else { PrimitiveMap[type.Name] = CreatePrimitive(graphics, cubeTexture, 32, 32, type.Top, type.Bottom, type.Sides); if (type.Name == "_designation") { DesignationType = type; type.ID = 1; } else { type.ID = id; id += 1; } } 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; } } } TypeList = TypeList.OrderBy(v => v.ID).ToList(); if (TypeList.Count > VoxelConstants.MaximumVoxelTypes) { throw new InvalidProgramException(String.Format("There can be only {0} voxel types.", VoxelConstants.MaximumVoxelTypes)); } }