From b019dd4f69c9fefeba9f14c2049fb352127e448f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 7 Dec 2016 20:36:28 -0500 Subject: replace out_items, out_melee, and out_rings commands with a searchable list_items command --- src/TrainerMod/ItemData/ISearchItem.cs | 21 +++++++++++++ src/TrainerMod/ItemData/ItemType.cs | 15 +++++++++ src/TrainerMod/ItemData/SearchableObject.cs | 48 +++++++++++++++++++++++++++++ src/TrainerMod/ItemData/SearchableRing.cs | 48 +++++++++++++++++++++++++++++ src/TrainerMod/ItemData/SearchableWeapon.cs | 48 +++++++++++++++++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 src/TrainerMod/ItemData/ISearchItem.cs create mode 100644 src/TrainerMod/ItemData/ItemType.cs create mode 100644 src/TrainerMod/ItemData/SearchableObject.cs create mode 100644 src/TrainerMod/ItemData/SearchableRing.cs create mode 100644 src/TrainerMod/ItemData/SearchableWeapon.cs (limited to 'src/TrainerMod/ItemData') diff --git a/src/TrainerMod/ItemData/ISearchItem.cs b/src/TrainerMod/ItemData/ISearchItem.cs new file mode 100644 index 00000000..b2f7c2b8 --- /dev/null +++ b/src/TrainerMod/ItemData/ISearchItem.cs @@ -0,0 +1,21 @@ +namespace TrainerMod.ItemData +{ + /// An item that can be searched and added to the player's inventory through the console. + internal interface ISearchItem + { + /********* + ** Accessors + *********/ + /// Whether the item is valid. + bool IsValid { get; } + + /// The item ID. + int ID { get; } + + /// The item name. + string Name { get; } + + /// The item type. + ItemType Type { get; } + } +} \ No newline at end of file diff --git a/src/TrainerMod/ItemData/ItemType.cs b/src/TrainerMod/ItemData/ItemType.cs new file mode 100644 index 00000000..2e049aa1 --- /dev/null +++ b/src/TrainerMod/ItemData/ItemType.cs @@ -0,0 +1,15 @@ +namespace TrainerMod.ItemData +{ + /// An item type that can be searched and added to the player through the console. + internal enum ItemType + { + /// Any object in (except rings). + Object, + + /// A ring in . + Ring, + + /// A weapon from Data\weapons. + Weapon + } +} diff --git a/src/TrainerMod/ItemData/SearchableObject.cs b/src/TrainerMod/ItemData/SearchableObject.cs new file mode 100644 index 00000000..30362f54 --- /dev/null +++ b/src/TrainerMod/ItemData/SearchableObject.cs @@ -0,0 +1,48 @@ +using StardewValley; + +namespace TrainerMod.ItemData +{ + /// An object that can be searched and added to the player's inventory through the console. + internal class SearchableObject : ISearchItem + { + /********* + ** Properties + *********/ + /// The underlying item. + private readonly Item Item; + + + /********* + ** Accessors + *********/ + /// Whether the item is valid. + public bool IsValid => this.Item != null && this.Item.Name != "Broken Item"; + + /// The item ID. + public int ID => this.Item.parentSheetIndex; + + /// The item name. + public string Name => this.Item.Name; + + /// The item type. + public ItemType Type => ItemType.Object; + + + /********* + ** Accessors + *********/ + /// Construct an instance. + /// The item ID. + public SearchableObject(int id) + { + try + { + this.Item = new Object(id, 1); + } + catch + { + // invalid + } + } + } +} \ No newline at end of file diff --git a/src/TrainerMod/ItemData/SearchableRing.cs b/src/TrainerMod/ItemData/SearchableRing.cs new file mode 100644 index 00000000..7751e6aa --- /dev/null +++ b/src/TrainerMod/ItemData/SearchableRing.cs @@ -0,0 +1,48 @@ +using StardewValley.Objects; + +namespace TrainerMod.ItemData +{ + /// A ring that can be searched and added to the player's inventory through the console. + internal class SearchableRing : ISearchItem + { + /********* + ** Properties + *********/ + /// The underlying item. + private readonly Ring Ring; + + + /********* + ** Accessors + *********/ + /// Whether the item is valid. + public bool IsValid => this.Ring != null; + + /// The item ID. + public int ID => this.Ring.parentSheetIndex; + + /// The item name. + public string Name => this.Ring.Name; + + /// The item type. + public ItemType Type => ItemType.Ring; + + + /********* + ** Accessors + *********/ + /// Construct an instance. + /// The ring ID. + public SearchableRing(int id) + { + try + { + this.Ring = new Ring(id); + } + catch + { + // invalid + } + } + } +} \ No newline at end of file diff --git a/src/TrainerMod/ItemData/SearchableWeapon.cs b/src/TrainerMod/ItemData/SearchableWeapon.cs new file mode 100644 index 00000000..cc9ef459 --- /dev/null +++ b/src/TrainerMod/ItemData/SearchableWeapon.cs @@ -0,0 +1,48 @@ +using StardewValley.Tools; + +namespace TrainerMod.ItemData +{ + /// A weapon that can be searched and added to the player's inventory through the console. + internal class SearchableWeapon : ISearchItem + { + /********* + ** Properties + *********/ + /// The underlying item. + private readonly MeleeWeapon Weapon; + + + /********* + ** Accessors + *********/ + /// Whether the item is valid. + public bool IsValid => this.Weapon != null; + + /// The item ID. + public int ID => this.Weapon.initialParentTileIndex; + + /// The item name. + public string Name => this.Weapon.Name; + + /// The item type. + public ItemType Type => ItemType.Weapon; + + + /********* + ** Accessors + *********/ + /// Construct an instance. + /// The weapon ID. + public SearchableWeapon(int id) + { + try + { + this.Weapon = new MeleeWeapon(id); + } + catch + { + // invalid + } + } + } +} \ No newline at end of file -- cgit