From 6352e8e3196f78388b6c771073f9e03eaa612673 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 20 Jun 2023 14:33:09 +1000 Subject: everything everywhere all at once --- source/game/scripting/StarItemLuaBindings.cpp | 246 ++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 source/game/scripting/StarItemLuaBindings.cpp (limited to 'source/game/scripting/StarItemLuaBindings.cpp') diff --git a/source/game/scripting/StarItemLuaBindings.cpp b/source/game/scripting/StarItemLuaBindings.cpp new file mode 100644 index 0000000..2875f86 --- /dev/null +++ b/source/game/scripting/StarItemLuaBindings.cpp @@ -0,0 +1,246 @@ +#include "StarItemLuaBindings.hpp" +#include "StarJsonExtra.hpp" +#include "StarLuaGameConverters.hpp" +#include "StarCasting.hpp" +#include "StarItem.hpp" +#include "StarToolUserItem.hpp" + +namespace Star { + +LuaCallbacks LuaBindings::makeItemCallbacks(Item* item) { + LuaCallbacks callbacks; + + callbacks.registerCallbackWithSignature("name", bind(ItemCallbacks::name, item)); + callbacks.registerCallbackWithSignature("count", bind(ItemCallbacks::count, item)); + callbacks.registerCallbackWithSignature("setCount", bind(ItemCallbacks::setCount, item, _1)); + callbacks.registerCallbackWithSignature("maxStack", bind(ItemCallbacks::maxStack, item)); + callbacks.registerCallbackWithSignature>("matches", bind(ItemCallbacks::matches, item, _1, _2)); + callbacks.registerCallbackWithSignature("consume", bind(ItemCallbacks::consume, item, _1)); + callbacks.registerCallbackWithSignature("empty", bind(ItemCallbacks::empty, item)); + callbacks.registerCallbackWithSignature("descriptor", bind(ItemCallbacks::descriptor, item)); + callbacks.registerCallbackWithSignature("description", bind(ItemCallbacks::description, item)); + callbacks.registerCallbackWithSignature("friendlyName", bind(ItemCallbacks::friendlyName, item)); + callbacks.registerCallbackWithSignature("rarity", bind(ItemCallbacks::rarity, item)); + callbacks.registerCallbackWithSignature("rarityString", bind(ItemCallbacks::rarityString, item)); + callbacks.registerCallbackWithSignature("price", bind(ItemCallbacks::price, item)); + callbacks.registerCallbackWithSignature("fuelAmount", bind(ItemCallbacks::fuelAmount, item)); + callbacks.registerCallbackWithSignature("iconDrawables", bind(ItemCallbacks::iconDrawables, item)); + callbacks.registerCallbackWithSignature("dropDrawables", bind(ItemCallbacks::dropDrawables, item)); + callbacks.registerCallbackWithSignature("largeImage", bind(ItemCallbacks::largeImage, item)); + callbacks.registerCallbackWithSignature("tooltipKind", bind(ItemCallbacks::tooltipKind, item)); + callbacks.registerCallbackWithSignature("category", bind(ItemCallbacks::category, item)); + callbacks.registerCallbackWithSignature("pickupSound", bind(ItemCallbacks::pickupSound, item)); + callbacks.registerCallbackWithSignature("twoHanded", bind(ItemCallbacks::twoHanded, item)); + callbacks.registerCallbackWithSignature("timeToLive", bind(ItemCallbacks::timeToLive, item)); + callbacks.registerCallbackWithSignature("learnBlueprintsOnPickup", bind(ItemCallbacks::learnBlueprintsOnPickup, item)); + callbacks.registerCallbackWithSignature("hasItemTag", bind(ItemCallbacks::hasItemTag, item, _1)); + callbacks.registerCallbackWithSignature("pickupQuestTemplates", bind(ItemCallbacks::pickupQuestTemplates, item)); + + return callbacks; +} + +// Returns the name of the item. (Unique identifier) +// +// @return A string containing the name of the item as specified in its +// configuration +String LuaBindings::ItemCallbacks::name(Item* item) { + return item->name(); +} + +// Returns the number of items in this stack +// +// @return An integer containing the number of items in this stack +size_t LuaBindings::ItemCallbacks::count(Item* item) { + return item->count(); +} + +// Sets the number of items in the stack (up to maxStack) +// +// @param count The desired amount +// @return An integer containing the number of items that overflowed +size_t LuaBindings::ItemCallbacks::setCount(Item* item, size_t count) { + return item->setCount(count); +} + +// Returns the maximum number of items in this item's stack +// +// @return An integer containing the number of items in this item's maximum +// stack +size_t LuaBindings::ItemCallbacks::maxStack(Item* item) { + return item->maxStack(); +} + +// Returns whether or not the serialized item descriptor passed logically +// matches this item +// Checks both name and parameters and uses the item's internal list of matching +// descriptors +// +// @see is +// @param descriptor A properly serialized item descriptor +// @return A bool true if matches, false if not. +// +bool LuaBindings::ItemCallbacks::matches(Item* item, Json const& desc, Maybe exactMatch) { + ItemDescriptor itemDesc = ItemDescriptor(desc); + return item->matches(itemDesc, exactMatch.value(false)); +} + +// If the given number of this item is available, consumes that number and +// returns true, otherwise +// returns false. +// +// @param toConsume The number of items you'd like to consume from this stack +// @return true if items were successfully consumed, false otherwise +bool LuaBindings::ItemCallbacks::consume(Item* item, size_t count) { + return item->consume(count); +} + +// Returns the number of items in the stack is equal to 0 +// +// @return true if stack is empty, false otherwise +bool LuaBindings::ItemCallbacks::empty(Item* item) { + return item->empty(); +} + +// Returns the descriptor of this item +// +// @return a table containing a serialized item descriptor +Json LuaBindings::ItemCallbacks::descriptor(Item* item) { + return item->descriptor().toJson(); +} + +// Returns the item description +// +// @return a string containing the item's description +String LuaBindings::ItemCallbacks::description(Item* item) { + return item->description(); +} + +// Returns the friendly name of the item +// +// @return a string containing the friendly name of the item +String LuaBindings::ItemCallbacks::friendlyName(Item* item) { + return item->friendlyName(); +} + +// Returns the rarity of the item as an integer +// Common = 0, +// Uncommon = 1, +// Rare = 2, +// Legendary = 3 +// Essential = 4 +// +// @return an integer representing the rarity of the item +int LuaBindings::ItemCallbacks::rarity(Item* item) { + return (int)item->rarity(); +} + +// Returns the rarity of the item as a string +// +// @return a string representing the rarity of the item +String LuaBindings::ItemCallbacks::rarityString(Item* item) { + return RarityNames.getRight(item->rarity()); +} + +// Returns the shop price of the item +// +// @return an integer representing the shop price of the item in pixels (before +// modifiers) +size_t LuaBindings::ItemCallbacks::price(Item* item) { + return item->price(); +} + +// Returns the amount of fuel given for buring this item stack in an engine +// +// @return an integer representing the amount of fuel in the entire stack +unsigned LuaBindings::ItemCallbacks::fuelAmount(Item* item) { + return item->instanceValue("fuelAmount", 0).toUInt(); +} + +// Returns the iconDrawables for this item serialized into json +// +// @return List of tables containing the serialized icon drawables for this +// item. +Json LuaBindings::ItemCallbacks::iconDrawables(Item* item) { + return jsonFromList(item->iconDrawables(), [](Drawable const& drawable) { return drawable.toJson(); }); +} + +// Returns the dropDrawables for this item serialized into json +// +// @return List of tables containing the serialized drop drawables for this +// item. +Json LuaBindings::ItemCallbacks::dropDrawables(Item* item) { + return jsonFromList(item->dropDrawables(), [](Drawable const& drawable) { return drawable.toJson(); }); +} + +// Returns the large image for this item as displayed on mouseover in the +// tooltip +// +// @return String containing a path to the largeImage for this item +String LuaBindings::ItemCallbacks::largeImage(Item* item) { + return item->largeImage(); +} + +// Returns the inspection kind of this item (as defined in item config, defaults +// to empty string) +// +// @return String containing the inspection kind +String LuaBindings::ItemCallbacks::tooltipKind(Item* item) { + return item->tooltipKind(); +} + +// Returns the category of this item (as defined in item config) +// +// @return String containing the category +String LuaBindings::ItemCallbacks::category(Item* item) { + return item->category(); +} + +// Returns the pickup sound for the item +// +// @return string containing the path to the pickup sound for this item +String LuaBindings::ItemCallbacks::pickupSound(Item* item) { + return item->pickupSound(); +} + +// Returns whether or not the item is two handed +// +// @return bool containing true if the item is twoHanded, false otherwise +bool LuaBindings::ItemCallbacks::twoHanded(Item* item) { + return item->twoHanded(); +} + +// Returns the time to live for this item as an item drop +// +// @return float containing the time to live for this item +float LuaBindings::ItemCallbacks::timeToLive(Item* item) { + return item->timeToLive(); +} + +// Returns a list of item descriptors representing recipes whose blueprints you +// learn when you pick +// this item up +// +// @return a list of tables containing serialize item descriptors +Json LuaBindings::ItemCallbacks::learnBlueprintsOnPickup(Item* item) { + return jsonFromList( + item->learnBlueprintsOnPickup(), [](ItemDescriptor const& descriptor) { return descriptor.toJson(); }); +} + +// Returns whether or not this items has a specific item tag +// +// @param itemTag a string containing the tag value +// @return a bool representing whether or not this item contains that tag +bool LuaBindings::ItemCallbacks::hasItemTag(Item* item, String const& itemTag) { + return item->hasItemTag(itemTag); +} + +// Returns the pickup Quest Templates for this item +// +// @return a list of string containing the different quest templates triggered +// by this item on +// pickup +Json LuaBindings::ItemCallbacks::pickupQuestTemplates(Item* item) { + return item->pickupQuestTemplates().transformed(mem_fn(&QuestArcDescriptor::toJson)); +} + +} -- cgit v1.2.3