diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-07-25 00:49:20 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-07-25 00:49:20 +1000 |
commit | ea084165bf2f414a49a559ddf5921b9073fc464c (patch) | |
tree | c8f1263d9e11600f3632df2d0202cb884673c97e /source/game/scripting | |
parent | 8547c56ba4607e1c4efac483f97f01b8ba8c3a01 (diff) |
Optimize entityPortrait: Drawable > LuaTable instead of Drawable > Json > LuaTable
Diffstat (limited to 'source/game/scripting')
-rw-r--r-- | source/game/scripting/StarWorldLuaBindings.cpp | 15 | ||||
-rw-r--r-- | source/game/scripting/StarWorldLuaBindings.hpp | 3 |
2 files changed, 7 insertions, 11 deletions
diff --git a/source/game/scripting/StarWorldLuaBindings.cpp b/source/game/scripting/StarWorldLuaBindings.cpp index 087f88c..4645eb7 100644 --- a/source/game/scripting/StarWorldLuaBindings.cpp +++ b/source/game/scripting/StarWorldLuaBindings.cpp @@ -491,10 +491,10 @@ namespace LuaBindings { callbacks.registerCallbackWithSignature<Maybe<String>, EntityId>("entityGender", bind(WorldEntityCallbacks::entityGender, world, _1)); callbacks.registerCallbackWithSignature<Maybe<String>, EntityId>("entityName", bind(WorldEntityCallbacks::entityName, world, _1)); callbacks.registerCallbackWithSignature<Maybe<String>, EntityId, Maybe<String>>("entityDescription", bind(WorldEntityCallbacks::entityDescription, world, _1, _2)); - callbacks.registerCallbackWithSignature<Maybe<JsonArray>, EntityId, String>("entityPortrait", bind(WorldEntityCallbacks::entityPortrait, world, _1, _2)); + callbacks.registerCallbackWithSignature<LuaNullTermWrapper<Maybe<List<Drawable>>>, EntityId, String>("entityPortrait", bind(WorldEntityCallbacks::entityPortrait, world, _1, _2)); callbacks.registerCallbackWithSignature<Maybe<String>, EntityId, String>("entityHandItem", bind(WorldEntityCallbacks::entityHandItem, world, _1, _2)); callbacks.registerCallbackWithSignature<Json, EntityId, String>("entityHandItemDescriptor", bind(WorldEntityCallbacks::entityHandItemDescriptor, world, _1, _2)); - callbacks.registerCallbackWithSignature<Maybe<String>, EntityId>("entityUniqueId", bind(WorldEntityCallbacks::entityUniqueId, world, _1)); + callbacks.registerCallbackWithSignature<LuaNullTermWrapper<Maybe<String>>, EntityId>("entityUniqueId", bind(WorldEntityCallbacks::entityUniqueId, world, _1)); callbacks.registerCallbackWithSignature<Json, EntityId, String, Maybe<Json>>("getObjectParameter", bind(WorldEntityCallbacks::getObjectParameter, world, _1, _2, _3)); callbacks.registerCallbackWithSignature<Json, EntityId, String, Maybe<Json>>("getNpcScriptParameter", bind(WorldEntityCallbacks::getNpcScriptParameter, world, _1, _2, _3)); callbacks.registerCallbackWithSignature<List<Vec2I>, EntityId>("objectSpaces", bind(WorldEntityCallbacks::objectSpaces, world, _1)); @@ -1421,14 +1421,9 @@ namespace LuaBindings { return {}; } - LuaNullTermWrapper<Maybe<JsonArray>> WorldEntityCallbacks::entityPortrait(World* world, EntityId entityId, String const& portraitMode) { - auto entity = world->entity(entityId); - - if (auto portraitEntity = as<PortraitEntity>(entity)) { - PortraitMode mode = PortraitModeNames.getLeft(portraitMode); - auto drawables = portraitEntity->portrait(mode); - return drawables.transformed(mem_fn(&Drawable::toJson)); - } + LuaNullTermWrapper<Maybe<List<Drawable>>> WorldEntityCallbacks::entityPortrait(World* world, EntityId entityId, String const& portraitMode) { + if (auto portraitEntity = as<PortraitEntity>(world->entity(entityId))) + return portraitEntity->portrait(PortraitModeNames.getLeft(portraitMode)); return {}; } diff --git a/source/game/scripting/StarWorldLuaBindings.hpp b/source/game/scripting/StarWorldLuaBindings.hpp index e2d082c..e308ded 100644 --- a/source/game/scripting/StarWorldLuaBindings.hpp +++ b/source/game/scripting/StarWorldLuaBindings.hpp @@ -5,6 +5,7 @@ #include "StarRect.hpp" #include "StarPoly.hpp" #include "StarColor.hpp" +#include "StarDrawable.hpp" #include "StarGameTypes.hpp" #include "StarCollisionBlock.hpp" #include "StarLua.hpp" @@ -122,7 +123,7 @@ namespace LuaBindings { Maybe<String> entityGender(World* world, EntityId entityId); Maybe<String> entityName(World* world, EntityId entityId); Maybe<String> entityDescription(World* world, EntityId entityId, Maybe<String> const& species); - LuaNullTermWrapper<Maybe<JsonArray>> entityPortrait(World* world, EntityId entityId, String const& portraitMode); + LuaNullTermWrapper<Maybe<List<Drawable>>> entityPortrait(World* world, EntityId entityId, String const& portraitMode); Maybe<String> entityHandItem(World* world, EntityId entityId, String const& handName); Json entityHandItemDescriptor(World* world, EntityId entityId, String const& handName); LuaNullTermWrapper<Maybe<String>> entityUniqueId(World* world, EntityId entityId); |