Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/scripting/JSInterface_Main.cpp
Show All 30 Lines | |||||
#include "ps/Hotkey.h" | #include "ps/Hotkey.h" | ||||
#include "ps/Util.h" | #include "ps/Util.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "tools/atlas/GameInterface/GameLoop.h" | #include "tools/atlas/GameInterface/GameLoop.h" | ||||
extern void QuitEngine(); | extern void QuitEngine(); | ||||
extern void StartAtlas(); | extern void StartAtlas(); | ||||
void JSI_Main::QuitEngine(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void JSI_Main::QuitEngine(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
::QuitEngine(); | ::QuitEngine(); | ||||
} | } | ||||
void JSI_Main::StartAtlas(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void JSI_Main::StartAtlas(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
::StartAtlas(); | ::StartAtlas(); | ||||
} | } | ||||
bool JSI_Main::AtlasIsAvailable(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | bool JSI_Main::AtlasIsAvailable(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
return ATLAS_IsAvailable(); | return ATLAS_IsAvailable(); | ||||
} | } | ||||
bool JSI_Main::IsAtlasRunning(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | bool JSI_Main::IsAtlasRunning(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
return g_AtlasGameLoop && g_AtlasGameLoop->running; | return g_AtlasGameLoop && g_AtlasGameLoop->running; | ||||
} | } | ||||
void JSI_Main::OpenURL(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& url) | void JSI_Main::OpenURL(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::string& url) | ||||
{ | { | ||||
sys_open_url(url); | sys_open_url(url); | ||||
} | } | ||||
std::wstring JSI_Main::GetSystemUsername(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | std::wstring JSI_Main::GetSystemUsername(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
return sys_get_user_name(); | return sys_get_user_name(); | ||||
} | } | ||||
std::wstring JSI_Main::GetMatchID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | std::wstring JSI_Main::GetMatchID(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
return ps_generate_guid().FromUTF8(); | return ps_generate_guid().FromUTF8(); | ||||
} | } | ||||
JS::Value JSI_Main::LoadMapSettings(ScriptInterface::CxPrivate* pCxPrivate, const VfsPath& pathname) | JS::Value JSI_Main::LoadMapSettings(ScriptInterface::CmptPrivate* pCmptPrivate, const VfsPath& pathname) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCxPrivate); | ScriptInterface::Request rq(pCmptPrivate); | ||||
CMapSummaryReader reader; | CMapSummaryReader reader; | ||||
if (reader.LoadMap(pathname) != PSRETURN_OK) | if (reader.LoadMap(pathname) != PSRETURN_OK) | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
JS::RootedValue settings(rq.cx); | JS::RootedValue settings(rq.cx); | ||||
reader.GetMapSettings(*(pCxPrivate->pScriptInterface), &settings); | reader.GetMapSettings(*(pCmptPrivate->pScriptInterface), &settings); | ||||
return settings; | return settings; | ||||
} | } | ||||
bool JSI_Main::HotkeyIsPressed_(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& hotkeyName) | bool JSI_Main::HotkeyIsPressed_(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::string& hotkeyName) | ||||
{ | { | ||||
return HotkeyIsPressed(hotkeyName); | return HotkeyIsPressed(hotkeyName); | ||||
} | } | ||||
// This value is recalculated once a frame. We take special care to | // This value is recalculated once a frame. We take special care to | ||||
// filter it, so it is both accurate and free of jitter. | // filter it, so it is both accurate and free of jitter. | ||||
int JSI_Main::GetFps(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | int JSI_Main::GetFps(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
if (!g_frequencyFilter) | if (!g_frequencyFilter) | ||||
return 0; | return 0; | ||||
return g_frequencyFilter->StableFrequency(); | return g_frequencyFilter->StableFrequency(); | ||||
} | } | ||||
int JSI_Main::GetTextWidth(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& fontName, const std::wstring& text) | int JSI_Main::GetTextWidth(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::string& fontName, const std::wstring& text) | ||||
{ | { | ||||
int width = 0; | int width = 0; | ||||
int height = 0; | int height = 0; | ||||
CStrIntern _fontName(fontName); | CStrIntern _fontName(fontName); | ||||
CFontMetrics fontMetrics(_fontName); | CFontMetrics fontMetrics(_fontName); | ||||
fontMetrics.CalculateStringSize(text.c_str(), width, height); | fontMetrics.CalculateStringSize(text.c_str(), width, height); | ||||
return width; | return width; | ||||
} | } | ||||
std::string JSI_Main::CalculateMD5(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& input) | std::string JSI_Main::CalculateMD5(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::string& input) | ||||
{ | { | ||||
u8 digest[MD5::DIGESTSIZE]; | u8 digest[MD5::DIGESTSIZE]; | ||||
MD5 m; | MD5 m; | ||||
m.Update((const u8*)input.c_str(), input.length()); | m.Update((const u8*)input.c_str(), input.length()); | ||||
m.Final(digest); | m.Final(digest); | ||||
return Hexify(digest, MD5::DIGESTSIZE); | return Hexify(digest, MD5::DIGESTSIZE); | ||||
Show All 17 Lines |
Wildfire Games · Phabricator