Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/scripting/ScriptComponent.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 21 Lines | |||||
{ | { | ||||
m_Instance.init(ScriptRequest(m_ScriptInterface).cx, instance); | m_Instance.init(ScriptRequest(m_ScriptInterface).cx, instance); | ||||
} | } | ||||
void CComponentTypeScript::Init(const CParamNode& paramNode, entity_id_t ent) | void CComponentTypeScript::Init(const CParamNode& paramNode, entity_id_t ent) | ||||
{ | { | ||||
ScriptRequest rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
Script::SetProperty(rq, m_Instance, "entity", (int)ent, true, false); | Script::SetProperty(rq, m_Instance, "entity", (int)ent, true, false); | ||||
Script::SetProperty(rq, m_Instance, "template", paramNode, true, false); | Script::SetProperty(rq, m_Instance, "template", paramNode, false, false); | ||||
ScriptFunction::CallVoid(rq, m_Instance, "Init"); | ScriptFunction::CallVoid(rq, m_Instance, "Init"); | ||||
} | } | ||||
void CComponentTypeScript::Deinit() | void CComponentTypeScript::Deinit() | ||||
{ | { | ||||
ScriptRequest rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
ScriptFunction::CallVoid(rq, m_Instance, "Deinit"); | ScriptFunction::CallVoid(rq, m_Instance, "Deinit"); | ||||
} | } | ||||
void CComponentTypeScript::Update(const CParamNode& paramNode) { | |||||
ScriptRequest rq(m_ScriptInterface); | |||||
if (!ScriptFunction::CallVoid(rq, m_Instance, "Update", paramNode)) | |||||
Script::SetProperty(rq, m_Instance, "template", paramNode, false, false); | |||||
} | |||||
void CComponentTypeScript::HandleMessage(const CMessage& msg, bool global) | void CComponentTypeScript::HandleMessage(const CMessage& msg, bool global) | ||||
{ | { | ||||
ScriptRequest rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
const char* name = global ? msg.GetScriptGlobalHandlerName() : msg.GetScriptHandlerName(); | const char* name = global ? msg.GetScriptGlobalHandlerName() : msg.GetScriptHandlerName(); | ||||
JS::RootedValue msgVal(rq.cx, msg.ToJSValCached(m_ScriptInterface)); | JS::RootedValue msgVal(rq.cx, msg.ToJSValCached(m_ScriptInterface)); | ||||
Show All 33 Lines |
Wildfire Games · Phabricator