From 567c422f8cd42eba2437f9a8c2522716a1649be7 Mon Sep 17 00:00:00 2001 From: hazel Date: Mon, 26 Jan 2026 22:04:39 +0100 Subject: celesteia archive, last updated april 9th 2024 Signed-off-by: hazel --- source/resources/collections/BaseCollection.cs | 207 +++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 source/resources/collections/BaseCollection.cs (limited to 'source/resources/collections/BaseCollection.cs') diff --git a/source/resources/collections/BaseCollection.cs b/source/resources/collections/BaseCollection.cs new file mode 100644 index 0000000..2af029e --- /dev/null +++ b/source/resources/collections/BaseCollection.cs @@ -0,0 +1,207 @@ +using System.Collections.Generic; +using Celesteia.Game.Components; +using Celesteia.Game.ECS; +using Celesteia.Game.Items; +using Celesteia.Graphics.Lighting; +using Celesteia.Resources.Types; +using Celesteia.Resources.Types.Builders; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using MonoGame.Extended.TextureAtlases; + +/* + A collection of resources for the base game. +*/ +namespace Celesteia.Resources.Collections { + public class BaseCollection : IResourceCollection + { + public NamespacedKey GetKey(string index) => NamespacedKey.Base(index); + + private ContentManager _content; + public BaseCollection(ContentManager Content) { + _content = Content; + } + + + public Dictionary GetBlocks() => LoadBlocks(); + private Dictionary blocks; + private Dictionary LoadBlocks(int pixelSize = 8) { + if (blocks != null) return blocks; + + void AddBlock(string index, BlockType type) => blocks.Add(GetKey(index), type); + + TextureAtlas _atlas = TextureAtlas.Create("blocks", _content.Load("sprites/blocks"), pixelSize, pixelSize); + BlockTypeBuilder builder = new BlockTypeBuilder(_atlas); + + blocks = new Dictionary(); + AddBlock("air", builder.WithName("Air").Invisible().Get()); + AddBlock("grown_soil", builder.WithName("Grown Soil").Full().Frames(0).Properties( + strength: 5, + drop: GetKey("soil") + ).Get()); + AddBlock("soil", builder.WithName("Soil").Full().Frames(1).Properties( + strength: 5, + drop: GetKey("soil") + ).Get()); + AddBlock("stone", builder.WithName("Stone").Full().Frames(2).Properties( + strength: 7, + drop: GetKey("stone") + ).Get()); + AddBlock("deepstone", builder.WithName("Deepstone").Full().Frames(3).Properties( + strength: -1, + drop: GetKey("deepstone") + ).Get()); + AddBlock("log", builder.WithName("Wooden Log").Full().Frames(10).Properties( + strength: 2, + drop: GetKey("log") + ).Get()); + AddBlock("leaves", builder.WithName("Leaves").Walkthrough().Frames(11).Properties( + translucent: true, + strength: 1, + light: new BlockLightProperties(LightColor.black, 0, false) + ).Get()); + AddBlock("iron_ore", builder.WithName("Iron Ore").Full().Frames(8).Properties( + strength: 15, + drop: GetKey("iron_ore") + ).Get()); + AddBlock("copper_ore", builder.WithName("Copper Ore").Full().Frames(7).Properties( + strength: 10, + drop: GetKey("copper_ore") + ).Get()); + AddBlock("coal_ore", builder.WithName("Coal Ore").Full().Frames(14).Properties( + strength: 10, + drop: GetKey("coal") + ).Get()); + AddBlock("wooden_planks", builder.WithName("Wooden Planks").Full().Frames(4).Properties( + strength: 4, + drop: GetKey("wooden_planks") + ).Get()); + AddBlock("torch", builder.WithName("Torch").Walkthrough().Frames(9).Properties( + translucent: true, + strength: 1, + drop: GetKey("wooden_torch"), + light: new BlockLightProperties(LightColor.white, 6, false) + ).Get()); + AddBlock("stone_bricks", builder.WithName("Stone Bricks").Frames(6).Full().Properties( + strength: 7, + drop: GetKey("stone_bricks") + ).Get()); + AddBlock("unyx_bricks", builder.WithName("Unyx Bricks").Frames(12).Full().Properties( + strength: 10, + drop: GetKey("unyx_bricks") + ).Get()); + AddBlock("unyx_eyestone", builder.WithName("Unyx Eyestone").Frames(13).Full().Properties( + strength: 10, + drop: GetKey("unyx_eyestone"), + light: new BlockLightProperties(new LightColor(230f, 74f, 255f), 5, true) + ).Get()); + AddBlock("scorched_soil", builder.WithName("Scorched Soil").Frames(15).Full().Properties( + strength: -1 + ).Get()); + AddBlock("blue_flower", builder.WithName("Morning Stars").Frames(16).Walkthrough().Properties( + strength: 1, + drop: GetKey("blue_flower_bundle"), + light: new BlockLightProperties(LightColor.black, 0, false) + ).Get()); + AddBlock("red_flower", builder.WithName("Red Tears").Frames(17).Walkthrough().Properties( + strength: 1, + drop: GetKey("red_flower_bundle"), + light: new BlockLightProperties(LightColor.black, 0, false) + ).Get()); + AddBlock("violet_flower", builder.WithName("Colupria").Frames(18).Walkthrough().Properties( + strength: 1, + drop: GetKey("violet_flower_bundle"), + light: new BlockLightProperties(LightColor.black, 0, false) + ).Get()); + AddBlock("grass", builder.WithName("Grass").Frames(19).Walkthrough().Properties( + strength: 1, + light: new BlockLightProperties(LightColor.black, 0, false) + ).Get()); + AddBlock("crashed_capsule_base", builder.WithName("Crashed Capsule").UniqueFrames( + TextureAtlas.Create("cc", _content.Load("sprites/crashed_capsule"), pixelSize * 3, pixelSize * 3), 0, 1, + new Vector2(pixelSize * 1, pixelSize * 2) + ).Walkthrough().Properties( + translucent: true, + strength: -1, + light: new BlockLightProperties(LightColor.black, 0, false) + ).Get()); + AddBlock("crashed_capsule_frame", builder.WithName("Crashed Capsule").Invisible().Properties( + translucent: true, + strength: -1, + light: new BlockLightProperties(LightColor.black, 0, false) + ).Get()); + + return blocks; + } + + public Dictionary GetItems() => LoadItems(); + private Dictionary items; + private Dictionary LoadItems(int pixelSize = 16) { + if (items != null) return items; + + void AddItem(string index, ItemType type) => items.Add(GetKey(index), type); + + TextureAtlas _atlas = TextureAtlas.Create("items", _content.Load("sprites/items"), pixelSize, pixelSize); + ItemTypeBuilder builder = new ItemTypeBuilder(_atlas); + + items = new Dictionary(); + if (blocks != null) { + foreach (KeyValuePair pair in blocks) { + if (pair.Value.Frames == null) continue; + AddItem(pair.Key.Index, builder.WithName(pair.Value.Name).Block(pair.Key).Frame(pair.Value.Frames.GetFrame(0).GetRegion()).Get()); + } + } + + AddItem("iron_pickaxe", builder.WithName("Iron Pickaxe").Pickaxe(4).Frame(0).Get()); + AddItem("wooden_log", builder.WithName("Wooden Log").Frame(1).Block(NamespacedKey.Base("log")).Get()); + AddItem("coal", builder.WithName("Coal Lump").Frame(2).Get()); + AddItem("plank", builder.WithName("Plank").Frame(3).Get()); + AddItem("copper_ingot", builder.WithName("Copper Ingot").Frame(4).Get()); + AddItem("iron_ingot", builder.WithName("Iron Ingot").Frame(5).Get()); + AddItem("fuel_tank", builder.WithName("Fuel Tank").Frame(6).Upgrade(EntityAttribute.JumpFuel, 0.5f, 5f).Get()); + AddItem("wooden_torch", builder.WithName("Wooden Torch").Template(new ItemTypeTemplate(1000, true)) + .Frame(7).Actions(new TorchItemActions(NamespacedKey.Base("torch"))).Get()); + AddItem("blue_flower_bundle", builder.WithName("Morning Stars").Template(new ItemTypeTemplate(1000, true)) + .Frame(10).Actions(new FoliageItemActions(NamespacedKey.Base("blue_flower"))).Get()); + AddItem("red_flower_bundle", builder.WithName("Red Tears").Template(new ItemTypeTemplate(1000, true)) + .Frame(11).Actions(new FoliageItemActions(NamespacedKey.Base("red_flower"))).Get()); + AddItem("violet_flower_bundle", builder.WithName("Colupria").Template(new ItemTypeTemplate(1000, true)) + .Frame(12).Actions(new FoliageItemActions(NamespacedKey.Base("violet_flower"))).Get()); + + return items; + } + + public Dictionary GetRecipes() => LoadRecipes(); + private Dictionary recipes; + private Dictionary LoadRecipes() { + if (recipes != null) return recipes; + + void AddRecipe(string index, Recipe type) => recipes.Add(GetKey(index), type); + + recipes = new Dictionary(); + AddRecipe("plank_ingredient", new Recipe(new Part(GetKey("plank"), 4), new Part(GetKey("log"), 1))); + AddRecipe("plank_block", new Recipe(new Part(GetKey("wooden_planks"), 1), new Part(GetKey("plank"), 2))); + AddRecipe("copper_smelt", new Recipe(new Part(GetKey("copper_ingot"), 1), new Part(GetKey("copper_ore"), 1))); + AddRecipe("iron_smelt", new Recipe(new Part(GetKey("iron_ingot"), 1), new Part(GetKey("iron_ore"), 1))); + AddRecipe("fuel_tank", new Recipe(new Part(GetKey("fuel_tank"), 1), new Part(GetKey("iron_ingot"), 10), new Part(GetKey("copper_ingot"), 5))); + AddRecipe("torches", new Recipe(new Part(GetKey("wooden_torch"), 4), new Part(GetKey("plank"), 1), new Part(GetKey("coal"), 1))); + AddRecipe("stone_brick", new Recipe(new Part(GetKey("stone_bricks"), 4), new Part(GetKey("stone"), 4))); + + return recipes; + } + + public Dictionary GetEntities() => LoadEntities(); + private Dictionary entities; + private Dictionary LoadEntities() { + if (entities != null) return entities; + + void AddEntity(string index, EntityType type) => entities.Add(GetKey(index), type); + + entities = new Dictionary(); + AddEntity("player", new EntityType((e) => EntityFactory.BuildPlayer(e, _content.Load("sprites/entities/player/astronaut")))); + + return entities; + } + } +} \ No newline at end of file -- cgit v1.2.3