mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Merge branch 'topic/list-potions' into 'master'
Implement API method `records` for all record types See merge request OpenMW/openmw!2880
This commit is contained in:
commit
cf9d2e0d89
@ -23,7 +23,7 @@ namespace MWLua
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Activator>(activator);
|
||||
addRecordFunctionBinding<ESM::Activator>(activator, context);
|
||||
|
||||
sol::usertype<ESM::Activator> record = context.mLua->sol().new_usertype<ESM::Activator>("ESM3_Activator");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -30,7 +30,7 @@ namespace MWLua
|
||||
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Apparatus>(apparatus);
|
||||
addRecordFunctionBinding<ESM::Apparatus>(apparatus, context);
|
||||
|
||||
sol::usertype<ESM::Apparatus> record = context.mLua->sol().new_usertype<ESM::Apparatus>("ESM3_Apparatus");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -37,7 +37,7 @@ namespace MWLua
|
||||
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Armor>(armor);
|
||||
addRecordFunctionBinding<ESM::Armor>(armor, context);
|
||||
|
||||
sol::usertype<ESM::Armor> record = context.mLua->sol().new_usertype<ESM::Armor>("ESM3_Armor");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -32,7 +32,7 @@ namespace MWLua
|
||||
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Book>(book);
|
||||
addRecordFunctionBinding<ESM::Book>(book, context);
|
||||
|
||||
sol::usertype<ESM::Book> record = context.mLua->sol().new_usertype<ESM::Book>("ESM3_Book");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -36,7 +36,7 @@ namespace MWLua
|
||||
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Clothing>(clothing);
|
||||
addRecordFunctionBinding<ESM::Clothing>(clothing, context);
|
||||
|
||||
sol::usertype<ESM::Clothing> record = context.mLua->sol().new_usertype<ESM::Clothing>("ESM3_Clothing");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -48,7 +48,7 @@ namespace MWLua
|
||||
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Container>(container);
|
||||
addRecordFunctionBinding<ESM::Container>(container, context);
|
||||
|
||||
sol::usertype<ESM::Container> record = context.mLua->sol().new_usertype<ESM::Container>("ESM3_Container");
|
||||
record[sol::meta_function::to_string] = [](const ESM::Container& rec) -> std::string {
|
||||
|
@ -23,7 +23,7 @@ namespace MWLua
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Creature>(creature);
|
||||
addRecordFunctionBinding<ESM::Creature>(creature, context);
|
||||
|
||||
sol::usertype<ESM::Creature> record = context.mLua->sol().new_usertype<ESM::Creature>("ESM3_Creature");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -43,7 +43,7 @@ namespace MWLua
|
||||
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Door>(door);
|
||||
addRecordFunctionBinding<ESM::Door>(door, context);
|
||||
|
||||
sol::usertype<ESM::Door> record = context.mLua->sol().new_usertype<ESM::Door>("ESM3_Door");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -24,7 +24,7 @@ namespace MWLua
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Ingredient>(ingredient);
|
||||
addRecordFunctionBinding<ESM::Ingredient>(ingredient, context);
|
||||
|
||||
sol::usertype<ESM::Ingredient> record = context.mLua->sol().new_usertype<ESM::Ingredient>(("ESM3_Ingredient"));
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -23,7 +23,7 @@ namespace MWLua
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Light>(light);
|
||||
addRecordFunctionBinding<ESM::Light>(light, context);
|
||||
|
||||
sol::usertype<ESM::Light> record = context.mLua->sol().new_usertype<ESM::Light>("ESM3_Light");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -23,7 +23,7 @@ namespace MWLua
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Lockpick>(lockpick);
|
||||
addRecordFunctionBinding<ESM::Lockpick>(lockpick, context);
|
||||
|
||||
sol::usertype<ESM::Lockpick> record = context.mLua->sol().new_usertype<ESM::Lockpick>("ESM3_Lockpick");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -23,7 +23,7 @@ namespace MWLua
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Miscellaneous>(miscellaneous);
|
||||
addRecordFunctionBinding<ESM::Miscellaneous>(miscellaneous, context);
|
||||
|
||||
sol::usertype<ESM::Miscellaneous> record
|
||||
= context.mLua->sol().new_usertype<ESM::Miscellaneous>("ESM3_Miscellaneous");
|
||||
|
@ -25,7 +25,7 @@ namespace MWLua
|
||||
{
|
||||
addNpcStatsBindings(npc, context);
|
||||
|
||||
addRecordFunctionBinding<ESM::NPC>(npc);
|
||||
addRecordFunctionBinding<ESM::NPC>(npc, context);
|
||||
|
||||
sol::usertype<ESM::NPC> record = context.mLua->sol().new_usertype<ESM::NPC>("ESM3_NPC");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -41,7 +41,7 @@ namespace MWLua
|
||||
{
|
||||
void addPotionBindings(sol::table potion, const Context& context)
|
||||
{
|
||||
addRecordFunctionBinding<ESM::Potion>(potion);
|
||||
addRecordFunctionBinding<ESM::Potion>(potion, context);
|
||||
|
||||
// Creates a new potion struct but does not store it in MWWorld::ESMStore.
|
||||
// Global scripts can use world.createRecord to add the potion to the world.
|
||||
|
@ -23,7 +23,7 @@ namespace MWLua
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Probe>(probe);
|
||||
addRecordFunctionBinding<ESM::Probe>(probe, context);
|
||||
|
||||
sol::usertype<ESM::Probe> record = context.mLua->sol().new_usertype<ESM::Probe>("ESM3_Probe");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -23,7 +23,7 @@ namespace MWLua
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Repair>(repair);
|
||||
addRecordFunctionBinding<ESM::Repair>(repair, context);
|
||||
|
||||
sol::usertype<ESM::Repair> record = context.mLua->sol().new_usertype<ESM::Repair>("ESM3_Repair");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -23,7 +23,7 @@ namespace MWLua
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Static>(stat);
|
||||
addRecordFunctionBinding<ESM::Static>(stat, context);
|
||||
|
||||
sol::usertype<ESM::Static> record = context.mLua->sol().new_usertype<ESM::Static>("ESM3_Static");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
#include <components/esm/defs.hpp>
|
||||
#include <components/lua/luastate.hpp>
|
||||
|
||||
#include "apps/openmw/mwbase/environment.hpp"
|
||||
#include "apps/openmw/mwbase/world.hpp"
|
||||
@ -13,6 +14,16 @@
|
||||
#include "../context.hpp"
|
||||
#include "../object.hpp"
|
||||
|
||||
namespace sol
|
||||
{
|
||||
// Ensure sol does not try to create the automatic Container or usertype bindings for Store.
|
||||
// They include write operations and we want the store to be read-only.
|
||||
template <typename T>
|
||||
struct is_automagical<typename MWWorld::Store<T>> : std::false_type
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
// `getLiveCellRefType()` is not exactly what we usually mean by "type" because some refids have special meaning.
|
||||
@ -53,12 +64,33 @@ namespace MWLua
|
||||
void addLightBindings(sol::table light, const Context& context);
|
||||
|
||||
template <class T>
|
||||
void addRecordFunctionBinding(sol::table table)
|
||||
void addRecordFunctionBinding(sol::table table, const Context& context)
|
||||
{
|
||||
const MWWorld::Store<T>& store = MWBase::Environment::get().getWorld()->getStore().get<T>();
|
||||
|
||||
table["record"] = sol::overload([](const Object& obj) -> const T* { return obj.ptr().get<T>()->mBase; },
|
||||
[&store](std::string_view id) -> const T* { return store.find(ESM::RefId::deserializeText(id)); });
|
||||
|
||||
// Define a custom user type for the store.
|
||||
// Provide the interface of a read-only array.
|
||||
using StoreT = MWWorld::Store<T>;
|
||||
sol::state_view& lua = context.mLua->sol();
|
||||
sol::usertype<StoreT> storeT = lua.new_usertype<StoreT>(std::string(T::getRecordType()) + "WorldStore");
|
||||
storeT[sol::meta_function::to_string] = [](const StoreT& store) {
|
||||
return "{" + std::to_string(store.getSize()) + " " + std::string(T::getRecordType()) + " records}";
|
||||
};
|
||||
storeT[sol::meta_function::length] = [](const StoreT& store) { return store.getSize(); };
|
||||
storeT[sol::meta_function::index] = [](const StoreT& store, size_t index) -> const T& {
|
||||
if (index > 0 && index <= store.getSize())
|
||||
return store.at(index - 1); // Translate from Lua's 1-based indexing.
|
||||
else
|
||||
throw std::runtime_error("Index out of range");
|
||||
};
|
||||
storeT[sol::meta_function::pairs] = lua["ipairsForArray"].template get<sol::function>();
|
||||
storeT[sol::meta_function::ipairs] = lua["ipairsForArray"].template get<sol::function>();
|
||||
|
||||
// Provide access to the store.
|
||||
table["records"] = [&store]() { return &store; };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace MWLua
|
||||
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
addRecordFunctionBinding<ESM::Weapon>(weapon);
|
||||
addRecordFunctionBinding<ESM::Weapon>(weapon, context);
|
||||
|
||||
sol::usertype<ESM::Weapon> record = context.mLua->sol().new_usertype<ESM::Weapon>("ESM3_Weapon");
|
||||
record[sol::meta_function::to_string]
|
||||
|
@ -205,6 +205,11 @@ namespace MWWorld
|
||||
{
|
||||
return mShared.end();
|
||||
}
|
||||
template <typename T>
|
||||
const T& TypedDynamicStore<T>::at(size_t index) const
|
||||
{
|
||||
return *mShared.at(index);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t TypedDynamicStore<T>::getSize() const
|
||||
|
@ -209,6 +209,7 @@ namespace MWWorld
|
||||
|
||||
iterator begin() const;
|
||||
iterator end() const;
|
||||
const T& at(size_t index) const;
|
||||
|
||||
size_t getSize() const override;
|
||||
int getDynamicSize() const override;
|
||||
|
@ -466,6 +466,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #CreatureRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#CreatureRecord}s in the world database.
|
||||
-- @function [parent=#Creature] records
|
||||
-- @return #list<#CreatureRecord>
|
||||
|
||||
---
|
||||
-- @type CreatureRecord
|
||||
-- @field #string name
|
||||
@ -502,6 +507,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #NpcRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#NpcRecord}s in the world database.
|
||||
-- @function [parent=#Npc] records
|
||||
-- @return #list<#NpcRecord>
|
||||
|
||||
---
|
||||
-- @type NpcRecord
|
||||
-- @field #string name
|
||||
@ -564,6 +574,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #ArmorRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#ArmorRecord}s in the world database.
|
||||
-- @function [parent=#Armor] records
|
||||
-- @return #list<#ArmorRecord>
|
||||
|
||||
---
|
||||
-- @type ArmorRecord
|
||||
-- @field #string id Record id
|
||||
@ -634,6 +649,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #BookRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#BookRecord}s in the world database.
|
||||
-- @function [parent=#Book] records
|
||||
-- @return #list<#BookRecord>
|
||||
|
||||
---
|
||||
-- @type BookRecord
|
||||
-- @field #string id The record ID of the book
|
||||
@ -687,6 +707,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #ClothingRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#ClothingRecord}s in the world database.
|
||||
-- @function [parent=#Clothing] records
|
||||
-- @return #list<#ClothingRecord>
|
||||
|
||||
---
|
||||
-- @type ClothingRecord
|
||||
-- @field #string id Record id
|
||||
@ -723,6 +748,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #IngredientRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#IngredientRecord}s in the world database.
|
||||
-- @function [parent=#Ingredient] records
|
||||
-- @return #list<#IngredientRecord>
|
||||
|
||||
---
|
||||
-- @type IngredientRecord
|
||||
-- @field #string id Record id
|
||||
@ -755,6 +785,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #LightRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#LightRecord}s in the world database.
|
||||
-- @function [parent=#Light] records
|
||||
-- @return #list<#LightRecord>
|
||||
|
||||
---
|
||||
-- @type LightRecord
|
||||
-- @field #string id Record id
|
||||
@ -792,6 +827,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #MiscellaneousRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#MiscellaneousRecord}s in the world database.
|
||||
-- @function [parent=#Miscellaneous] records
|
||||
-- @return #list<#MiscellaneousRecord>
|
||||
|
||||
---
|
||||
-- @type MiscellaneousRecord
|
||||
-- @field #string id The record ID of the miscellaneous item
|
||||
@ -823,6 +863,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #PotionRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#PotionRecord}s in the world database.
|
||||
-- @function [parent=#Potion] records
|
||||
-- @return #list<#PotionRecord>
|
||||
|
||||
---
|
||||
-- Creates a @{#PotionRecord} without adding it to the world database.
|
||||
-- Use @{openmw_world#(world).createRecord} to add the record to the world.
|
||||
@ -882,6 +927,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #WeaponRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#WeaponRecord}s in the world database.
|
||||
-- @function [parent=#Weapon] records
|
||||
-- @return #list<#WeaponRecord>
|
||||
|
||||
---
|
||||
-- @type WeaponRecord
|
||||
-- @field #string id Record id
|
||||
@ -938,6 +988,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #ApparatusRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#ApparatusRecord}s in the world database.
|
||||
-- @function [parent=#Apparatus] records
|
||||
-- @return #list<#ApparatusRecord>
|
||||
|
||||
---
|
||||
-- @type ApparatusRecord
|
||||
-- @field #string id The record ID of the apparatus
|
||||
@ -970,6 +1025,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #LockpickRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#LockpickRecord}s in the world database.
|
||||
-- @function [parent=#Lockpick] records
|
||||
-- @return #list<#LockpickRecord>
|
||||
|
||||
---
|
||||
-- @type LockpickRecord
|
||||
-- @field #string id The record ID of the lockpick
|
||||
@ -1002,6 +1062,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #ProbeRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#ProbeRecord}s in the world database.
|
||||
-- @function [parent=#Probe] records
|
||||
-- @return #list<#ProbeRecord>
|
||||
|
||||
---
|
||||
-- @type ProbeRecord
|
||||
-- @field #string id The record ID of the probe
|
||||
@ -1034,6 +1099,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #RepairRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#RepairRecord}s in the world database.
|
||||
-- @function [parent=#Repair] records
|
||||
-- @return #list<#RepairRecord>
|
||||
|
||||
---
|
||||
-- @type RepairRecord
|
||||
-- @field #string id The record ID of the repair tool
|
||||
@ -1064,6 +1134,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #ActivatorRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#ActivatorRecord}s in the world database.
|
||||
-- @function [parent=#Activator] records
|
||||
-- @return #list<#ActivatorRecord>
|
||||
|
||||
---
|
||||
-- @type ActivatorRecord
|
||||
-- @field #string id Record id
|
||||
@ -1107,6 +1182,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #ContainerRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#ContainerRecord}s in the world database.
|
||||
-- @function [parent=#Container] records
|
||||
-- @return #list<#ContainerRecord>
|
||||
|
||||
---
|
||||
-- @type ContainerRecord
|
||||
-- @field #string id Record id
|
||||
@ -1157,6 +1237,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #DoorRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#DoorRecord}s in the world database.
|
||||
-- @function [parent=#Door] records
|
||||
-- @return #list<#DoorRecord>
|
||||
|
||||
---
|
||||
-- @type DoorRecord
|
||||
-- @field #string id Record id
|
||||
@ -1186,6 +1271,11 @@
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #StaticRecord
|
||||
|
||||
---
|
||||
-- Returns a read-only list of all @{#StaticRecord}s in the world database.
|
||||
-- @function [parent=#Static] records
|
||||
-- @return #list<#StaticRecord>
|
||||
|
||||
---
|
||||
-- @type StaticRecord
|
||||
-- @field #string id Record id
|
||||
|
Loading…
x
Reference in New Issue
Block a user