Skip to content

Commit 456e91d

Browse files
committed
Fixed an issue where InputSingleton was not reset when the UI Registry was cleared
Fixed an issue where PCall was called without popping the return value
1 parent 453c027 commit 456e91d

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

Source/Game-Lib/Game-Lib/Scripting/Handlers/UIHandler.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ namespace Scripting::UI
8888
void UIHandler::Clear()
8989
{
9090
entt::registry* registry = ServiceLocator::GetEnttRegistries()->uiRegistry;
91+
auto& ctx = registry->ctx();
9192
auto& transformSystem = ECS::Transform2DSystem::Get(*registry);
9293

9394
registry->view<ECS::Components::UI::Widget>().each([&transformSystem](entt::entity entity, ECS::Components::UI::Widget& widget)
@@ -108,9 +109,9 @@ namespace Scripting::UI
108109
transformSystem.ClearQueue();
109110
ServiceLocator::GetGameRenderer()->GetCanvasRenderer()->Clear();
110111

111-
if (registry->ctx().contains<ECS::Singletons::UISingleton>())
112+
if (ctx.contains<ECS::Singletons::UISingleton>())
112113
{
113-
ECS::Singletons::UISingleton& uiSingleton = registry->ctx().get<ECS::Singletons::UISingleton>();
114+
ECS::Singletons::UISingleton& uiSingleton = ctx.get<ECS::Singletons::UISingleton>();
114115
uiSingleton.panelTemplates.clear();
115116
uiSingleton.textTemplates.clear();
116117

@@ -124,7 +125,14 @@ namespace Scripting::UI
124125
uiSingleton.cursorCanvasEntity = entt::null;
125126
uiSingleton.allHoveredEntities.clear();
126127
uiSingleton.scriptWidgets.clear();
127-
}
128+
}
129+
130+
if (ctx.contains<ECS::Singletons::InputSingleton>())
131+
{
132+
auto& inputSingleton = ctx.get<ECS::Singletons::InputSingleton>();
133+
inputSingleton.globalKeyboardEvents.clear();
134+
inputSingleton.eventIDToKeyboardEventIndex.clear();
135+
}
128136
}
129137

130138
// UI
@@ -974,6 +982,8 @@ namespace Scripting::UI
974982

975983
ctx.PCall(5, 1);
976984
bool result = ctx.Get(false);
985+
ctx.Pop();
986+
977987
return result; // Return if we should consume the event or not
978988
}
979989

@@ -991,6 +1001,8 @@ namespace Scripting::UI
9911001

9921002
ctx.PCall(4 , 1);
9931003
bool result = ctx.Get(false);
1004+
ctx.Pop();
1005+
9941006
return result; // Return if we should consume the event or not
9951007
}
9961008

@@ -1010,6 +1022,8 @@ namespace Scripting::UI
10101022

10111023
ctx.PCall(3, 1);
10121024
bool result = ctx.Get(false);
1025+
ctx.Pop();
1026+
10131027
return result; // Return if widget should consume the event or not
10141028
}
10151029

Source/Game-Lib/Game-Lib/Scripting/Handlers/UnitHandler.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,22 @@ namespace Scripting
5555

5656
u32 unitID = ctx.Get(std::numeric_limits<u32>().max(), 1);
5757
if (unitID == std::numeric_limits<u32>().max())
58-
{
59-
luaL_error(state, "Expected unitID as parameter 1");
60-
}
58+
return 0;
59+
6160
entt::entity entityID = entt::entity(unitID);
6261

6362
entt::registry* registry = ServiceLocator::GetEnttRegistries()->gameRegistry;
6463
if (!registry->valid(entityID))
65-
{
66-
luaL_error(state, "Invalid unitID");
67-
}
64+
return 0;
6865

6966
if (!registry->all_of<ECS::Components::Model, ECS::Components::AttachmentData>(entityID))
70-
{
71-
luaL_error(state, "Unit does not have a model or attachment data");
72-
}
67+
return 0;
7368

7469
ECS::Components::Model& model = registry->get<ECS::Components::Model>(entityID);
7570
ECS::Components::AttachmentData& attachmentData = registry->get<ECS::Components::AttachmentData>(entityID);
7671

7772
if (!Util::Attachment::EnableAttachment(entityID, model, attachmentData, Attachment::Defines::Type::PlayerName))
78-
{
79-
luaL_error(state, "Failed to enable attachment");
80-
}
73+
return 0;
8174

8275
const mat4x4* mat = Util::Attachment::GetAttachmentMatrix(attachmentData, Attachment::Defines::Type::PlayerName);
8376
vec3 position = (*mat)[3];

Source/Game-Lib/Game-Lib/Scripting/LuaState.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ namespace Scripting
216216
i32 result = lua_pcall(_state, numArgs, numResults, errorfunc);
217217
if (result != LUA_OK)
218218
{
219+
const char* errorMsg = lua_tostring(_state, -1);
219220
NC_LOG_ERROR("[Scripting] Failed to run a script. Please check the errors below and correct them");
220-
NC_LOG_ERROR("{0}", Get("Failed to read Luau Runtime Error"));
221+
NC_LOG_ERROR("{0}", errorMsg);
221222
Pop();
222223
}
223224

Source/Resources/Scripts/API/UI/Nameplate.luau

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ local function FormatText(health : number, healthPercent : number)
5757
end
5858

5959
local function SetupNameplateMethods(nameplateTable : Nameplate)
60-
6160
nameplateTable.SetEnabled = function(self : Nameplate, enabled : boolean)
6261
nameplateTable.border:SetEnabled(enabled);
6362
end

0 commit comments

Comments
 (0)