mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-09 03:58:19 +03:00
Move GameScriptInventoryObject to Scripting (and some stuff to Common to make it compile).
This commit is contained in:
parent
71946c6f93
commit
a2ecc0e55c
13 changed files with 16 additions and 9 deletions
|
@ -24,6 +24,7 @@
|
|||
<ClInclude Include="include\GameScriptAIObject.h" />
|
||||
<ClInclude Include="include\GameScriptCameraInfo.h" />
|
||||
<ClInclude Include="include\GameScriptColor.h" />
|
||||
<ClInclude Include="include\GameScriptInventoryObject.h" />
|
||||
<ClInclude Include="include\GameScriptNamedBase.h" />
|
||||
<ClInclude Include="include\GameScriptPosition.h" />
|
||||
<ClInclude Include="include\GameScriptRotation.h" />
|
||||
|
@ -39,6 +40,7 @@
|
|||
<ClCompile Include="src\GameScriptAIObject.cpp" />
|
||||
<ClCompile Include="src\GameScriptCameraInfo.cpp" />
|
||||
<ClCompile Include="src\GameScriptColor.cpp" />
|
||||
<ClCompile Include="src\GameScriptInventoryObject.cpp" />
|
||||
<ClCompile Include="src\GameScriptPosition.cpp" />
|
||||
<ClCompile Include="src\GameScriptRotation.cpp" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -45,6 +45,9 @@
|
|||
<ClInclude Include="include\GameScriptAIObject.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\GameScriptInventoryObject.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="frameworkandsol.cpp">
|
||||
|
@ -65,6 +68,9 @@
|
|||
<ClCompile Include="src\GameScriptAIObject.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\GameScriptInventoryObject.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
|
41
Scripting/include/GameScriptInventoryObject.h
Normal file
41
Scripting/include/GameScriptInventoryObject.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include "ItemEnumPair.h"
|
||||
#include "GameScriptRotation.h"
|
||||
#include "Game/gui.h"
|
||||
|
||||
static const std::unordered_map<std::string, RotationFlags> kRotAxes{
|
||||
{"X", RotationFlags::INV_ROT_X},
|
||||
{"Y", RotationFlags::INV_ROT_Y},
|
||||
{"Z", RotationFlags::INV_ROT_Z}
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string, ItemOptions> kItemActions{
|
||||
{"USE", ItemOptions::OPT_USE},
|
||||
{"EQUIP", ItemOptions::OPT_EQUIP},
|
||||
{"EXAMINE", ItemOptions::OPT_EXAMINABLE}
|
||||
};
|
||||
|
||||
namespace sol {
|
||||
class state;
|
||||
}
|
||||
|
||||
struct GameScriptInventoryObject
|
||||
{
|
||||
std::string name{};
|
||||
InventoryObjectTypes slot{ INV_OBJECT_PISTOLS };
|
||||
short yOffset{ 0 };
|
||||
float scale{ 1.0f };
|
||||
GameScriptRotation rot{};
|
||||
RotationFlags rotationFlags{ RotationFlags::INV_ROT_X };
|
||||
int meshBits{ 0 };
|
||||
ItemOptions action{ ItemOptions::OPT_USE };
|
||||
|
||||
GameScriptInventoryObject() = default;
|
||||
GameScriptInventoryObject(std::string const & a_name, ItemEnumPair a_slot, short a_yOffset, float a_scale, GameScriptRotation const & a_rot, RotationFlags a_rotationFlags, int a_meshBits, ItemOptions a_actions);
|
||||
|
||||
static void Register(sol::state* lua);
|
||||
|
||||
void SetAction(ItemOptions a_action);
|
||||
void SetSlot(ItemEnumPair a_slot);
|
||||
};
|
10
Scripting/include/ItemEnumPair.h
Normal file
10
Scripting/include/ItemEnumPair.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
#include "Game/gui.h"
|
||||
#include "Objects/objectslist.h"
|
||||
#include <utility>
|
||||
|
||||
struct ItemEnumPair
|
||||
{
|
||||
std::pair<GAME_OBJECT_ID, InventoryObjectTypes> m_pair;
|
||||
ItemEnumPair(GAME_OBJECT_ID id, InventoryObjectTypes id2) : m_pair { id, id2 } {}
|
||||
};
|
123
Scripting/src/GameScriptInventoryObject.cpp
Normal file
123
Scripting/src/GameScriptInventoryObject.cpp
Normal file
|
@ -0,0 +1,123 @@
|
|||
#include "frameworkandsol.h"
|
||||
#include "GameScriptInventoryObject.h"
|
||||
#include "ScriptAssert.h"
|
||||
#include <string>
|
||||
|
||||
/***
|
||||
Represents the properties of an object as it appears in the inventory.
|
||||
|
||||
@pregameclass InventoryObject
|
||||
@pragma nostrip
|
||||
*/
|
||||
|
||||
/*** Create an inventoryObject item. Use this if you want to specify property values later later.
|
||||
The default property values are not disclosed here, since at the time of writing, they are subject to change.
|
||||
@function InventoryObject.new
|
||||
@return an InventoryObject
|
||||
*/
|
||||
|
||||
/*** For more information on each parameter, see the
|
||||
associated getters and setters.
|
||||
@function InventoryObject.new
|
||||
@tparam string nameKey name key
|
||||
@tparam InvItem slot slot of inventory object to change
|
||||
@tparam int yOffset y-axis offset (positive values move the item down)
|
||||
@tparam float scale item size (1 being standard size)
|
||||
@tparam Rotation rot rotation about x, y, and z axes
|
||||
@tparam RotationAxis rotAxisWhenCurrent axis to rotate around in inventory
|
||||
@tparam int meshBits not currently implemented
|
||||
@tparam ItemAction action is this usable, equippable, or examinable?
|
||||
@return an InventoryObject
|
||||
*/
|
||||
GameScriptInventoryObject::GameScriptInventoryObject(std::string const& a_name, ItemEnumPair a_slot, short a_yOffset, float a_scale, GameScriptRotation const & a_rot, RotationFlags a_rotationFlags, int a_meshBits, ItemOptions a_action) :
|
||||
name{ a_name },
|
||||
slot{ a_slot.m_pair.second },
|
||||
yOffset{ a_yOffset },
|
||||
scale{ a_scale },
|
||||
rot{ a_rot },
|
||||
rotationFlags{ a_rotationFlags },
|
||||
meshBits{ a_meshBits }
|
||||
{
|
||||
SetAction(a_action);
|
||||
}
|
||||
|
||||
void GameScriptInventoryObject::Register(sol::state * lua)
|
||||
{
|
||||
lua->new_usertype<GameScriptInventoryObject>("InventoryObject",
|
||||
sol::constructors<GameScriptInventoryObject(std::string const &, ItemEnumPair, short, float, GameScriptRotation const &, RotationFlags, int, ItemOptions), GameScriptInventoryObject()>(),
|
||||
/*** (string) string key for the item's (localised) name. Corresponds to an entry in strings.lua.
|
||||
@mem nameKey
|
||||
*/
|
||||
"nameKey", &GameScriptInventoryObject::name,
|
||||
|
||||
/*** (@{InvItem}) slot of item whose inventory display properties you wish to change
|
||||
@mem slot
|
||||
*/
|
||||
"slot", sol::property(&GameScriptInventoryObject::SetSlot),
|
||||
|
||||
/*** (float) y-axis offset (positive values will move the item lower).
|
||||
A value of about 100 will cause the item to display directly below its usual position.
|
||||
@mem yOffset
|
||||
*/
|
||||
"yOffset", &GameScriptInventoryObject::yOffset,
|
||||
|
||||
/*** (float) Item's size when displayed in the inventory as a multiple of its "regular" size.
|
||||
A value of 0.5 will cause the item to render at half the size,
|
||||
and a value of 2 will cause the item to render at twice the size.
|
||||
@mem scale
|
||||
*/
|
||||
"scale", &GameScriptInventoryObject::scale,
|
||||
|
||||
/*** (@{Rotation}) Item's rotation about its origin when displayed in the inventory.
|
||||
@mem rot
|
||||
*/
|
||||
"rot", &GameScriptInventoryObject::rot,
|
||||
|
||||
/*** (RotationAxis) Axis to rotate about when the item is being looked at in the inventory.
|
||||
Note that this is entirely separate from the `rot` field described above.
|
||||
Must be RotationAxis.X, RotationAxis.Y or RotationAxis.Z.
|
||||
e.g. `myItem.rotAxisWhenCurrent = RotationAxis.X`
|
||||
@mem rotAxisWhenCurrent
|
||||
*/
|
||||
"rotAxisWhenCurrent", &GameScriptInventoryObject::rotationFlags,
|
||||
|
||||
/*** (int) __Not currently implemented__ (will have no effect regardless of what you set it to)
|
||||
@mem meshBits
|
||||
*/
|
||||
"meshBits", &GameScriptInventoryObject::meshBits,
|
||||
|
||||
/*** (ItemAction) What can the player do with the item?
|
||||
Must be one of:
|
||||
EQUIP
|
||||
USE
|
||||
EXAMINE
|
||||
e.g. `myItem.action = ItemAction.EXAMINE`
|
||||
@mem action
|
||||
*/
|
||||
"action", sol::property(&GameScriptInventoryObject::SetAction)
|
||||
);
|
||||
}
|
||||
|
||||
// Add validation so the user can't choose something unimplemented
|
||||
void GameScriptInventoryObject::SetAction(ItemOptions a_action)
|
||||
{
|
||||
bool isSupported = (a_action == ItemOptions::OPT_EQUIP) ||
|
||||
(a_action == ItemOptions::OPT_USE) ||
|
||||
(a_action == ItemOptions::OPT_EXAMINABLE);
|
||||
|
||||
if (!ScriptAssert(isSupported, "Unsupported item action: " + std::to_string(a_action)))
|
||||
{
|
||||
ItemOptions def = ItemOptions::OPT_USE;
|
||||
ScriptWarn("Defaulting to " + std::to_string(def));
|
||||
action = def;
|
||||
}
|
||||
else
|
||||
{
|
||||
action = a_action;
|
||||
}
|
||||
}
|
||||
|
||||
void GameScriptInventoryObject::SetSlot(ItemEnumPair a_slot)
|
||||
{
|
||||
slot = a_slot.m_pair.second;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue