mirror of
https://github.com/Ellpeck/TinyLifeExampleMod.git
synced 2024-11-22 12:03:28 +01:00
0.25.1
This commit is contained in:
parent
ccd87ee252
commit
fa0514c7a2
4 changed files with 62 additions and 4 deletions
|
@ -14,5 +14,8 @@
|
|||
},
|
||||
"Actions": {
|
||||
"ExampleMod.SitOnGrass": "Sit on Grass"
|
||||
},
|
||||
"Ui": {
|
||||
"ExampleMod.DarkShirtSpeedOption": "Dark Shirt Speed"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ using ExtremelySimpleLogger;
|
|||
using MLEM.Data;
|
||||
using MLEM.Data.Content;
|
||||
using MLEM.Textures;
|
||||
using MLEM.Ui;
|
||||
using MLEM.Ui.Elements;
|
||||
using TinyLife;
|
||||
using TinyLife.Actions;
|
||||
using TinyLife.Emotions;
|
||||
|
@ -18,6 +20,7 @@ public class ExampleMod : Mod {
|
|||
|
||||
// the logger that we can use to log info about this mod
|
||||
public static Logger Logger { get; private set; }
|
||||
public static ModOptions Options { get; private set; }
|
||||
|
||||
public static EmotionModifier GrassSittingModifier { get; private set; }
|
||||
|
||||
|
@ -62,7 +65,7 @@ public class ExampleMod : Mod {
|
|||
// changing the walk speed to be doubled if a person is wearing our dark shirt
|
||||
person.OnGetWalkSpeed += (ref float s) => {
|
||||
if (person.CurrentOutfit.Clothes.TryGetValue(ClothesLayer.Shirt, out var shirt) && shirt.Type == darkShirt)
|
||||
s *= 2;
|
||||
s *= ExampleMod.Options.DarkShirtSpeedIncrease;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -82,10 +85,10 @@ public class ExampleMod : Mod {
|
|||
CanDoRandomly = true,
|
||||
// the solved needs indicate when the AI should mark this action as important, they don't actually have to match the action's behavior
|
||||
SolvedNeeds = new[] {NeedType.Energy},
|
||||
// make people more likely to sit down in the grass if they're uncomfortable
|
||||
// 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
|
||||
// since this action doesn't use objects (like chairs etc.), we set a texture to display instead
|
||||
Texture = this.uiTextures[1, 0]
|
||||
});
|
||||
|
||||
|
@ -99,6 +102,7 @@ public class ExampleMod : Mod {
|
|||
|
||||
public override void Initialize(Logger logger, RawContentManager content, RuntimeTexturePacker texturePacker, ModInfo info) {
|
||||
ExampleMod.Logger = logger;
|
||||
ExampleMod.Options = ModOptions.Load(info);
|
||||
|
||||
// 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
|
||||
|
@ -118,4 +122,18 @@ public class ExampleMod : Mod {
|
|||
yield return "CustomFurniture";
|
||||
}
|
||||
|
||||
// this method can be overridden to populate the section in the mod tab of the game's options menu where this mod's options should be displayed
|
||||
// this mod uses the ModOptions class to manage its options, though that is optional
|
||||
// in general, options should be stored in the ModInfo.OptionsFile file that is given to the mod by the game
|
||||
public override void PopulateOptions(Group group, ModInfo info) {
|
||||
group.AddChild(new Paragraph(Anchor.AutoLeft, 1, _ => $"{Localization.Get(LnCategory.Ui, "ExampleMod.DarkShirtSpeedOption")}: {ExampleMod.Options.DarkShirtSpeedIncrease}"));
|
||||
group.AddChild(new Slider(Anchor.AutoLeft, new Vector2(1, 12), 5, 5) {
|
||||
CurrentValue = ExampleMod.Options.DarkShirtSpeedIncrease,
|
||||
OnValueChanged = (_, v) => {
|
||||
ExampleMod.Options.DarkShirtSpeedIncrease = v;
|
||||
ExampleMod.Options.Save(info);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TinyLifeApi" Version="0.25.0" />
|
||||
<PackageReference Include="TinyLifeApi" Version="0.25.1" />
|
||||
|
||||
<PackageReference Include="ExtremelySimpleLogger" Version="1.2.5" />
|
||||
<PackageReference Include="Lib.Harmony" Version="2.2.1" />
|
||||
|
@ -13,6 +13,7 @@
|
|||
<PackageReference Include="MLEM.Extended" Version="6.0.0" />
|
||||
<PackageReference Include="MLEM.Startup" Version="6.0.0" />
|
||||
<PackageReference Include="MonoGame.Extended" Version="3.8.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.263" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
36
ModOptions.cs
Normal file
36
ModOptions.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using TinyLife;
|
||||
using TinyLife.Mods;
|
||||
|
||||
namespace ExampleMod;
|
||||
|
||||
// a simple implementation of custom options for the example mod
|
||||
public class ModOptions {
|
||||
|
||||
public float DarkShirtSpeedIncrease = 2;
|
||||
|
||||
// a simple save method for the mod options, which saves the current instance to the designated options file
|
||||
public void Save(ModInfo info) {
|
||||
ExampleMod.Logger.Info($"Saving options to {info.OptionsFile}");
|
||||
if (!info.OptionsFile.Directory.Exists)
|
||||
info.OptionsFile.Directory.Create();
|
||||
using var writer = new JsonTextWriter(info.OptionsFile.CreateText());
|
||||
SaveHandler.CreateSerializer(null).Serialize(writer, this);
|
||||
}
|
||||
|
||||
// a simple loader for the mod options, which uses the designated options file given to us by the game
|
||||
// this method loads an instance of the options using a JSON loader and then returns it to be used in ExampleMod
|
||||
public static ModOptions Load(ModInfo info) {
|
||||
ExampleMod.Logger.Info($"Loading options from {info.OptionsFile}");
|
||||
if (info.OptionsFile.Exists) {
|
||||
using var reader = new JsonTextReader(info.OptionsFile.OpenText());
|
||||
return SaveHandler.CreateSerializer(null).Deserialize<ModOptions>(reader);
|
||||
} else {
|
||||
var ret = new ModOptions();
|
||||
ret.Save(info);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue