TinyLifeExampleMod/ExampleMod.cs

70 lines
3.1 KiB
C#
Raw Permalink Normal View History

2020-11-25 00:33:47 +01:00
using System.Collections.Generic;
using ExtremelySimpleLogger;
using Microsoft.Xna.Framework;
2020-11-28 17:05:46 +01:00
using Microsoft.Xna.Framework.Graphics;
2020-11-25 00:33:47 +01:00
using MLEM.Data;
using MLEM.Data.Content;
2020-11-28 17:05:46 +01:00
using MLEM.Textures;
2020-11-25 00:33:47 +01:00
using TinyLife;
using TinyLife.Mods;
using TinyLife.Objects;
using TinyLife.Utilities;
namespace ExampleMod {
public class ExampleMod : Mod {
// the logger that we can use to log info about this mod
public static Logger Logger { get; private set; }
// visual data about this mod
public override string Name => "Example Mod";
public override string Description => "This is the example mod for Tiny Life!";
2021-02-18 19:12:01 +01:00
public override TextureRegion Icon => this.uiTextures[0, 0];
2020-11-25 00:33:47 +01:00
2020-11-28 17:05:46 +01:00
private UniformTextureAtlas customClothes;
2021-02-18 19:12:01 +01:00
private UniformTextureAtlas uiTextures;
2020-11-25 00:33:47 +01:00
public override void AddGameContent(GameImpl game) {
// adding a custom furniture item
FurnitureType.Register(new FurnitureType.TypeSettings("ExampleMod.CustomTable", new Point(1, 1), ObjectCategory.Table, 150, ColorScheme.SimpleWood) {
2021-02-18 19:12:01 +01:00
ConstructedType = typeof(CustomTable),
Icon = this.Icon
2020-11-25 00:33:47 +01:00
});
2020-11-28 17:05:46 +01:00
// adding custom clothing
2021-05-17 23:35:34 +02:00
var darkShirt = new Clothes("ExampleMod.DarkShirt", ClothesLayer.Shirt,
2020-11-28 17:05:46 +01:00
this.customClothes[0, 0], // the top left in-world region (the rest will be auto-gathered from the atlas)
2021-05-17 23:35:34 +02:00
100, this.Icon, false, ColorScheme.WarmDark);
Clothes.Register(darkShirt);
// adding an event subscription to people
MapObject.OnEventsAttachable += o => {
if (o is Person person) {
// changing the walk speed to be doubled if a person is wearing our dark shirt
person.OnGetWalkSpeed += (ref float s) => {
if (person.WornClothes.TryGetValue(ClothesLayer.Shirt, out var shirt) && shirt.Type == darkShirt)
s *= 2;
};
}
};
2020-11-25 00:33:47 +01:00
}
2020-12-20 13:33:38 +01:00
public override void Initialize(Logger logger, RawContentManager content, RuntimeTexturePacker texturePacker) {
2020-11-25 00:33:47 +01:00
Logger = logger;
2021-02-18 19:12:01 +01:00
2020-11-28 17:05:46 +01:00
// loads a texture atlas with the given amount of separate texture regions in the x and y axes
2020-12-20 13:33:38 +01:00
// we submit it to the texture packer to increase rendering performance. The callback is invoked once packing is completed
2021-05-17 23:35:34 +02:00
texturePacker.Add(content.Load<Texture2D>("CustomClothes"), r => this.customClothes = new UniformTextureAtlas(r, 4, 8));
2021-02-18 19:12:01 +01:00
texturePacker.Add(content.Load<Texture2D>("UiTextures"), r => this.uiTextures = new UniformTextureAtlas(r, 8, 8));
2020-11-25 00:33:47 +01:00
}
2020-12-20 13:33:38 +01:00
public override IEnumerable<string> GetCustomFurnitureTextures() {
2020-11-25 00:33:47 +01:00
// tell the game about our custom furniture texture
2020-12-20 13:33:38 +01:00
// this needs to be a path to a data texture atlas, relative to our "Content" directory
// the texture atlas combines the png texture and the .atlas information
// see https://mlem.ellpeck.de/api/MLEM.Data.DataTextureAtlas.html for more info
yield return "CustomFurniture";
2020-11-25 00:33:47 +01:00
}
}
}