added information on saving/loading data

This commit is contained in:
Ell 2021-06-26 15:49:37 +02:00
parent 45c21080c5
commit 461ab8a8db
2 changed files with 17 additions and 0 deletions

View file

@ -1,12 +1,22 @@
using System; using System;
using System.Runtime.Serialization;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MonoGame.Extended;
using TinyLife.Objects; using TinyLife.Objects;
using TinyLife.World; using TinyLife.World;
namespace ExampleMod { namespace ExampleMod {
public class CustomTable : Furniture { public class CustomTable : Furniture {
private static readonly Random Random = new();
// 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 CustomTable(Guid id, FurnitureType type, int[] colors, Map map, Vector2 pos) : base(id, type, colors, map, pos) { public CustomTable(Guid id, FurnitureType type, int[] colors, Map map, Vector2 pos) : base(id, type, colors, map, pos) {
this.TestValue = Random.NextSingle();
} }
public override void OnAdded() { public override void OnAdded() {
@ -19,5 +29,11 @@ namespace ExampleMod {
ExampleMod.Logger.Info("We were removed from " + this.Position); ExampleMod.Logger.Info("We were 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;
}
} }
} }

View file

@ -9,6 +9,7 @@ using Action = TinyLife.Actions.Action;
namespace ExampleMod { namespace ExampleMod {
// we use a multi action because we want to walk to the location, and then execute the main sitting part // 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 SitDownOnGrassAction : MultiAction { public class SitDownOnGrassAction : MultiAction {
public SitDownOnGrassAction(ActionType type, ActionInfo info) : base(type, info) { public SitDownOnGrassAction(ActionType type, ActionInfo info) : base(type, info) {