2020-11-25 00:33:47 +01:00
|
|
|
using System.Collections.Generic;
|
2021-05-22 18:14:05 +02:00
|
|
|
using System.Linq;
|
2020-11-25 00:33:47 +01:00
|
|
|
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;
|
2021-05-22 17:39:17 +02:00
|
|
|
using TinyLife.Actions;
|
|
|
|
using TinyLife.Emotions;
|
2020-11-25 00:33:47 +01:00
|
|
|
using TinyLife.Mods;
|
|
|
|
using TinyLife.Objects;
|
|
|
|
using TinyLife.Utilities;
|
|
|
|
|
2021-12-25 18:05:47 +01:00
|
|
|
namespace ExampleMod;
|
2020-11-25 00:33:47 +01:00
|
|
|
|
2021-12-23 23:23:56 +01:00
|
|
|
public class ExampleMod : Mod {
|
2020-11-25 00:33:47 +01:00
|
|
|
|
2021-12-23 23:23:56 +01:00
|
|
|
// the logger that we can use to log info about this mod
|
|
|
|
public static Logger Logger { get; private set; }
|
2021-05-22 17:39:17 +02:00
|
|
|
|
2021-12-23 23:23:56 +01:00
|
|
|
public static EmotionModifier GrassSittingModifier { get; private set; }
|
2020-11-25 00:33:47 +01:00
|
|
|
|
2021-12-23 23:23:56 +01:00
|
|
|
// visual data about this mod
|
|
|
|
public override string Name => "Example Mod";
|
|
|
|
public override string Description => "This is the example mod for Tiny Life!";
|
|
|
|
public override TextureRegion Icon => this.uiTextures[0, 0];
|
2020-11-25 00:33:47 +01:00
|
|
|
|
2021-12-23 23:23:56 +01:00
|
|
|
private UniformTextureAtlas customTops;
|
|
|
|
private UniformTextureAtlas customHairs;
|
|
|
|
private UniformTextureAtlas customBottoms;
|
|
|
|
private UniformTextureAtlas uiTextures;
|
2020-11-28 17:05:46 +01:00
|
|
|
|
2022-03-09 16:12:57 +01:00
|
|
|
public override void AddGameContent(GameImpl game, ModInfo info) {
|
2021-12-23 23:23:56 +01:00
|
|
|
// adding a custom furniture item
|
|
|
|
FurnitureType.Register(new FurnitureType.TypeSettings("ExampleMod.CustomTable", new Point(1, 1), ObjectCategory.Table, 150, ColorScheme.SimpleWood) {
|
|
|
|
// specify the type that should be constructed when this furniture type is placed
|
|
|
|
// if this is not specified, the Furniture class is used, which is used for furniture without special animations or data
|
|
|
|
ConstructedType = typeof(CustomTable),
|
|
|
|
// specifying icons for custom clothes and furniture is optional, but using the mod's icon helps users recognize a mod's features
|
|
|
|
Icon = this.Icon,
|
|
|
|
// allow chairs and plates to be slotted into and onto the table
|
|
|
|
ObjectSpots = ObjectSpot.TableSpots(new Point(1, 1)).ToArray()
|
|
|
|
});
|
2021-05-17 23:35:34 +02:00
|
|
|
|
2021-12-23 23:23:56 +01:00
|
|
|
// adding custom clothing
|
|
|
|
var darkShirt = new Clothes("ExampleMod.DarkShirt", ClothesLayer.Shirt,
|
|
|
|
this.customTops[0, 0], // the top left in-world region (the rest will be auto-gathered from the atlas)
|
|
|
|
100, // the price
|
|
|
|
ClothesIntention.Everyday | ClothesIntention.Workout, // the clothes item's use cases
|
|
|
|
ColorScheme.WarmDark) {Icon = this.Icon};
|
|
|
|
Clothes.Register(darkShirt);
|
|
|
|
// adding some more custom clothing
|
|
|
|
Clothes.Register(new Clothes("ExampleMod.PastelPants", ClothesLayer.Pants, this.customBottoms[4, 0], 100, ClothesIntention.Everyday, ColorScheme.Pastel) {Icon = this.Icon});
|
|
|
|
Clothes.Register(new Clothes("ExampleMod.PastelShoes", ClothesLayer.Shoes, this.customBottoms[0, 0], 100, ClothesIntention.Everyday, ColorScheme.Pastel) {Icon = this.Icon});
|
|
|
|
Clothes.Register(new Clothes("ExampleMod.WeirdHair", ClothesLayer.Hair, this.customHairs[0, 0], 0, ClothesIntention.None, ColorScheme.Modern) {Icon = this.Icon});
|
2021-05-22 17:39:17 +02:00
|
|
|
|
2021-12-23 23:23:56 +01:00
|
|
|
// 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) => {
|
2022-01-01 17:06:02 +01:00
|
|
|
if (person.CurrentOutfit.Clothes.TryGetValue(ClothesLayer.Shirt, out var shirt) && shirt.Type == darkShirt)
|
2021-12-23 23:23:56 +01:00
|
|
|
s *= 2;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2020-11-25 00:33:47 +01:00
|
|
|
|
2021-12-23 23:23:56 +01:00
|
|
|
// adding a simple action: sitting down in the grass, which also gives us a nice emotion modifier
|
|
|
|
ActionType.Register(new ActionType.TypeSettings("ExampleMod.SitOnGrass", ObjectCategory.Ground, typeof(SitDownOnGrassAction)) {
|
|
|
|
// we set this action to be executable only on grass tiles, not on other ground
|
|
|
|
CanExecute = (info, automatic) => {
|
|
|
|
if (!info.Map.IsInBounds(info.ActionLocation.ToPoint()))
|
|
|
|
return ActionType.CanExecuteResult.Hidden;
|
|
|
|
var tile = info.Map.GetTile(info.ActionLocation.ToPoint());
|
|
|
|
if (tile.Name.StartsWith("Grass"))
|
|
|
|
return ActionType.CanExecuteResult.Valid;
|
|
|
|
// hidden means the action won't be displayed in the ring menu
|
|
|
|
return ActionType.CanExecuteResult.Hidden;
|
|
|
|
},
|
|
|
|
Ai = {
|
|
|
|
// we allow the action to be done even if the solved needs aren't low enough on a person
|
|
|
|
CanDoRandomly = true,
|
|
|
|
SolvedNeeds = new[] {NeedType.Energy},
|
|
|
|
// make people more likely to sit down in the grass if they're uncomfortable
|
|
|
|
PassivePriority = p => p.Emotion == EmotionType.Uncomfortable ? 150 : 25
|
|
|
|
},
|
|
|
|
// since this action doesn't use objects (like chairs etc.), we set a texture to display instead
|
|
|
|
Texture = this.uiTextures[1, 0]
|
|
|
|
});
|
|
|
|
GrassSittingModifier = EmotionModifier.Register(
|
|
|
|
new EmotionModifier("ExampleMod.GrassSitting", this.uiTextures[1, 0], EmotionType.Happy));
|
|
|
|
}
|
2021-02-18 19:12:01 +01:00
|
|
|
|
2022-03-09 16:12:57 +01:00
|
|
|
public override void Initialize(Logger logger, RawContentManager content, RuntimeTexturePacker texturePacker, ModInfo info) {
|
2021-12-23 23:23:56 +01:00
|
|
|
Logger = logger;
|
2020-11-25 00:33:47 +01:00
|
|
|
|
2021-12-23 23:23:56 +01:00
|
|
|
// loads a texture atlas with the given amount of separate texture regions in the x and y axes
|
|
|
|
// we submit it to the texture packer to increase rendering performance. The callback is invoked once packing is completed
|
|
|
|
texturePacker.Add(content.Load<Texture2D>("CustomTops"), r => this.customTops = new UniformTextureAtlas(r, 4, 8));
|
|
|
|
texturePacker.Add(content.Load<Texture2D>("CustomHairs"), r => this.customHairs = new UniformTextureAtlas(r, 4, 6));
|
|
|
|
texturePacker.Add(content.Load<Texture2D>("CustomBottomsShoes"), r => this.customBottoms = new UniformTextureAtlas(r, 8, 6));
|
|
|
|
texturePacker.Add(content.Load<Texture2D>("UiTextures"), r => this.uiTextures = new UniformTextureAtlas(r, 8, 8));
|
|
|
|
}
|
2020-11-25 00:33:47 +01:00
|
|
|
|
2022-03-09 16:12:57 +01:00
|
|
|
public override IEnumerable<string> GetCustomFurnitureTextures(ModInfo info) {
|
2021-12-23 23:23:56 +01:00
|
|
|
// tell the game about our custom furniture texture
|
|
|
|
// 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
|
|
|
}
|
2021-12-23 23:23:56 +01:00
|
|
|
|
2020-11-25 00:33:47 +01:00
|
|
|
}
|