Index: ps/trunk/source/gui/Scripting/JSInterface_GUISize.h
===================================================================
--- ps/trunk/source/gui/Scripting/JSInterface_GUISize.h (revision 25442)
+++ ps/trunk/source/gui/Scripting/JSInterface_GUISize.h (revision 25443)
@@ -1,39 +1,40 @@
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 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 .
*/
#ifndef INCLUDED_JSI_GUISIZE
#define INCLUDED_JSI_GUISIZE
-class CStr8;
-class ScriptInterface;
+#include "ps/CStr.h"
+#include "scriptinterface/ScriptForward.h"
+#include "scriptinterface/ScriptTypes.h"
namespace JSI_GUISize
{
extern JSClass JSI_class;
extern JSClassOps JSI_classops;
extern JSPropertySpec JSI_props[];
extern JSFunctionSpec JSI_methods[];
void RegisterScriptClass(ScriptInterface& scriptInterface);
bool construct(JSContext* cx, uint argc, JS::Value* vp);
bool toString(JSContext* cx, uint argc, JS::Value* vp);
- CStr8 ToPercentString(double pix, double per);
+ CStr ToPercentString(double pix, double per);
}
#endif // INCLUDED_JSI_GUISIZE
Index: ps/trunk/source/gui/SettingTypes/CGUISize.cpp
===================================================================
--- ps/trunk/source/gui/SettingTypes/CGUISize.cpp (revision 25442)
+++ ps/trunk/source/gui/SettingTypes/CGUISize.cpp (revision 25443)
@@ -1,230 +1,231 @@
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 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 .
*/
#include "precompiled.h"
#include "CGUISize.h"
#include "gui/Scripting/JSInterface_GUISize.h"
#include "ps/CLogger.h"
+#include "ps/CStr.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptInterface.h"
CGUISize::CGUISize()
: pixel(), percent()
{
}
CGUISize::CGUISize(const CRect& pixel, const CRect& percent)
: pixel(pixel), percent(percent)
{
}
CGUISize CGUISize::Full()
{
return CGUISize(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100));
}
CRect CGUISize::GetSize(const CRect& parent) const
{
// If it's a 0 0 100% 100% we need no calculations
if (percent == CRect(0.f, 0.f, 100.f, 100.f) && pixel == CRect())
return parent;
CRect client;
// This should probably be cached and not calculated all the time for every object.
client.left = parent.left + (parent.right-parent.left)*percent.left/100.f + pixel.left;
client.top = parent.top + (parent.bottom-parent.top)*percent.top/100.f + pixel.top;
client.right = parent.left + (parent.right-parent.left)*percent.right/100.f + pixel.right;
client.bottom = parent.top + (parent.bottom-parent.top)*percent.bottom/100.f + pixel.bottom;
return client;
}
bool CGUISize::FromString(const CStr& Value)
{
/*
* GUISizes contain a left, top, right, and bottom
* for example: "50%-150 10%+9 50%+150 10%+25" means
* the left edge is at 50% minus 150 pixels, the top
* edge is at 10% plus 9 pixels, the right edge is at
* 50% plus 150 pixels, and the bottom edge is at 10%
* plus 25 pixels.
* All four coordinates are required and can be
* defined only in pixels, only in percents, or some
* combination of both.
*/
// Check the input is only numeric
const char* input = Value.c_str();
- CStr buffer = "";
+ CStr buffer;
unsigned int coord = 0;
float pixels[4] = {0, 0, 0, 0};
float percents[4] = {0, 0, 0, 0};
for (unsigned int i = 0; i < Value.length(); ++i)
{
switch (input[i])
{
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
buffer.push_back(input[i]);
break;
case '+':
pixels[coord] += buffer.ToFloat();
buffer = "+";
break;
case '-':
pixels[coord] += buffer.ToFloat();
buffer = "-";
break;
case '%':
percents[coord] += buffer.ToFloat();
buffer = "";
break;
case ' ':
pixels[coord] += buffer.ToFloat();
buffer = "";
++coord;
break;
default:
LOGERROR("CGUISize definition may only include numbers. Your input: '%s'", Value.c_str());
return false;
}
if (coord > 3)
{
LOGERROR("Too many CGUISize parameters (4 max). Your input: '%s'", Value.c_str());
return false;
}
}
if (coord < 3)
{
LOGERROR("Too few CGUISize parameters (4 min). Your input: '%s'", Value.c_str());
return false;
}
// Now that we're at the end of the string, flush the remaining buffer.
pixels[coord] += buffer.ToFloat();
// Now store the coords in the right place
pixel.left = pixels[0];
pixel.top = pixels[1];
pixel.right = pixels[2];
pixel.bottom = pixels[3];
percent.left = percents[0];
percent.top = percents[1];
percent.right = percents[2];
percent.bottom = percents[3];
return true;
}
void CGUISize::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret) const
{
const ScriptInterface& scriptInterface = rq.GetScriptInterface();
ret.setObjectOrNull(scriptInterface.CreateCustomObject("GUISize"));
if (!ret.isObject())
{
ScriptException::Raise(rq, "CGUISize value is not an Object");
return;
}
JS::RootedObject obj(rq.cx, &ret.toObject());
if (!JS_InstanceOf(rq.cx, obj, &JSI_GUISize::JSI_class, nullptr))
{
ScriptException::Raise(rq, "CGUISize value is not a CGUISize class instance");
return;
}
#define P(x, y, z)\
if (!Script::SetProperty(rq, ret, #z, x.y)) \
{ \
ScriptException::Raise(rq, "Could not SetProperty '%s'", #z); \
return; \
}
P(pixel, left, left);
P(pixel, top, top);
P(pixel, right, right);
P(pixel, bottom, bottom);
P(percent, left, rleft);
P(percent, top, rtop);
P(percent, right, rright);
P(percent, bottom, rbottom);
#undef P
}
bool CGUISize::FromJSVal(const ScriptRequest& rq, JS::HandleValue v)
{
if (v.isString())
{
CStrW str;
if (!Script::FromJSVal(rq, v, str))
{
LOGERROR("CGUISize could not read JS string");
return false;
}
if (!FromString(str.ToUTF8()))
{
LOGERROR("CGUISize could not parse JS string");
return false;
}
return true;
}
if (!v.isObject())
{
LOGERROR("CGUISize value is not an String, nor Object");
return false;
}
JS::RootedObject obj(rq.cx, &v.toObject());
if (!JS_InstanceOf(rq.cx, obj, &JSI_GUISize::JSI_class, nullptr))
{
LOGERROR("CGUISize value is not a CGUISize class instance");
return false;
}
#define P(x, y, z) \
if (!Script::GetProperty(rq, v, #z, x.y))\
{\
LOGERROR("CGUISize could not get object property '%s'", #z);\
return false;\
}
P(pixel, left, left);
P(pixel, top, top);
P(pixel, right, right);
P(pixel, bottom, bottom);
P(percent, left, rleft);
P(percent, top, rtop);
P(percent, right, rright);
P(percent, bottom, rbottom);
#undef P
return true;
}
Index: ps/trunk/source/lobby/scripting/GlooxScriptConversions.cpp
===================================================================
--- ps/trunk/source/lobby/scripting/GlooxScriptConversions.cpp (revision 25442)
+++ ps/trunk/source/lobby/scripting/GlooxScriptConversions.cpp (revision 25443)
@@ -1,61 +1,61 @@
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 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 .
*/
#include "precompiled.h"
#include "lib/config2.h"
#if CONFIG2_LOBBY
-
+#include "lib/utf8.h"
#include "lobby/XmppClient.h"
#include "scriptinterface/ScriptConversions.h"
template<> void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const glooxwrapper::string& val)
{
ToJSVal(rq, ret, wstring_from_utf8(val.to_string()));
}
template<> void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::Presence::PresenceType& val)
{
ToJSVal(rq, ret, XmppClient::GetPresenceString(val));
}
template<> void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::MUCRoomRole& val)
{
ToJSVal(rq, ret, XmppClient::GetRoleString(val));
}
template<> void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::StanzaError& val)
{
ToJSVal(rq, ret, wstring_from_utf8(XmppClient::StanzaErrorToString(val)));
}
template<> void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::ConnectionError& val)
{
ToJSVal(rq, ret, wstring_from_utf8(XmppClient::ConnectionErrorToString(val)));
}
template<> void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::RegistrationResult& val)
{
ToJSVal(rq, ret, wstring_from_utf8(XmppClient::RegistrationResultToString(val)));
}
template<> void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::CertStatus& val)
{
ToJSVal(rq, ret, wstring_from_utf8(XmppClient::CertificateErrorToString(val)));
}
#endif // CONFIG2_LOBBY
Index: ps/trunk/source/ps/Mod.h
===================================================================
--- ps/trunk/source/ps/Mod.h (revision 25442)
+++ ps/trunk/source/ps/Mod.h (revision 25443)
@@ -1,67 +1,66 @@
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 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 .
*/
#ifndef INCLUDED_MOD
#define INCLUDED_MOD
#include "ps/CStr.h"
#include "ps/GameSetup/CmdLineArgs.h"
-
-class ScriptContext;
+#include "scriptinterface/ScriptForward.h"
extern std::vector g_modsLoaded;
extern CmdLineArgs g_args;
namespace Mod
{
JS::Value GetAvailableMods(const ScriptInterface& scriptInterface);
const std::vector& GetEnabledMods();
const std::vector& GetIncompatibleMods();
const std::vector& GetFailedMods();
/**
* This reads the version numbers from the launched mods.
* It caches the result, since the reading of zip files is slow and
* JS pages can request the version numbers too often easily.
* Make sure this is called after each MountMods call.
*/
void CacheEnabledModVersions(const shared_ptr& scriptContext);
const std::vector& GetModsFromArguments(const CmdLineArgs& args, int flags);
bool AreModsCompatible(const ScriptInterface& scriptInterface, const std::vector& mods, const JS::RootedValue& availableMods);
bool CheckAndEnableMods(const ScriptInterface& scriptInterface, const std::vector& mods);
bool CompareVersionStrings(const CStr& required, const CStr& op, const CStr& version);
void SetDefaultMods();
void ClearIncompatibleMods();
/**
* Get the loaded mods and their version.
* "user" mod and "mod" mod are ignored as they are irrelevant for compatibility checks.
*
* @param scriptInterface the ScriptInterface in which to create the return data.
* @return list of loaded mods with the format [[modA, versionA], [modB, versionB], ...]
*/
JS::Value GetLoadedModsWithVersions(const ScriptInterface& scriptInterface);
/**
* Gets info (version and mods loaded) on the running engine
*
* @param scriptInterface the ScriptInterface in which to create the return data.
* @return list of objects containing data
*/
JS::Value GetEngineInfo(const ScriptInterface& scriptInterface);
}
#endif // INCLUDED_MOD
Index: ps/trunk/source/ps/ModIo.h
===================================================================
--- ps/trunk/source/ps/ModIo.h (revision 25442)
+++ ps/trunk/source/ps/ModIo.h (revision 25443)
@@ -1,208 +1,211 @@
/* Copyright (C) 2021 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef INCLUDED_MODIO
#define INCLUDED_MODIO
#include "lib/external_libraries/curl.h"
#include "lib/os_path.h"
+#include "scriptinterface/ScriptForward.h"
+#include