2020-11-25 00:33:47 +01:00
|
|
|
using System;
|
2021-06-26 15:49:37 +02:00
|
|
|
using System.Runtime.Serialization;
|
2020-11-25 00:33:47 +01:00
|
|
|
using Microsoft.Xna.Framework;
|
2021-06-26 15:49:37 +02:00
|
|
|
using MonoGame.Extended;
|
2020-11-25 00:33:47 +01:00
|
|
|
using TinyLife.Objects;
|
|
|
|
using TinyLife.World;
|
|
|
|
|
|
|
|
namespace ExampleMod {
|
2021-08-02 03:11:08 +02:00
|
|
|
// 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
|
2020-11-25 00:33:47 +01:00
|
|
|
public class CustomTable : Furniture {
|
|
|
|
|
2021-06-26 15:49:37 +02:00
|
|
|
// 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;
|
|
|
|
|
2020-11-25 00:33:47 +01:00
|
|
|
public CustomTable(Guid id, FurnitureType type, int[] colors, Map map, Vector2 pos) : base(id, type, colors, map, pos) {
|
2021-06-26 15:49:37 +02:00
|
|
|
this.TestValue = Random.NextSingle();
|
2020-11-25 00:33:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnAdded() {
|
|
|
|
base.OnAdded();
|
|
|
|
ExampleMod.Logger.Info("We were added at " + this.Position);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnRemoved() {
|
|
|
|
base.OnRemoved();
|
|
|
|
ExampleMod.Logger.Info("We were removed from " + this.Position);
|
|
|
|
}
|
|
|
|
|
2021-06-26 15:49:37 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2020-11-25 00:33:47 +01:00
|
|
|
}
|
|
|
|
}
|