std::size_t SerializerElement::GetChildrenCount( gd::String name, gd::String deprecatedName) const { if (name.empty()) { if (arrayOf.empty()) { std::cout << "ERROR: Getting children count without specifying name, from a " "SerializerElement which is NOT considered as an array." << std::endl; return 0; } name = arrayOf; deprecatedName = deprecatedArrayOf; } std::size_t currentIndex = 0; for (size_t i = 0; i < children.size(); ++i) { if (children[i].second == std::shared_ptr<SerializerElement>()) continue; if (children[i].first == name || (!arrayOf.empty() && children[i].first.empty()) || (!deprecatedName.empty() && children[i].first == deprecatedName)) currentIndex++; } return currentIndex; }
void GD_EXTENSION_API CaptureScreen( RuntimeScene & scene, const gd::String & destFileName, const gd::String & destImageName ) { if ( !scene.renderWindow ) return; sf::Image capture = scene.renderWindow->capture(); if ( !destFileName.empty() ) capture.saveToFile(destFileName.ToLocale()); if ( !destImageName.empty() && scene.GetImageManager()->HasLoadedSFMLTexture(destImageName) ) { std::shared_ptr<SFMLTextureWrapper> sfmlTexture = scene.GetImageManager()->GetSFMLTexture(destImageName); sfmlTexture->image = capture; sfmlTexture->texture.loadFromImage(sfmlTexture->image); //Do not forget to update the associated texture } }
void GD_API SendHttpRequest(const gd::String & host, const gd::String & uri, const gd::String & body, const gd::String & method, const gd::String & contentType, gd::Variable & responseVar) { // Separate the host and the port number auto hostInfo = host.Split(U':'); if(hostInfo.size() < 2) return; //Invalid address (there should be two elements: "http" and "//the.domain.com") // Create Http sf::Http http; http.setHost(hostInfo[0].ToUTF8() + ":" + hostInfo[1].ToUTF8(), hostInfo.size() > 2 ? hostInfo[2].To<unsigned short>() : 0); // Create request sf::Http::Request request; request.setMethod(method == "POST" ? sf::Http::Request::Post : sf::Http::Request::Get); request.setField("Content-Type", contentType.empty() ? "application/x-www-form-urlencoded" : contentType.ToUTF8()); request.setUri(uri.ToUTF8()); request.setBody(body.ToUTF8()); // Send request & Get response sf::Http::Response response = http.sendRequest(request); if (response.getStatus() == sf::Http::Response::Ok) { responseVar.SetString(gd::String::FromUTF8(response.getBody())); } //else request failed. }
bool InstructionSelectorDialog::MatchSearchCriteria(gd::String search, const gd::InstructionMetadata & instrMetadata) { if (search.empty()) return true; return instrMetadata.GetGroup().FindCaseInsensitive(search) != string::npos || instrMetadata.GetFullName().FindCaseInsensitive(search) != string::npos; }
gd::String InstructionSentenceFormatter::LabelFromType(const gd::String & type) { if ( type.empty() ) return ""; else if ( type == "expression" ) return _("Expression"); else if ( gd::ParameterMetadata::IsObject(type) ) return _("Object"); else if ( type == "behavior" ) return _("Behavior"); else if ( type == "operator" ) return _("Operator"); else if ( type == "relationalOperator" ) return _( "Relational operator" ); else if ( type == "file" ) return _("File"); else if ( type == "key" ) return _( "Key" ); else if ( type == "mouse" ) return _( "Mouse button" ); else if ( type == "yesorno" ) return _("Yes or no"); else if ( type == "police" ) return _("Font"); else if ( type == "color" ) return _("Color"); else if ( type == "trueorfalse" ) return _( "True or False" ); else if ( type == "string" ) return _("String"); else if ( type == "musicfile" ) return _("Music"); else if ( type == "soundfile" ) return _("Sound"); else if ( type == "password" ) return _("Password"); else if ( type == "layer" ) return _("Layer"); else if ( type == "joyaxis" ) return _("Joystick axis"); else if ( type == "objectvar" ) return _("Variable of the object"); else if ( type == "scenevar" ) return _("Scene variable"); else if ( type == "globalvar" ) return _("Global variable"); return _("Unknown"); }
float RuntimeSpriteObject::GetPointY(const gd::String & name) const { if ( !name.empty() ) { const Point & point = GetCurrentSprite().GetPoint(name); return GetCurrentSFMLSprite().getTransform().transformPoint(point.GetX(), point.GetY()).y; } return GetY(); }
bool SerializerElement::HasChild(const gd::String& name, gd::String deprecatedName) const { for (size_t i = 0; i < children.size(); ++i) { if (children[i].second == std::shared_ptr<SerializerElement>()) continue; if (children[i].first == name || (!deprecatedName.empty() && children[i].first == deprecatedName)) return true; } return false; }
std::set < gd::String > EventsVariablesFinder::FindArgumentsInInstructions(const gd::Platform & platform, const gd::Project & project, const gd::Layout & layout, const gd::InstructionsList & instructions, bool instructionsAreConditions, const gd::String & parameterType, const gd::String & objectName) { std::set < gd::String > results; for (std::size_t aId = 0;aId < instructions.size();++aId) { gd::String lastObjectParameter = ""; gd::InstructionMetadata instrInfos = instructionsAreConditions ? MetadataProvider::GetConditionMetadata(platform, instructions[aId].GetType()) : MetadataProvider::GetActionMetadata(platform, instructions[aId].GetType()); for (std::size_t pNb = 0;pNb < instrInfos.parameters.size();++pNb) { //The parameter has the searched type... if ( instrInfos.parameters[pNb].type == parameterType ) { //...remember the value of the parameter. if (objectName.empty() || lastObjectParameter == objectName) results.insert(instructions[aId].GetParameter(pNb).GetPlainString()); } //Search in expressions else if (instrInfos.parameters[pNb].type == "expression") { CallbacksForSearchingVariable callbacks(results, parameterType, objectName); gd::ExpressionParser parser(instructions[aId].GetParameter(pNb).GetPlainString()); parser.ParseMathExpression(platform, project, layout, callbacks); } //Search in gd::String expressions else if (instrInfos.parameters[pNb].type == "string"||instrInfos.parameters[pNb].type == "file" ||instrInfos.parameters[pNb].type == "joyaxis" ||instrInfos.parameters[pNb].type == "color"||instrInfos.parameters[pNb].type == "layer") { CallbacksForSearchingVariable callbacks(results, parameterType, objectName); gd::ExpressionParser parser(instructions[aId].GetParameter(pNb).GetPlainString()); parser.ParseStringExpression(platform, project, layout, callbacks); } //Remember the value of the last "object" parameter. else if (gd::ParameterMetadata::IsObject(instrInfos.parameters[pNb].type)) { lastObjectParameter = instructions[aId].GetParameter(pNb).GetPlainString(); } } if ( !instructions[aId].GetSubInstructions().empty() ) FindArgumentsInInstructions(platform, project, layout, instructions[aId].GetSubInstructions(), instructionsAreConditions, parameterType); } return results; }
int SerializerElement::GetIntAttribute(const gd::String& name, int defaultValue, gd::String deprecatedName) const { if (attributes.find(name) != attributes.end()) return attributes.find(name)->second.GetInt(); else if (!deprecatedName.empty() && attributes.find(deprecatedName) != attributes.end()) return attributes.find(deprecatedName)->second.GetInt(); else { if (HasChild(name, deprecatedName)) { SerializerElement& child = GetChild(name, 0, deprecatedName); if (!child.IsValueUndefined()) return child.GetValue().GetInt(); } } return defaultValue; }
void ParameterControlsHelper::UpdateParameterContent(std::size_t i, const ParameterMetadata & metadata, gd::String content) { if (i >= paramEdits.size()) return; paramMetadata[i] = metadata; if (metadata.IsCodeOnly()) { paramCheckboxes.at(i)->Show(false); paramTexts.at(i)->Show(false); paramBmpBts.at(i)->Show(false); paramEdits.at(i)->Show(false); return; } const gd::String & type = metadata.GetType(); paramCheckboxes.at(i)->Show(metadata.IsOptional()); paramTexts.at(i)->Show(); paramBmpBts.at(i)->Show(!type.empty()); paramEdits.at(i)->Show(); paramCheckboxes.at(i)->SetValue(!paramEdits.at(i)->GetValue().empty()); paramTexts.at(i)->SetLabel(metadata.GetDescription() + _(":")); paramBmpBts.at(i)->SetBitmapLabel(gd::InstructionSentenceFormatter::Get()->BitmapFromType(type)); paramBmpBts.at(i)->SetToolTip(gd::InstructionSentenceFormatter::Get()->LabelFromType(type)); paramEdits.at(i)->SetValue(content); //De/activate widgets if parameter is optional bool disable = metadata.IsOptional() && !paramCheckboxes.at(i)->GetValue() && paramEdits.at(i)->GetValue().empty(); paramCheckboxes.at(i)->SetValue(!disable); paramTexts.at(i)->Enable(!disable); paramBmpBts.at(i)->Enable(!disable); paramEdits.at(i)->Enable(!disable); //Add defaults if (!metadata.IsOptional() && content.empty()) { if (!metadata.GetDefaultValue().empty()) paramEdits.at(i)->SetValue(metadata.GetDefaultValue()); else if ( type == "expression" ) paramEdits.at(i)->SetValue("0"); else if ( type == "string" ) paramEdits.at(i)->SetValue("\"\""); else if ( type == "operator" ) paramEdits.at(i)->SetValue("="); } }
bool SerializerElement::GetBoolAttribute(const gd::String& name, bool defaultValue, gd::String deprecatedName) const { if (attributes.find(name) != attributes.end()) { return attributes.find(name)->second.GetBool(); } else if (!deprecatedName.empty() && attributes.find(deprecatedName) != attributes.end()) { return attributes.find(deprecatedName)->second.GetBool(); } else { if (HasChild(name, deprecatedName)) { SerializerElement& child = GetChild(name, 0, deprecatedName); if (!child.IsValueUndefined()) { return child.GetValue().GetBool(); } } } std::cout << "Bool attribute \"" << name << "\" not found, returning " << defaultValue; return defaultValue; }
virtual bool IsAbsolute(const gd::String & filename) { return !filename.empty() && filename[0] == '/'; }