Provide ScriptInterface CreateObject and CreateArray functions to replace Eval calls following 7c2e9027c2, 1c0536bf08 and later.

Differential Revision: https://code.wildfiregames.com/D2080
Previous version reviewed By: Krinkle
Comments By: historic_bruno, wraitii
This was SVN commit r22528.
This commit is contained in:
elexis
2019-07-22 19:35:14 +00:00
parent 6643613b54
commit b4626359f5
23 changed files with 316 additions and 192 deletions
+15 -10
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -295,11 +295,14 @@ void CNetClient::PostPlayerAssignmentsToScript()
for (const std::pair<CStr, PlayerAssignment>& p : m_PlayerAssignments)
{
JS::RootedValue assignment(cx);
GetScriptInterface().Eval("({})", &assignment);
GetScriptInterface().SetProperty(assignment, "name", CStrW(p.second.m_Name), false);
GetScriptInterface().SetProperty(assignment, "player", p.second.m_PlayerID, false);
GetScriptInterface().SetProperty(assignment, "status", p.second.m_Status, false);
GetScriptInterface().SetProperty(newAssignments, p.first.c_str(), assignment, false);
GetScriptInterface().CreateObject(
&assignment,
"name", CStrW(p.second.m_Name),
"player", p.second.m_PlayerID,
"status", p.second.m_Status);
GetScriptInterface().SetProperty(newAssignments, p.first.c_str(), assignment);
}
PushGuiMessage(msg);
@@ -760,10 +763,12 @@ bool CNetClient::OnKicked(void *context, CFsmEvent* event)
CKickedMessage* message = (CKickedMessage*)event->GetParamRef();
JS::RootedValue msg(cx);
client->GetScriptInterface().Eval("({})", &msg);
client->GetScriptInterface().SetProperty(msg, "username", message->m_Name);
client->GetScriptInterface().SetProperty(msg, "type", CStr("kicked"));
client->GetScriptInterface().SetProperty(msg, "banned", message->m_Ban != 0);
client->GetScriptInterface().CreateObject(
&msg,
"username", message->m_Name,
"type", CStr("kicked"),
"banned", message->m_Ban != 0);
client->PushGuiMessage(msg);
return true;