Changeset View
Changeset View
Standalone View
Standalone View
source/gui/Scripting/JSInterface_CMiniMap.cpp
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
/* Copyright (C) 2020 Wildfire Games. | |||||
* This file is part of 0 A.D. | |||||
vladislavbelov: It seems we already have pretty similar code. I think it should be reused. Also some parts of… | |||||
* | |||||
* 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 | |||||
* the Free Software Foundation, either version 2 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* 0 A.D. is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "precompiled.h" | |||||
#include "JSInterface_GUIProxy_impl.h" | |||||
#include "gui/ObjectTypes/CMiniMap.h" | |||||
#include "maths/Vector2D.h" | |||||
#include "ps/CLogger.h" | |||||
bool CMiniMap_Flare(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
CMiniMap* obj = static_cast<CMiniMap*>(js::GetProxyPrivate(args.thisv().toObjectOrNull()).toPrivate()); | |||||
if (!obj) | |||||
return false; | |||||
if (args.length() != 2) | |||||
Done Inline Actions*Cough*. vladislavbelov: *Cough*. | |||||
{ | |||||
LOGERROR("CMiniMap::Flare: Got %d arguments, but expected 2.", args.length()); | |||||
return false; | |||||
} | |||||
Done Inline ActionsBraces on new lines. vladislavbelov: Braces on new lines. | |||||
ScriptInterface& scriptInterface = *ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; | |||||
ScriptRequest rq(scriptInterface); | |||||
CVector2D pos; | |||||
CStr colorStr; | |||||
CColor color; | |||||
if (!(ScriptInterface::FromJSVal(rq, args.get(0), pos) && | |||||
ScriptInterface::FromJSVal(rq, args.get(1), colorStr) && | |||||
color.ParseString(colorStr))) | |||||
return false; | |||||
bool ret = obj->Flare(pos, color); | |||||
args.rval().set(JS::BooleanValue(ret)); | |||||
return true; | |||||
} | |||||
using GUIObjectType = CMiniMap; | |||||
template <> | |||||
void JSI_GUIProxy<GUIObjectType>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache) | |||||
{ | |||||
#define func(class, func) &JSInterface_GUIProxy::apply_to<GUIObjectType, class, &class::func> | |||||
cache->setFunction(rq, "toString", func(IGUIObject, toString), 0); | |||||
cache->setFunction(rq, "focus", func(IGUIObject, focus), 0); | |||||
cache->setFunction(rq, "blur", func(IGUIObject, blur), 0); | |||||
cache->setFunction(rq, "getComputedSize", func(IGUIObject, getComputedSize), 0); | |||||
#undef func | |||||
cache->setFunction(rq, "flare", CMiniMap_Flare, 1); | |||||
} | |||||
template class JSI_GUIProxy<GUIObjectType>; | |||||
Done Inline ActionsNeed to call this in AddObjectTypes wraitii: Need to call this in `AddObjectTypes` | |||||
Done Inline ActionsMacro in upper case with underscores. vladislavbelov: Macro in upper case with underscores. | |||||
Done Inline ActionsStill small. vladislavbelov: Still small. |
Wildfire Games · Phabricator
It seems we already have pretty similar code. I think it should be reused. Also some parts of the existing code were refactored.