mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-07 11:13:53 +03:00
Move Inventory functions into their own file.
This commit is contained in:
parent
dbbcd7b6d7
commit
4573db873d
7 changed files with 27 additions and 86 deletions
|
@ -88,6 +88,7 @@
|
||||||
<ClInclude Include="src\GameScriptSettings.h" />
|
<ClInclude Include="src\GameScriptSettings.h" />
|
||||||
<ClInclude Include="src\GameScriptSkyLayer.h" />
|
<ClInclude Include="src\GameScriptSkyLayer.h" />
|
||||||
<ClInclude Include="src\InventorySlots.h" />
|
<ClInclude Include="src\InventorySlots.h" />
|
||||||
|
<ClInclude Include="src\Inventory\InventoryHandler.h" />
|
||||||
<ClInclude Include="src\ItemEnumPair.h" />
|
<ClInclude Include="src\ItemEnumPair.h" />
|
||||||
<ClInclude Include="src\Logic\LogicHandler.h" />
|
<ClInclude Include="src\Logic\LogicHandler.h" />
|
||||||
<ClInclude Include="src\LuaHandler.h" />
|
<ClInclude Include="src\LuaHandler.h" />
|
||||||
|
@ -114,6 +115,7 @@
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\Flow\FlowHandler.cpp" />
|
<ClCompile Include="src\Flow\FlowHandler.cpp" />
|
||||||
|
<ClCompile Include="src\Inventory\InventoryHandler.cpp" />
|
||||||
<ClCompile Include="src\Logic\LogicHandler.cpp" />
|
<ClCompile Include="src\Logic\LogicHandler.cpp" />
|
||||||
<ClCompile Include="src\Objects\AIObject\AIObject.cpp" />
|
<ClCompile Include="src\Objects\AIObject\AIObject.cpp" />
|
||||||
<ClCompile Include="src\Objects\Camera\Camera.cpp" />
|
<ClCompile Include="src\Objects\Camera\Camera.cpp" />
|
||||||
|
|
|
@ -276,6 +276,9 @@
|
||||||
<ClInclude Include="include\Scripting\Flow\ScriptInterfaceFlowHandler.h">
|
<ClInclude Include="include\Scripting\Flow\ScriptInterfaceFlowHandler.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\Inventory\InventoryHandler.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="frameworkandsol.cpp">
|
<ClCompile Include="frameworkandsol.cpp">
|
||||||
|
@ -353,6 +356,9 @@
|
||||||
<ClCompile Include="src\Flow\FlowHandler.cpp">
|
<ClCompile Include="src\Flow\FlowHandler.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Inventory\InventoryHandler.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
|
|
@ -32,7 +32,6 @@ FlowHandler::FlowHandler(sol::state* lua, sol::table & parent) : LuaHandler{ lua
|
||||||
GameScriptInventoryObject::Register(m_lua);
|
GameScriptInventoryObject::Register(m_lua);
|
||||||
GameScriptSettings::Register(m_lua);
|
GameScriptSettings::Register(m_lua);
|
||||||
GameScriptAnimations::Register(m_lua);
|
GameScriptAnimations::Register(m_lua);
|
||||||
GameScriptAudioTrack::Register(m_lua);
|
|
||||||
GameScriptColor::Register(m_lua);
|
GameScriptColor::Register(m_lua);
|
||||||
GameScriptRotation::Register(m_lua);
|
GameScriptRotation::Register(m_lua);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "GameScriptColor.h"
|
#include "GameScriptColor.h"
|
||||||
#include "GameScriptLevel.h"
|
#include "GameScriptLevel.h"
|
||||||
#include "GameScriptSettings.h"
|
#include "GameScriptSettings.h"
|
||||||
#include "GameScriptAudioTrack.h"
|
|
||||||
#include "GameScriptAnimations.h"
|
#include "GameScriptAnimations.h"
|
||||||
#include "ScriptInterfaceGame.h"
|
#include "ScriptInterfaceGame.h"
|
||||||
#include "Flow/ScriptInterfaceFlowHandler.h"
|
#include "Flow/ScriptInterfaceFlowHandler.h"
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
#include "Game\effects\lightning.h"
|
#include "Game\effects\lightning.h"
|
||||||
#include "effects\tomb4fx.h"
|
#include "effects\tomb4fx.h"
|
||||||
#include "effects\effects.h"
|
#include "effects\effects.h"
|
||||||
|
#include "Specific/configuration.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "pickup.h"
|
|
||||||
#include "ItemEnumPair.h"
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
Scripts that will be run on game startup.
|
Scripts that will be run on game startup.
|
||||||
|
@ -98,41 +97,6 @@ namespace GameScriptFreeFunctions {
|
||||||
{
|
{
|
||||||
PlaySoundTrack(trackName, SOUNDTRACK_PLAYTYPE::BGM);
|
PlaySoundTrack(trackName, SOUNDTRACK_PLAYTYPE::BGM);
|
||||||
}
|
}
|
||||||
static void InventoryAdd(ItemEnumPair slot, sol::optional<int> count)
|
|
||||||
{
|
|
||||||
// If 0 is passed in, then the amount added will be the default amount
|
|
||||||
// for that pickup - i.e. the amount you would get from picking up the
|
|
||||||
// item in-game (e.g. 1 for medipacks, 12 for flares).
|
|
||||||
PickedUpObject(slot.m_pair.first, count.value_or(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void InventoryRemove(ItemEnumPair slot, sol::optional<int> count)
|
|
||||||
{
|
|
||||||
// 0 is default for the same reason as in InventoryAdd.
|
|
||||||
RemoveObjectFromInventory(slot.m_pair.first, count.value_or(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int InventoryGetCount(ItemEnumPair slot)
|
|
||||||
{
|
|
||||||
return GetInventoryCount(slot.m_pair.first);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void InventorySetCount(ItemEnumPair slot, int count)
|
|
||||||
{
|
|
||||||
// add the amount we'd need to add to get to count
|
|
||||||
int currAmt = GetInventoryCount(slot.m_pair.first);
|
|
||||||
InventoryAdd(slot, count - currAmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void InventoryCombine(int slot1, int slot2)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void InventorySeparate(int slot)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static int CalculateDistance(GameScriptPosition const& pos1, GameScriptPosition const& pos2)
|
static int CalculateDistance(GameScriptPosition const& pos1, GameScriptPosition const& pos2)
|
||||||
{
|
{
|
||||||
|
@ -179,40 +143,6 @@ namespace GameScriptFreeFunctions {
|
||||||
//@tparam bool loop if true, the track will loop; if false, it won't (default: false)
|
//@tparam bool loop if true, the track will loop; if false, it won't (default: false)
|
||||||
lua->set_function(ScriptReserved_PlayAudioTrack, &PlayAudioTrack);
|
lua->set_function(ScriptReserved_PlayAudioTrack, &PlayAudioTrack);
|
||||||
|
|
||||||
///Add x of an item to the inventory.
|
|
||||||
//A count of 0 will add the "default" amount of that item
|
|
||||||
//(i.e. the amount the player would get from a pickup of that type).
|
|
||||||
//For example, giving "zero" crossbow ammo would give the player
|
|
||||||
//10 instead, whereas giving "zero" medkits would give the player 1 medkit.
|
|
||||||
//@function GiveInvItem
|
|
||||||
//@tparam InvItem item the item to be added
|
|
||||||
//@tparam int count the number of items to add (default: 0)
|
|
||||||
lua->set_function(ScriptReserved_GiveInvItem, &InventoryAdd);
|
|
||||||
|
|
||||||
|
|
||||||
//Remove x of a certain item from the inventory.
|
|
||||||
//As in @{GiveInvItem}, a count of 0 will remove the "default" amount of that item.
|
|
||||||
//@function TakeInvItem
|
|
||||||
//@tparam InvItem item the item to be removed
|
|
||||||
//@tparam int count the number of items to remove (default: 0)
|
|
||||||
|
|
||||||
lua->set_function(ScriptReserved_TakeInvItem, &InventoryRemove);
|
|
||||||
|
|
||||||
|
|
||||||
///Get the amount the player holds of an item.
|
|
||||||
//@function GetInvItemCount
|
|
||||||
//@tparam InvItem item the item to check
|
|
||||||
//@treturn int the amount of the item the player has in the inventory
|
|
||||||
|
|
||||||
lua->set_function(ScriptReserved_GetInvItemCount, &InventoryGetCount);
|
|
||||||
|
|
||||||
|
|
||||||
///Set the amount of a certain item the player has in the inventory.
|
|
||||||
//Similar to @{GiveInvItem} but replaces with the new amount instead of adding it.
|
|
||||||
//@function SetInvItemCount
|
|
||||||
//@tparam @{InvItem} item the item to be set
|
|
||||||
//@tparam int count the number of items the player will have
|
|
||||||
lua->set_function(ScriptReserved_SetInvItemCount, &InventorySetCount);
|
|
||||||
|
|
||||||
|
|
||||||
///Calculate the distance between two positions.
|
///Calculate the distance between two positions.
|
||||||
|
|
|
@ -6,6 +6,7 @@ static constexpr char const ScriptReserved_Flow[] = "Flow";
|
||||||
static constexpr char const ScriptReserved_Logic[] = "Logic";
|
static constexpr char const ScriptReserved_Logic[] = "Logic";
|
||||||
static constexpr char const ScriptReserved_Objects[] = "Objects";
|
static constexpr char const ScriptReserved_Objects[] = "Objects";
|
||||||
static constexpr char const ScriptReserved_Strings[] = "Strings";
|
static constexpr char const ScriptReserved_Strings[] = "Strings";
|
||||||
|
static constexpr char const ScriptReserved_Inventory[] = "Inventory";
|
||||||
|
|
||||||
// Classes
|
// Classes
|
||||||
static constexpr char const ScriptReserved_Moveable[] = "Moveable";
|
static constexpr char const ScriptReserved_Moveable[] = "Moveable";
|
||||||
|
@ -41,10 +42,10 @@ static constexpr char const ScriptReserved_ShowString[] = "ShowString";
|
||||||
static constexpr char const ScriptReserved_HideString[] = "HideString";
|
static constexpr char const ScriptReserved_HideString[] = "HideString";
|
||||||
static constexpr char const ScriptReserved_SetAmbientTrack[] = "SetAmbientTrack";
|
static constexpr char const ScriptReserved_SetAmbientTrack[] = "SetAmbientTrack";
|
||||||
static constexpr char const ScriptReserved_PlayAudioTrack[] = "PlayAudioTrack";
|
static constexpr char const ScriptReserved_PlayAudioTrack[] = "PlayAudioTrack";
|
||||||
static constexpr char const ScriptReserved_GiveInvItem[] = "GiveInvItem";
|
static constexpr char const ScriptReserved_GiveInvItem[] = "GiveItem";
|
||||||
static constexpr char const ScriptReserved_TakeInvItem[] = "TakeInvItem";
|
static constexpr char const ScriptReserved_TakeInvItem[] = "TakeItem";
|
||||||
static constexpr char const ScriptReserved_GetInvItemCount[] = "GetInvItemCount";
|
static constexpr char const ScriptReserved_GetInvItemCount[] = "GetItemCount";
|
||||||
static constexpr char const ScriptReserved_SetInvItemCount[] = "SetInvItemCount";
|
static constexpr char const ScriptReserved_SetInvItemCount[] = "SetItemCount";
|
||||||
static constexpr char const ScriptReserved_GetMoveableByName[] = "GetMoveableByName";
|
static constexpr char const ScriptReserved_GetMoveableByName[] = "GetMoveableByName";
|
||||||
static constexpr char const ScriptReserved_GetStaticByName[] = "GetStaticByName";
|
static constexpr char const ScriptReserved_GetStaticByName[] = "GetStaticByName";
|
||||||
static constexpr char const ScriptReserved_GetCameraByName[] = "GetCameraByName";
|
static constexpr char const ScriptReserved_GetCameraByName[] = "GetCameraByName";
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
#include "Flow/FlowHandler.h"
|
#include "Flow/FlowHandler.h"
|
||||||
#include "Objects/ObjectsHandler.h"
|
#include "Objects/ObjectsHandler.h"
|
||||||
#include "Strings/StringsHandler.h"
|
#include "Strings/StringsHandler.h"
|
||||||
|
#include "Inventory/InventoryHandler.h"
|
||||||
#include "ReservedScriptNames.h"
|
#include "ReservedScriptNames.h"
|
||||||
|
|
||||||
static sol::state g_solState;
|
static sol::state s_solState;
|
||||||
static sol::table s_rootTable;
|
static sol::table s_rootTable;
|
||||||
|
|
||||||
int lua_exception_handler(lua_State* L, sol::optional<std::exception const &> maybe_exception, sol::string_view description)
|
int lua_exception_handler(lua_State* L, sol::optional<std::exception const &> maybe_exception, sol::string_view description)
|
||||||
|
@ -16,30 +17,33 @@ int lua_exception_handler(lua_State* L, sol::optional<std::exception const &> ma
|
||||||
|
|
||||||
ScriptInterfaceGame* ScriptInterfaceState::CreateGame()
|
ScriptInterfaceGame* ScriptInterfaceState::CreateGame()
|
||||||
{
|
{
|
||||||
return new LogicHandler(&g_solState, s_rootTable);
|
return new LogicHandler(&s_solState, s_rootTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptInterfaceFlowHandler* ScriptInterfaceState::CreateFlow()
|
ScriptInterfaceFlowHandler* ScriptInterfaceState::CreateFlow()
|
||||||
{
|
{
|
||||||
return new FlowHandler(&g_solState, s_rootTable);
|
return new FlowHandler(&s_solState, s_rootTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptInterfaceObjectsHandler* ScriptInterfaceState::CreateObjectsHandler()
|
ScriptInterfaceObjectsHandler* ScriptInterfaceState::CreateObjectsHandler()
|
||||||
{
|
{
|
||||||
return new ObjectsHandler(&g_solState, s_rootTable);
|
return new ObjectsHandler(&s_solState, s_rootTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptInterfaceStringsHandler* ScriptInterfaceState::CreateStringsHandler()
|
ScriptInterfaceStringsHandler* ScriptInterfaceState::CreateStringsHandler()
|
||||||
{
|
{
|
||||||
return new StringsHandler(&g_solState, s_rootTable);
|
return new StringsHandler(&s_solState, s_rootTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptInterfaceState::Init()
|
void ScriptInterfaceState::Init()
|
||||||
{
|
{
|
||||||
g_solState.open_libraries(sol::lib::base, sol::lib::math);
|
s_solState.open_libraries(sol::lib::base, sol::lib::math);
|
||||||
g_solState.set_exception_handler(lua_exception_handler);
|
s_solState.set_exception_handler(lua_exception_handler);
|
||||||
|
|
||||||
s_rootTable = sol::table{ g_solState.lua_state(), sol::create };
|
s_rootTable = sol::table{ s_solState.lua_state(), sol::create };
|
||||||
g_solState.set(ScriptReserved_TEN, s_rootTable);
|
s_solState.set(ScriptReserved_TEN, s_rootTable);
|
||||||
|
|
||||||
|
// Misc handlers not assigned above
|
||||||
|
InventoryHandler::Register(&s_solState, s_rootTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue