Compare commits
No commits in common. "main" and "0.31.1" have entirely different histories.
4
.gitignore
vendored
|
@ -1,6 +1,4 @@
|
||||||
bin/
|
bin/
|
||||||
obj/
|
obj/
|
||||||
/packages/
|
/packages/
|
||||||
.idea/
|
.idea
|
||||||
.vs/
|
|
||||||
.vscode/
|
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.1 KiB |
|
@ -1,8 +1,7 @@
|
||||||
{
|
{
|
||||||
"BuildMode": {
|
"BuildMode": {
|
||||||
"ExampleMod.CustomTable": "Custom Table",
|
"ExampleMod.CustomTable": "Custom Table",
|
||||||
"ExampleMod.CrossedWallpaper": "Crossed Wallpaper",
|
"ExampleMod.CrossedWallpaper": "Crossed Wallpaper"
|
||||||
"ExampleMod.CustomTile": "Custom Tile"
|
|
||||||
},
|
},
|
||||||
"Clothes": {
|
"Clothes": {
|
||||||
"ExampleMod.DarkShirt": "Dark Shirt",
|
"ExampleMod.DarkShirt": "Dark Shirt",
|
||||||
|
|
Before Width: | Height: | Size: 535 B |
140
ExampleMod.cs
|
@ -1,10 +1,6 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using ExtremelySimpleLogger;
|
using ExtremelySimpleLogger;
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
using MLEM.Data;
|
using MLEM.Data;
|
||||||
using MLEM.Data.Content;
|
using MLEM.Data.Content;
|
||||||
using MLEM.Textures;
|
using MLEM.Textures;
|
||||||
|
@ -17,7 +13,6 @@ using TinyLife.Mods;
|
||||||
using TinyLife.Objects;
|
using TinyLife.Objects;
|
||||||
using TinyLife.Utilities;
|
using TinyLife.Utilities;
|
||||||
using TinyLife.World;
|
using TinyLife.World;
|
||||||
using Action = TinyLife.Actions.Action;
|
|
||||||
|
|
||||||
namespace ExampleMod;
|
namespace ExampleMod;
|
||||||
|
|
||||||
|
@ -25,7 +20,7 @@ public class ExampleMod : Mod {
|
||||||
|
|
||||||
// the logger that we can use to log info about this mod
|
// the logger that we can use to log info about this mod
|
||||||
public static Logger Logger { get; private set; }
|
public static Logger Logger { get; private set; }
|
||||||
public static ExampleOptions Options { get; private set; }
|
public static ExampleModOptions Options { get; private set; }
|
||||||
|
|
||||||
public static EmotionModifier GrassSittingModifier { get; private set; }
|
public static EmotionModifier GrassSittingModifier { get; private set; }
|
||||||
|
|
||||||
|
@ -33,38 +28,19 @@ public class ExampleMod : Mod {
|
||||||
public override string Name => "Example Mod";
|
public override string Name => "Example Mod";
|
||||||
public override string Description => "This is the example mod for Tiny Life!";
|
public override string Description => "This is the example mod for Tiny Life!";
|
||||||
public override TextureRegion Icon => this.uiTextures[new Point(0, 0)];
|
public override TextureRegion Icon => this.uiTextures[new Point(0, 0)];
|
||||||
public override string IssueTrackerUrl => "https://github.com/Ellpeck/TinyLifeExampleMod/issues";
|
|
||||||
public override string TestedVersionRange => "[0.44.0,0.44.1]";
|
|
||||||
|
|
||||||
private Dictionary<Point, TextureRegion> customTops;
|
private Dictionary<Point, TextureRegion> customTops;
|
||||||
private Dictionary<Point, TextureRegion> customHairs;
|
private Dictionary<Point, TextureRegion> customHairs;
|
||||||
private Dictionary<Point, TextureRegion> customBottoms;
|
private Dictionary<Point, TextureRegion> customBottoms;
|
||||||
private Dictionary<Point, TextureRegion> uiTextures;
|
private Dictionary<Point, TextureRegion> uiTextures;
|
||||||
private Dictionary<Point, TextureRegion> wallpaperTextures;
|
private Dictionary<Point, TextureRegion> wallpaperTextures;
|
||||||
private Dictionary<Point, TextureRegion> tileTextures;
|
|
||||||
|
|
||||||
public override void Initialize(Logger logger, RawContentManager content, RuntimeTexturePacker texturePacker, ModInfo info) {
|
|
||||||
ExampleMod.Logger = logger;
|
|
||||||
ExampleMod.Options = info.LoadOptions(() => new ExampleOptions());
|
|
||||||
|
|
||||||
// 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
|
|
||||||
// additionally, we pad all texture regions by 1 pixel, so that rounding errors during rendering don't cause visual artifacts
|
|
||||||
texturePacker.Add(new UniformTextureAtlas(content.Load<Texture2D>("CustomTops"), 4, 11), r => this.customTops = r, 1, true);
|
|
||||||
texturePacker.Add(new UniformTextureAtlas(content.Load<Texture2D>("CustomHairs"), 4, 5), r => this.customHairs = r, 1, true);
|
|
||||||
texturePacker.Add(new UniformTextureAtlas(content.Load<Texture2D>("CustomBottomsShoes"), 8, 6), r => this.customBottoms = r, 1, true);
|
|
||||||
texturePacker.Add(new UniformTextureAtlas(content.Load<Texture2D>("UiTextures"), 8, 8), r => this.uiTextures = r, 1, true);
|
|
||||||
texturePacker.Add(new UniformTextureAtlas(content.Load<Texture2D>("Tiles"), 4, 2), r => this.tileTextures = r, 1, true);
|
|
||||||
// wallpaper textures require special treatment to work with openings, the x and y values are passed to the UniformTextureAtlas constructor
|
|
||||||
WallMode.ApplyMasks(content.Load<Texture2D>("Wallpapers"), 4, 5, texturePacker, r => this.wallpaperTextures = r);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void AddGameContent(GameImpl game, ModInfo info) {
|
public override void AddGameContent(GameImpl game, ModInfo info) {
|
||||||
// adding a custom furniture item
|
// adding a custom furniture item
|
||||||
FurnitureType.Register(new FurnitureType.TypeSettings("ExampleMod.CustomTable", new Point(1, 1), ObjectCategory.Table, 150, ColorScheme.SimpleWood) {
|
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
|
// 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
|
// if this is not specified, the Furniture class is used, which is used for furniture without special animations or data
|
||||||
ConstructedType = typeof(ExampleTable),
|
ConstructedType = typeof(ExampleModTable),
|
||||||
// specifying icons for custom clothes and furniture is optional, but using the mod's icon helps users recognize a mod's features
|
// 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,
|
Icon = this.Icon,
|
||||||
// allow chairs and plates to be slotted into and onto the table
|
// allow chairs and plates to be slotted into and onto the table
|
||||||
|
@ -73,25 +49,15 @@ public class ExampleMod : Mod {
|
||||||
|
|
||||||
// adding custom clothing
|
// adding custom clothing
|
||||||
var darkShirt = new Clothes("ExampleMod.DarkShirt", ClothesLayer.Shirt,
|
var darkShirt = new Clothes("ExampleMod.DarkShirt", ClothesLayer.Shirt,
|
||||||
// the top left in-world region
|
this.customTops, new Point(0, 0), // the top left in-world region (the rest will be auto-gathered from the atlas)
|
||||||
// additional regions will be auto-gathered from the atlas according to the rules described in https://docs.tinylifegame.com/articles/creating_textures.html
|
100, // the price
|
||||||
this.customTops, new Point(0, 0),
|
ClothesIntention.Everyday | ClothesIntention.Workout, // the clothes item's use cases
|
||||||
// the price
|
ColorScheme.WarmDark) {Icon = this.Icon};
|
||||||
100,
|
|
||||||
// the clothes item's use cases
|
|
||||||
ClothesIntention.Everyday | ClothesIntention.Workout,
|
|
||||||
// the clothes item's style preferences, which influence randomly generated tinies slightly
|
|
||||||
// neutral style preferences have the same chance to be picked for all tinies, others have a 25% chance for mismatched preferences
|
|
||||||
StylePreference.Neutral,
|
|
||||||
// the clothes item's color scheme
|
|
||||||
// if the item should have multiple layers, multiple color schemes can be supplied here (see docs above)
|
|
||||||
ColorScheme.WarmDark
|
|
||||||
) {Icon = this.Icon};
|
|
||||||
Clothes.Register(darkShirt);
|
Clothes.Register(darkShirt);
|
||||||
// adding some more custom clothing
|
// adding some more custom clothing
|
||||||
Clothes.Register(new Clothes("ExampleMod.PastelPants", ClothesLayer.Pants, this.customBottoms, new Point(4, 0), 100, ClothesIntention.Everyday, StylePreference.Neutral, ColorScheme.Pastel) {Icon = this.Icon});
|
Clothes.Register(new Clothes("ExampleMod.PastelPants", ClothesLayer.Pants, this.customBottoms, new Point(4, 0), 100, ClothesIntention.Everyday, ColorScheme.Pastel) {Icon = this.Icon});
|
||||||
Clothes.Register(new Clothes("ExampleMod.PastelShoes", ClothesLayer.Shoes, this.customBottoms, new Point(0, 0), 100, ClothesIntention.Everyday, StylePreference.Neutral, ColorScheme.Pastel) {Icon = this.Icon});
|
Clothes.Register(new Clothes("ExampleMod.PastelShoes", ClothesLayer.Shoes, this.customBottoms, new Point(0, 0), 100, ClothesIntention.Everyday, ColorScheme.Pastel) {Icon = this.Icon});
|
||||||
Clothes.Register(new Clothes("ExampleMod.WeirdHair", ClothesLayer.Hair, this.customHairs, new Point(0, 0), 0, ClothesIntention.None, StylePreference.Neutral, ColorScheme.Modern) {Icon = this.Icon});
|
Clothes.Register(new Clothes("ExampleMod.WeirdHair", ClothesLayer.Hair, this.customHairs, new Point(0, 0), 0, ClothesIntention.None, ColorScheme.Modern) {Icon = this.Icon});
|
||||||
|
|
||||||
// adding an event subscription to people
|
// adding an event subscription to people
|
||||||
MapObject.OnEventsAttachable += o => {
|
MapObject.OnEventsAttachable += o => {
|
||||||
|
@ -105,12 +71,12 @@ public class ExampleMod : Mod {
|
||||||
};
|
};
|
||||||
|
|
||||||
// adding a simple action: sitting down in the grass, which also gives us a nice emotion modifier
|
// 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(ExampleGrassSitAction)) {
|
ActionType.Register(new ActionType.TypeSettings("ExampleMod.SitOnGrass", ObjectCategory.Ground, typeof(ExampleModGrassSitAction)) {
|
||||||
// we set this action to be executable only on grass tiles, not on other ground
|
// we set this action to be executable only on grass tiles, not on other ground
|
||||||
CanExecute = (actionInfo, _) => {
|
CanExecute = (actionInfo, _) => {
|
||||||
if (!actionInfo.GoalMap.IsInBounds(actionInfo.ActionLocation.ToPoint()))
|
if (!actionInfo.Map.IsInBounds(actionInfo.ActionLocation.ToPoint()))
|
||||||
return CanExecuteResult.Hidden;
|
return CanExecuteResult.Hidden;
|
||||||
var tile = actionInfo.GoalMap.GetTile(actionInfo.ActionLocation.ToPoint(), (int) actionInfo.ActionFloor);
|
var tile = actionInfo.Map.GetTile(actionInfo.ActionLocation.ToPoint());
|
||||||
// hidden means the action won't be displayed in the ring menu, Valid means the player (or AI) is able to enqueue and execute it
|
// hidden means the action won't be displayed in the ring menu, Valid means the player (or AI) is able to enqueue and execute it
|
||||||
return tile.Name.StartsWith("Grass") ? CanExecuteResult.Valid : CanExecuteResult.Hidden;
|
return tile.Name.StartsWith("Grass") ? CanExecuteResult.Valid : CanExecuteResult.Hidden;
|
||||||
},
|
},
|
||||||
|
@ -118,7 +84,7 @@ public class ExampleMod : Mod {
|
||||||
// we allow the action to be done even if the solved needs aren't low enough on a person
|
// we allow the action to be done even if the solved needs aren't low enough on a person
|
||||||
CanDoRandomly = true,
|
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
|
// 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 = [NeedType.Energy],
|
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
|
PassivePriority = p => p.Emotion == EmotionType.Uncomfortable ? 150 : 25
|
||||||
},
|
},
|
||||||
|
@ -132,9 +98,20 @@ public class ExampleMod : Mod {
|
||||||
|
|
||||||
// adding a custom wallpaper (we're using the top left texture region, which is why we pass 0, 0 as the texture coordinate)
|
// adding a custom wallpaper (we're using the top left texture region, which is why we pass 0, 0 as the texture coordinate)
|
||||||
Wallpaper.Register("ExampleMod.CrossedWallpaper", 15, this.wallpaperTextures, new Point(0, 0), ColorScheme.Modern, this.Icon);
|
Wallpaper.Register("ExampleMod.CrossedWallpaper", 15, this.wallpaperTextures, new Point(0, 0), ColorScheme.Modern, this.Icon);
|
||||||
|
}
|
||||||
|
|
||||||
// adding a custom tile
|
public override void Initialize(Logger logger, RawContentManager content, RuntimeTexturePacker texturePacker, ModInfo info) {
|
||||||
Tile.Register("ExampleMod.CustomTile", 8, this.tileTextures, new Point(0, 0), ColorScheme.Bricks, icon: this.Icon);
|
ExampleMod.Logger = logger;
|
||||||
|
ExampleMod.Options = info.LoadOptions(() => new ExampleModOptions());
|
||||||
|
|
||||||
|
// 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(new UniformTextureAtlas(content.Load<Texture2D>("CustomTops"), 4, 8), r => this.customTops = r);
|
||||||
|
texturePacker.Add(new UniformTextureAtlas(content.Load<Texture2D>("CustomHairs"), 4, 6), r => this.customHairs = r);
|
||||||
|
texturePacker.Add(new UniformTextureAtlas(content.Load<Texture2D>("CustomBottomsShoes"), 8, 6), r => this.customBottoms = r);
|
||||||
|
texturePacker.Add(new UniformTextureAtlas(content.Load<Texture2D>("UiTextures"), 8, 8), r => this.uiTextures = r);
|
||||||
|
// wallpaper textures require special treatment to work with openings, the x and y values are passed to the UniformTextureAtlas constructor
|
||||||
|
WallMode.ApplyMasks(content.Load<Texture2D>("Wallpapers"), 4, 5, texturePacker, r => this.wallpaperTextures = r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<string> GetCustomFurnitureTextures(ModInfo info) {
|
public override IEnumerable<string> GetCustomFurnitureTextures(ModInfo info) {
|
||||||
|
@ -152,68 +129,11 @@ public class ExampleMod : Mod {
|
||||||
group.AddChild(new Paragraph(Anchor.AutoLeft, 1, _ => $"{Localization.Get(LnCategory.Ui, "ExampleMod.DarkShirtSpeedOption")}: {ExampleMod.Options.DarkShirtSpeedIncrease}"));
|
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, 10), 5, 5) {
|
group.AddChild(new Slider(Anchor.AutoLeft, new Vector2(1, 10), 5, 5) {
|
||||||
CurrentValue = ExampleMod.Options.DarkShirtSpeedIncrease,
|
CurrentValue = ExampleMod.Options.DarkShirtSpeedIncrease,
|
||||||
OnValueChanged = (_, v) => ExampleMod.Options.DarkShirtSpeedIncrease = v
|
OnValueChanged = (_, v) => {
|
||||||
|
ExampleMod.Options.DarkShirtSpeedIncrease = v;
|
||||||
|
info.SaveOptions(ExampleMod.Options);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
group.OnRemovedFromUi += _ => info.SaveOptions(ExampleMod.Options);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// these options are saved and loaded in ExampleMod
|
|
||||||
public class ExampleOptions {
|
|
||||||
|
|
||||||
public float DarkShirtSpeedIncrease = 2;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// we use a multi action because we want to walk to the location, and then execute the main sitting part
|
|
||||||
// see ExampleTable for information on how to store custom action-specific information to disk as well
|
|
||||||
public class ExampleGrassSitAction : MultiAction {
|
|
||||||
|
|
||||||
public ExampleGrassSitAction(ActionType type, ActionInfo info) : base(type, info) {}
|
|
||||||
|
|
||||||
protected override IEnumerable<Action> CreateFirstActions() {
|
|
||||||
// we want to walk to the location clicked, so we use the current action info
|
|
||||||
yield return ActionType.GoHere.Construct<Action>(this.Info);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void AndThenUpdate(GameTime time, TimeSpan passedInGame, float speedMultiplier) {
|
|
||||||
base.AndThenUpdate(time, passedInGame, speedMultiplier);
|
|
||||||
// set our person to look like they're sitting on the ground
|
|
||||||
this.Person.CurrentPose = Pose.SittingGround;
|
|
||||||
|
|
||||||
// restore need and lower emotions
|
|
||||||
this.Person.RestoreNeed(NeedType.Energy, 0.5F, this.Info, speedMultiplier);
|
|
||||||
this.Person.LowerEmotion(EmotionType.Uncomfortable, 0.0001F, speedMultiplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override CompletionType AndThenIsCompleted() {
|
|
||||||
// we want to complete our action once 10 minutes of sitting time have passed
|
|
||||||
return this.CompleteIfTimeUp(TimeSpan.FromMinutes(10));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void AndThenOnCompleted(CompletionType type) {
|
|
||||||
base.AndThenOnCompleted(type);
|
|
||||||
// this method is called when the action completes in any way, even if it fails
|
|
||||||
if (type == CompletionType.Completed) {
|
|
||||||
// once we're finished sitting, we want to get a nice emotion modifier for it
|
|
||||||
this.Person.AddEmotion(ExampleMod.GrassSittingModifier, 2, TimeSpan.FromHours(1), this.Type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// note that having a custom class for a furniture item like this is entirely optional
|
|
||||||
// but it allows for additional functionalities as displayed in this example
|
|
||||||
public class ExampleTable : Furniture {
|
|
||||||
|
|
||||||
// anything whose base classes have the DataContract attribute automatically gets saved and loaded to and from disk
|
|
||||||
// this means that you can add custom DataMember members to have them saved and loaded
|
|
||||||
[DataMember]
|
|
||||||
public float TestValue;
|
|
||||||
|
|
||||||
public ExampleTable(Guid id, FurnitureType type, int[] colors, Map map, Vector2 pos, float floor) : base(id, type, colors, map, pos, floor) {
|
|
||||||
this.TestValue = Furniture.Random.NextSingle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,24 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="TinyLife.ApiReference" Version="0.44.1" />
|
<PackageReference Include="TinyLifeApi" Version="0.31.1" />
|
||||||
|
|
||||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.2.1105" />
|
<PackageReference Include="ExtremelySimpleLogger" Version="1.2.5" />
|
||||||
<PackageReference Include="Lib.Harmony" Version="2.3.3" />
|
<PackageReference Include="Lib.Harmony" Version="2.2.1" />
|
||||||
<PackageReference Include="ExtremelySimpleLogger" Version="1.4.1" />
|
<PackageReference Include="MLEM.Data" Version="6.1.0" />
|
||||||
<PackageReference Include="MLEM.Data" Version="7.1.1" />
|
<PackageReference Include="MLEM.Extended" Version="6.1.0" />
|
||||||
<PackageReference Include="MLEM.Extended" Version="7.1.1" />
|
<PackageReference Include="MLEM.Startup" Version="6.1.0" />
|
||||||
<PackageReference Include="MLEM.Startup" Version="7.1.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.263" />
|
||||||
<PackageReference Include="DynamicEnums" Version="2.0.0" />
|
|
||||||
<PackageReference Include="Coroutine" Version="2.1.5" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="./Content/**">
|
<Content Include="./Content/**">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="SteamThumbnail.png">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
55
ExampleModGrassSitAction.cs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TinyLife;
|
||||||
|
using TinyLife.Actions;
|
||||||
|
using TinyLife.Emotions;
|
||||||
|
using TinyLife.Objects;
|
||||||
|
using Action = TinyLife.Actions.Action;
|
||||||
|
|
||||||
|
namespace ExampleMod;
|
||||||
|
|
||||||
|
// we use a multi action because we want to walk to the location, and then execute the main sitting part
|
||||||
|
// see CustomTable for information on how to store custom action-specific information to disk as well
|
||||||
|
public class ExampleModGrassSitAction : MultiAction {
|
||||||
|
|
||||||
|
public ExampleModGrassSitAction(ActionType type, ActionInfo info) : base(type, info) {}
|
||||||
|
|
||||||
|
protected override IEnumerable<Action> CreateFirstActions() {
|
||||||
|
// we want to walk to the location clicked, so we use the current action info
|
||||||
|
yield return ActionType.GoHere.Construct<Action>(this.Info);
|
||||||
|
|
||||||
|
// if multiple things should be done before starting this action, they can all be returned here
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void AndThenInitialize() {
|
||||||
|
// this is called when the main action starts (after going to the location, in our case)
|
||||||
|
// but we don't need to do anything here for our action
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void AndThenUpdate(GameTime time, TimeSpan passedInGame, float speedMultiplier) {
|
||||||
|
base.AndThenUpdate(time, passedInGame, speedMultiplier);
|
||||||
|
// this method gets called every update frame while the action is active
|
||||||
|
|
||||||
|
// set our person to look like they're sitting on the ground
|
||||||
|
this.Person.CurrentPose = Pose.SittingGround;
|
||||||
|
|
||||||
|
// restore need and lower emotions
|
||||||
|
this.Person.RestoreNeed(NeedType.Energy, 0.5F, this.Info, speedMultiplier);
|
||||||
|
this.Person.LowerEmotion(EmotionType.Uncomfortable, 0.0001F, speedMultiplier);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override CompletionType AndThenIsCompleted() {
|
||||||
|
// we want to complete our action once 10 minutes of sitting time have passed
|
||||||
|
return this.CompleteIfTimeUp(TimeSpan.FromMinutes(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void AndThenOnCompleted(CompletionType type) {
|
||||||
|
base.AndThenOnCompleted(type);
|
||||||
|
// this method is called when the action completes in any way, even if it fails
|
||||||
|
if (type == CompletionType.Completed) {
|
||||||
|
// once we're finished sitting, we want to get a nice emotion modifier for it
|
||||||
|
this.Person.AddEmotion(ExampleMod.GrassSittingModifier, 2, TimeSpan.FromHours(1), this.Type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
8
ExampleModOptions.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
namespace ExampleMod;
|
||||||
|
|
||||||
|
// these options are saved and loaded in ExampleMod
|
||||||
|
public class ExampleModOptions {
|
||||||
|
|
||||||
|
public float DarkShirtSpeedIncrease = 2;
|
||||||
|
|
||||||
|
}
|
37
ExampleModTable.cs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
using System;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using TinyLife.Objects;
|
||||||
|
using TinyLife.World;
|
||||||
|
|
||||||
|
namespace ExampleMod;
|
||||||
|
|
||||||
|
// note that having a custom class for a furniture item like this is entirely optional
|
||||||
|
// but it allows for additional functionalities as displayed in this example
|
||||||
|
public class ExampleModTable : Furniture {
|
||||||
|
|
||||||
|
// anything whose base classes have the DataContract attribute automatically gets saved and loaded to and from disk
|
||||||
|
// this means that you can add custom DataMember members to have them saved and loaded
|
||||||
|
[DataMember]
|
||||||
|
public float TestValue;
|
||||||
|
|
||||||
|
public ExampleModTable(Guid id, FurnitureType type, int[] colors, Map map, Vector2 pos) : base(id, type, colors, map, pos) {
|
||||||
|
this.TestValue = Furniture.Random.NextSingle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnAdded() {
|
||||||
|
base.OnAdded();
|
||||||
|
ExampleMod.Logger.Info("The custom table was added at " + this.Position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnRemoved() {
|
||||||
|
base.OnRemoved();
|
||||||
|
ExampleMod.Logger.Info("The custom table was removed from " + this.Position);
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate is called when this object is loaded from disk
|
||||||
|
// returning false causes the object to be marked as invalid and removed
|
||||||
|
public override bool Validate() {
|
||||||
|
return base.Validate() && this.TestValue <= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Before Width: | Height: | Size: 279 B |
23
build.cake
|
@ -4,7 +4,6 @@ using System.Threading;
|
||||||
|
|
||||||
var target = Argument("target", "Run");
|
var target = Argument("target", "Run");
|
||||||
var config = Argument("configuration", "Release");
|
var config = Argument("configuration", "Release");
|
||||||
var args = Argument("args", "");
|
|
||||||
|
|
||||||
var tinyLifeDir = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/Tiny Life";
|
var tinyLifeDir = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/Tiny Life";
|
||||||
|
|
||||||
|
@ -30,16 +29,12 @@ Task("Run").IsDependentOn("CopyToMods").Does(() => {
|
||||||
// start the tiny life process
|
// start the tiny life process
|
||||||
var exeDir = System.IO.File.ReadAllText($"{tinyLifeDir}/GameDir");
|
var exeDir = System.IO.File.ReadAllText($"{tinyLifeDir}/GameDir");
|
||||||
var process = Process.Start(new ProcessStartInfo($"{exeDir}/Tiny Life") {
|
var process = Process.Start(new ProcessStartInfo($"{exeDir}/Tiny Life") {
|
||||||
Arguments = $"-v --skip-splash --skip-preloads --debug-saves --ansi {args}",
|
Arguments = "-v --skip-splash --skip-preloads --debug-saves",
|
||||||
RedirectStandardOutput = true,
|
CreateNoWindow = true
|
||||||
RedirectStandardError = true
|
|
||||||
});
|
});
|
||||||
// make sure the output buffers (which we ignore) don't fill up
|
|
||||||
process.BeginOutputReadLine();
|
|
||||||
process.BeginErrorReadLine();
|
|
||||||
|
|
||||||
// we wait a bit to make sure the process has generated a new log file
|
// we wait a bit to make sure the process has generated a new log file, bleh
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(3000);
|
||||||
|
|
||||||
// attach to the newest log file
|
// attach to the newest log file
|
||||||
var logsDir = $"{tinyLifeDir}/Logs";
|
var logsDir = $"{tinyLifeDir}/Logs";
|
||||||
|
@ -48,16 +43,16 @@ Task("Run").IsDependentOn("CopyToMods").Does(() => {
|
||||||
using (var stream = new FileStream(log, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
|
using (var stream = new FileStream(log, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
|
||||||
using (var reader = new StreamReader(stream)) {
|
using (var reader = new StreamReader(stream)) {
|
||||||
var lastPos = 0L;
|
var lastPos = 0L;
|
||||||
do {
|
while (!process.HasExited) {
|
||||||
if (stream.Length > lastPos) {
|
if (reader.BaseStream.Length > lastPos) {
|
||||||
stream.Seek(lastPos, SeekOrigin.Begin);
|
reader.BaseStream.Seek(lastPos, SeekOrigin.Begin);
|
||||||
string line;
|
string line;
|
||||||
while ((line = reader.ReadLine()) != null)
|
while ((line = reader.ReadLine()) != null)
|
||||||
Information(line);
|
Information(line);
|
||||||
lastPos = stream.Position;
|
lastPos = reader.BaseStream.Position;
|
||||||
}
|
}
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
} while (!process.HasExited);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|