JSBool JSI_GUIMouse::toString(JSContext* cx, uint argc, jsval* vp) { UNUSED2(argc); i32 x, y, buttons; ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "x", x); pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "y", y); pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "buttons", buttons); char buffer[256]; snprintf(buffer, 256, "%d %d %d", x, y, buttons); JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buffer))); return JS_TRUE; }
/** * Send a request to register a game to the server. * * @param data A JS array of game attributes */ void XmppClient::SendIqRegisterGame(ScriptInterface& scriptInterface, CScriptVal data) { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); jsval dataval = data.get(); // Setup some base stanza attributes GameListQuery* g = new GameListQuery(); g->m_Command = "register"; glooxwrapper::Tag* game = glooxwrapper::Tag::allocate("game"); // Add a fake ip which will be overwritten by the ip stamp XMPP module on the server. game->addAttribute("ip", "fake"); // Iterate through all the properties reported and add them to the stanza. std::vector<std::string> properties; scriptInterface.EnumeratePropertyNamesWithPrefix(dataval, "", properties); for (std::vector<int>::size_type i = 0; i != properties.size(); i++) { std::wstring value; scriptInterface.GetProperty(dataval, properties[i].c_str(), value); game->addAttribute(properties[i], utf8_from_wstring(value)); } // Push the stanza onto the IQ g->m_GameList.push_back(game); // Send IQ glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid); iq.addExtension(g); DbgXMPP("SendIqRegisterGame [" << tag_xml(iq) << "]"); m_client->send(iq); }
/** * Send game report containing numerous game properties to the server. * * @param data A JS array of game statistics */ void XmppClient::SendIqGameReport(ScriptInterface& scriptInterface, CScriptVal data) { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); jsval dataval = data.get(); // Setup some base stanza attributes GameReport* game = new GameReport(); glooxwrapper::Tag* report = glooxwrapper::Tag::allocate("game"); // Iterate through all the properties reported and add them to the stanza. std::vector<std::string> properties; scriptInterface.EnumeratePropertyNamesWithPrefix(dataval, "", properties); for (std::vector<int>::size_type i = 0; i != properties.size(); i++) { std::wstring value; scriptInterface.GetProperty(dataval, properties[i].c_str(), value); report->addAttribute(properties[i], utf8_from_wstring(value)); } // Add stanza to IQ game->m_GameReport.push_back(report); // Send IQ glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid); iq.addExtension(game); DbgXMPP("SendGameReport [" << tag_xml(iq) << "]"); m_client->send(iq); };
JSBool JSI_GUIColor::toString(JSContext* cx, uint argc, jsval* vp) { UNUSED2(argc); double r, g, b, a; ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "r", r); pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "g", g); pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "b", b); pScriptInterface->GetProperty(JS_THIS_VALUE(cx, vp), "a", a); char buffer[256]; // Convert to integers, to be compatible with the GUI's string SetSetting snprintf(buffer, 256, "%d %d %d %d", (int)(255.0 * r), (int)(255.0 * g), (int)(255.0 * b), (int)(255.0 * a)); JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buffer))); return JS_TRUE; }
std::vector<std::string> CTemplateLoader::FindPlaceableTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType, ScriptInterface& scriptInterface) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); std::vector<std::string> templates; Status ok; VfsPath templatePath; if (templatesType == SIMULATION_TEMPLATES || templatesType == ALL_TEMPLATES) { JS::RootedValue placeablesFilter(cx); scriptInterface.ReadJSONFile("simulation/data/placeablesFilter.json", &placeablesFilter); JS::RootedObject folders(cx); if (scriptInterface.GetProperty(placeablesFilter, "templates", &folders)) { if (!(JS_IsArrayObject(cx, folders))) { LOGERROR("FindPlaceableTemplates: Argument must be an array!"); return templates; } u32 length; if (!JS_GetArrayLength(cx, folders, &length)) { LOGERROR("FindPlaceableTemplates: Failed to get array length!"); return templates; } templatePath = VfsPath(TEMPLATE_ROOT) / path; //I have every object inside, just run for each for (u32 i=0; i<length; ++i) { JS::RootedValue val(cx); if (!JS_GetElement(cx, folders, i, &val)) { LOGERROR("FindPlaceableTemplates: Failed to read array element!"); return templates; } std::string directoryPath; std::wstring fileFilter; scriptInterface.GetProperty(val, "directory", directoryPath); scriptInterface.GetProperty(val, "file", fileFilter); VfsPaths filenames; if (vfs::GetPathnames(g_VFS, templatePath / (directoryPath + "/"), fileFilter.c_str(), filenames) != INFO::OK) continue; for (const VfsPath& filename : filenames) { // Strip the .xml extension VfsPath pathstem = filename.ChangeExtension(L""); // Strip the root from the path std::wstring name = pathstem.string().substr(ARRAY_SIZE(TEMPLATE_ROOT) - 1); templates.emplace_back(name.begin(), name.end()); } } } } if (templatesType == ACTOR_TEMPLATES || templatesType == ALL_TEMPLATES) { templatePath = VfsPath(ACTOR_ROOT) / path; if (includeSubdirectories) ok = vfs::ForEachFile(g_VFS, templatePath, AddActorToTemplates, (uintptr_t)&templates, L"*.xml", vfs::DIR_RECURSIVE); else ok = vfs::ForEachFile(g_VFS, templatePath, AddActorToTemplates, (uintptr_t)&templates, L"*.xml"); WARN_IF_ERR(ok); } if (templatesType != SIMULATION_TEMPLATES && templatesType != ACTOR_TEMPLATES && templatesType != ALL_TEMPLATES) LOGERROR("Undefined template type (valid: all, simulation, actor)"); return templates; }