mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 09:39:44 +00:00
Merge branch 'lua_action_fixes' into 'master'
Lua Action fixes See merge request OpenMW/openmw!3717
This commit is contained in:
commit
b132fd4373
5 changed files with 24 additions and 18 deletions
|
@ -76,7 +76,7 @@ namespace MWLua
|
|||
inputActions[sol::meta_function::pairs] = pairs;
|
||||
}
|
||||
|
||||
auto actionInfo = context.mLua->sol().new_usertype<LuaUtil::InputAction::Info>("ActionInfo", "key",
|
||||
context.mLua->sol().new_usertype<LuaUtil::InputAction::Info>("ActionInfo", "key",
|
||||
sol::property([](const LuaUtil::InputAction::Info& info) { return info.mKey; }), "name",
|
||||
sol::property([](const LuaUtil::InputAction::Info& info) { return info.mName; }), "description",
|
||||
sol::property([](const LuaUtil::InputAction::Info& info) { return info.mDescription; }), "type",
|
||||
|
@ -102,7 +102,7 @@ namespace MWLua
|
|||
inputTriggers[sol::meta_function::pairs] = pairs;
|
||||
}
|
||||
|
||||
auto triggerInfo = context.mLua->sol().new_usertype<LuaUtil::InputTrigger::Info>("TriggerInfo", "key",
|
||||
context.mLua->sol().new_usertype<LuaUtil::InputTrigger::Info>("TriggerInfo", "key",
|
||||
sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mKey; }), "name",
|
||||
sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mName; }), "description",
|
||||
sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mDescription; }), "l10n",
|
||||
|
@ -127,7 +127,7 @@ namespace MWLua
|
|||
parsedOptions.mName = options["name"].get<std::string_view>();
|
||||
parsedOptions.mDescription = options["description"].get<std::string_view>();
|
||||
parsedOptions.mDefaultValue = options["defaultValue"].get<sol::main_object>();
|
||||
manager->inputActions().insert(parsedOptions);
|
||||
manager->inputActions().insert(std::move(parsedOptions));
|
||||
};
|
||||
api["bindAction"] = [manager = context.mLuaManager](
|
||||
std::string_view key, const sol::table& callback, sol::table dependencies) {
|
||||
|
@ -164,7 +164,7 @@ namespace MWLua
|
|||
parsedOptions.mL10n = options["l10n"].get<std::string_view>();
|
||||
parsedOptions.mName = options["name"].get<std::string_view>();
|
||||
parsedOptions.mDescription = options["description"].get<std::string_view>();
|
||||
manager->inputTriggers().insert(parsedOptions);
|
||||
manager->inputTriggers().insert(std::move(parsedOptions));
|
||||
};
|
||||
api["registerTriggerHandler"]
|
||||
= [manager = context.mLuaManager](std::string_view key, const sol::table& callback) {
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace LuaUtil
|
|||
}
|
||||
}
|
||||
|
||||
void Registry::insert(Info info)
|
||||
void Registry::insert(const Info& info)
|
||||
{
|
||||
if (mIds.find(info.mKey) != mIds.end())
|
||||
throw std::domain_error(Misc::StringUtils::format("Action key \"%s\" is already in use", info.mKey));
|
||||
|
@ -251,7 +251,7 @@ namespace LuaUtil
|
|||
return it->second;
|
||||
}
|
||||
|
||||
void Registry::insert(Info info)
|
||||
void Registry::insert(const Info& info)
|
||||
{
|
||||
if (mIds.find(info.mKey) != mIds.end())
|
||||
throw std::domain_error(Misc::StringUtils::format("Trigger key \"%s\" is already in use", info.mKey));
|
||||
|
@ -265,6 +265,14 @@ namespace LuaUtil
|
|||
mHandlers.push_back({});
|
||||
}
|
||||
|
||||
std::optional<Info> Registry::operator[](std::string_view key)
|
||||
{
|
||||
auto iter = mIds.find(key);
|
||||
if (iter == mIds.end())
|
||||
return std::nullopt;
|
||||
return mInfo[iter->second];
|
||||
}
|
||||
|
||||
void Registry::registerHandler(std::string_view key, const LuaUtil::Callback& callback)
|
||||
{
|
||||
Id id = safeIdByKey(key);
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace LuaUtil::InputAction
|
|||
{
|
||||
public:
|
||||
using ConstIterator = std::vector<Info>::const_iterator;
|
||||
void insert(Info info);
|
||||
void insert(const Info& info);
|
||||
size_t size() const { return mKeys.size(); }
|
||||
std::optional<std::string> firstKey() const { return mKeys.empty() ? std::nullopt : std::optional(mKeys[0]); }
|
||||
std::optional<std::string> nextKey(std::string_view key) const;
|
||||
|
@ -126,12 +126,8 @@ namespace LuaUtil::InputTrigger
|
|||
return std::nullopt;
|
||||
return it->first;
|
||||
}
|
||||
std::optional<Info> operator[](std::string_view key)
|
||||
{
|
||||
Id id = safeIdByKey(key);
|
||||
return mInfo[id];
|
||||
}
|
||||
void insert(Info info);
|
||||
std::optional<Info> operator[](std::string_view key);
|
||||
void insert(const Info& info);
|
||||
void registerHandler(std::string_view key, const LuaUtil::Callback& callback);
|
||||
void activate(std::string_view key);
|
||||
void clear()
|
||||
|
|
|
@ -195,9 +195,11 @@ end))
|
|||
|
||||
local startUse = false
|
||||
input.registerActionHandler('Use', async:callback(function(value)
|
||||
if value then startUse = true end
|
||||
if value and combatAllowed() then startUse = true end
|
||||
end))
|
||||
local function processAttacking()
|
||||
-- for spell-casting, set controls.use to true for exactly one frame
|
||||
-- otherwise spell casting is attempted every frame while Use is true
|
||||
if Actor.stance(self) == Actor.STANCE.Spell then
|
||||
self.controls.use = startUse and 1 or 0
|
||||
else
|
||||
|
|
|
@ -402,10 +402,10 @@
|
|||
|
||||
---
|
||||
-- @type TriggerInfo
|
||||
-- @field [parent=#Actioninfo] #string key
|
||||
-- @field [parent=#Actioninfo] #string l10n Localization context containing the name and description keys
|
||||
-- @field [parent=#Actioninfo] #string name Localization key of the trigger's name
|
||||
-- @field [parent=#Actioninfo] #string description Localization key of the trigger's description
|
||||
-- @field [parent=#TriggerInfo] #string key
|
||||
-- @field [parent=#TriggerInfo] #string l10n Localization context containing the name and description keys
|
||||
-- @field [parent=#TriggerInfo] #string name Localization key of the trigger's name
|
||||
-- @field [parent=#TriggerInfo] #string description Localization key of the trigger's description
|
||||
|
||||
---
|
||||
-- Map of all currently registered triggers
|
||||
|
|
Loading…
Reference in a new issue