Exemple #1
0
	virtual void PostNetworkCommand(JS::HandleValue cmd1)
	{
		JSContext* cx = GetSimContext().GetScriptInterface().GetContext();
		JSAutoRequest rq(cx);
		
		// TODO: This is a workaround because we need to pass a MutableHandle to StringifyJSON.
		JS::RootedValue cmd(cx, cmd1.get());

		PROFILE2_EVENT("post net command");
		PROFILE2_ATTR("command: %s", GetSimContext().GetScriptInterface().StringifyJSON(&cmd, false).c_str());

		// TODO: would be nicer to not use globals
		if (g_Game && g_Game->GetTurnManager())
			g_Game->GetTurnManager()->PostCommand(cmd);
	}
Exemple #2
0
void IGUIObject::ScriptEvent(const CStr& Action, JS::HandleValue Argument)
{
	auto it = m_ScriptHandlers.find(Action);
	if (it == m_ScriptHandlers.end())
		return;

	JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
	JSAutoRequest rq(cx);
	JS::AutoValueVector paramData(cx);
	paramData.append(Argument.get());
	JS::RootedObject obj(cx, GetJSObject());
	JS::RootedValue handlerVal(cx, JS::ObjectValue(*it->second));
	JS::RootedValue result(cx);
	bool ok = JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result);
	if (!ok)
	{
		JS_ReportError(cx, "Errors executing script action \"%s\"", Action.c_str());
	}
}