mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Merge pull request #3 from 4ian/utf8-gdstring
Support for emscripten + small refactoring/update
This commit is contained in:
@@ -196,6 +196,8 @@ String String::FromLocale( const std::string &localizedString )
|
||||
return FromSfString(sf::String(localizedString)); //Don't need to use the current locale, on Windows, std::locale is always the C locale
|
||||
#elif defined(MACOS)
|
||||
return FromUTF8(localizedString); //Assume UTF8 is the current locale
|
||||
#elif defined(EMSCRIPTEN)
|
||||
return FromUTF8(localizedString); //Assume UTF8 is the current locale
|
||||
#else
|
||||
if(std::locale("").name().find("UTF-8") != std::string::npos)
|
||||
return FromUTF8(localizedString); //UTF8 is already the current locale
|
||||
@@ -243,6 +245,8 @@ std::string String::ToLocale() const
|
||||
return ToSfString().toAnsiString();
|
||||
#elif defined(MACOS)
|
||||
return m_string;
|
||||
#elif defined(EMSCRIPTEN)
|
||||
return m_string;
|
||||
#else
|
||||
if(std::locale("").name().find("UTF-8") != std::string::npos)
|
||||
return m_string; //UTF8 is already the current locale on Linux
|
||||
|
@@ -16,39 +16,25 @@ namespace GDpriv
|
||||
void CompilerMessagesParser::ParseOutput(gd::String rawOutput)
|
||||
{
|
||||
parsedMessages.clear();
|
||||
std::vector<std::string> output = SplitString<std::string>(rawOutput.ToUTF8(), '\n');
|
||||
std::vector<gd::String> output = rawOutput.Split(U'\n');
|
||||
|
||||
for (unsigned int i = 0;i<output.size();++i)
|
||||
{
|
||||
CompilerMessage newMessage;
|
||||
std::vector<gd::String> columns = output[i].Split(U':');
|
||||
|
||||
//Parse file
|
||||
size_t fileEndPos = output[i].find_first_of(':', 2);
|
||||
if ( fileEndPos != gd::String::npos ) newMessage.file = gd::String::FromUTF8(output[i].substr(0, fileEndPos));
|
||||
|
||||
//Get line
|
||||
size_t lineEndPos = gd::String::npos;
|
||||
if ( output[i].length()>fileEndPos && isdigit(output[i][fileEndPos+1]) )
|
||||
if (columns.size() >= 3)
|
||||
{
|
||||
lineEndPos = output[i].find_first_of(':', fileEndPos+1);
|
||||
if ( lineEndPos != gd::String::npos ) newMessage.line = ToInt(output[i].substr(fileEndPos+1, lineEndPos));
|
||||
newMessage.file = columns[0];
|
||||
newMessage.line = columns[1].ToInt();
|
||||
newMessage.column = columns[2].ToInt();
|
||||
}
|
||||
if (!columns.empty()) newMessage.message = columns.back();
|
||||
|
||||
//Get column
|
||||
size_t colEndPos = gd::String::npos;
|
||||
if ( output[i].length()>lineEndPos && isdigit(output[i][lineEndPos+1]) )
|
||||
{
|
||||
colEndPos = output[i].find_first_of(':', lineEndPos+1);
|
||||
if ( colEndPos != gd::String::npos ) newMessage.column = ToInt(output[i].substr(lineEndPos+1, colEndPos));
|
||||
}
|
||||
|
||||
if ( fileEndPos < output[i].length() )
|
||||
newMessage.message = gd::String::FromUTF8(output[i].substr(colEndPos != gd::String::npos ? colEndPos+1 : fileEndPos, output[i].length()));
|
||||
if ( output[i].find("error") < output[i].length() )
|
||||
newMessage.messageType = CompilerMessage::error;
|
||||
else
|
||||
newMessage.message = gd::String::FromUTF8(output[i]);
|
||||
|
||||
if ( output[i].find("error") < output[i].length() ) newMessage.messageType = CompilerMessage::error;
|
||||
else newMessage.messageType = CompilerMessage::simple;
|
||||
newMessage.messageType = CompilerMessage::simple;
|
||||
|
||||
parsedMessages.push_back(newMessage);
|
||||
}
|
||||
|
@@ -72,9 +72,9 @@ gd::String EventsCodeGenerator::GenerateSceneEventsCompleteCode(gd::Project & pr
|
||||
for (unsigned int j = 1;j<=maxDepth;++j)
|
||||
{
|
||||
globalObjectLists += codeGenerator.GetCodeNamespace()
|
||||
+ManObjListName(object.GetName())+gd::ToString(j) + "= [];\n";
|
||||
+ ManObjListName(object.GetName()) + gd::String::FromUInt(j) + "= [];\n";
|
||||
globalObjectListsReset += codeGenerator.GetCodeNamespace()
|
||||
+ManObjListName(object.GetName())+gd::ToString(j) + ".length = 0;\n";
|
||||
+ ManObjListName(object.GetName()) + gd::String::FromUInt(j) + ".length = 0;\n";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -93,7 +93,7 @@ gd::String EventsCodeGenerator::GenerateSceneEventsCompleteCode(gd::Project & pr
|
||||
globalConditionsBooleans += codeGenerator.GetCodeNamespace()+"conditionTrue_"+gd::String::FromUInt(i)+" = {val:false};\n";
|
||||
for (unsigned int j = 0;j<=codeGenerator.GetMaxConditionsListsSize();++j)
|
||||
{
|
||||
globalConditionsBooleans += codeGenerator.GetCodeNamespace()+"condition"+gd::ToString(j)+"IsTrue_"+gd::String::FromUInt(i)+" = {val:false};\n";
|
||||
globalConditionsBooleans += codeGenerator.GetCodeNamespace()+"condition"+gd::String::FromUInt(j)+"IsTrue_"+gd::String::FromUInt(i)+" = {val:false};\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,7 +379,8 @@ gd::String EventsCodeGenerator::GenerateAutomatismAction(const gd::String & obje
|
||||
|
||||
gd::String EventsCodeGenerator::GetObjectListName(const gd::String & name, const gd::EventsCodeGenerationContext & context)
|
||||
{
|
||||
return GetCodeNamespace()+ManObjListName(name)+gd::ToString(context.GetLastDepthObjectListWasNeeded(name));
|
||||
return GetCodeNamespace() + ManObjListName(name)
|
||||
+ gd::String::FromUInt(context.GetLastDepthObjectListWasNeeded(name));
|
||||
}
|
||||
|
||||
gd::String EventsCodeGenerator::GenerateObjectsDeclarationCode(gd::EventsCodeGenerationContext & context)
|
||||
@@ -573,7 +574,8 @@ gd::String EventsCodeGenerator::GenerateBooleanInitializationToFalse(const gd::S
|
||||
|
||||
gd::String EventsCodeGenerator::GenerateBooleanFullName(const gd::String & boolName, const gd::EventsCodeGenerationContext & context )
|
||||
{
|
||||
return GetCodeNamespace()+boolName+"_"+gd::ToString(context.GetCurrentConditionDepth());
|
||||
return GetCodeNamespace() + boolName + "_"
|
||||
+ gd::String::FromUInt(context.GetCurrentConditionDepth());
|
||||
}
|
||||
|
||||
gd::String EventsCodeGenerator::GetCodeNamespace()
|
||||
|
@@ -337,16 +337,18 @@ bool Exporter::ExportEventsCode(gd::Project & project, gd::String outputDir, std
|
||||
gd::Layout & exportedLayout = project.GetLayout(i);
|
||||
gd::String eventsOutput = EventsCodeGenerator::GenerateSceneEventsCompleteCode(project, exportedLayout,
|
||||
exportedLayout.GetEvents(), eventsIncludes, false /*Export for edittime*/);
|
||||
gd::String filename = outputDir+"code"+gd::String::FromUInt(i)+".js";
|
||||
|
||||
//Export the code
|
||||
if (fs.WriteToFile(outputDir+"code"+gd::ToString(i)+".js", eventsOutput))
|
||||
if (fs.WriteToFile(filename, eventsOutput))
|
||||
{
|
||||
for ( std::set<gd::String>::iterator include = eventsIncludes.begin() ; include != eventsIncludes.end(); ++include )
|
||||
InsertUnique(includesFiles, *include);
|
||||
|
||||
InsertUnique(includesFiles, gd::String(outputDir+"code"+gd::ToString(i)+".js"));
|
||||
InsertUnique(includesFiles, filename);
|
||||
}
|
||||
else {
|
||||
lastError = _("Unable to write ")+outputDir+"code"+gd::ToString(i)+".js";
|
||||
lastError = _("Unable to write ") + filename;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -88,7 +88,7 @@ void VariableCodeGenerationCallbacks::OnRootVariable(gd::String variableName)
|
||||
unsigned int index = variables->GetPosition(variableName);
|
||||
if ( index < variables->Count() )
|
||||
{
|
||||
output += ".getFromIndex("+gd::ToString(index)+")";
|
||||
output += ".getFromIndex(" + gd::String::FromUInt(index) + ")";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -100,7 +100,7 @@ void BuildMessagesPnl::OpenFileContainingFirstError()
|
||||
row_info.m_mask = wxLIST_MASK_TEXT;
|
||||
|
||||
messagesList->GetItem( row_info );
|
||||
size_t line = row_info.m_text.empty() ? gd::String::npos : ToInt(string(row_info.m_text.mb_str()));
|
||||
size_t line = row_info.m_text.empty() ? gd::String::npos : gd::String(row_info.m_text).ToInt();
|
||||
gd::String file = messagesList->GetItemText(0);
|
||||
|
||||
if ( projectManager && wxFileExists(file) ) projectManager->EditSourceFile(gameAssociatedWithErrors, file, line);
|
||||
@@ -115,7 +115,7 @@ void BuildMessagesPnl::OnmessagesListItemActivated(wxListEvent& event)
|
||||
row_info.m_mask = wxLIST_MASK_TEXT;
|
||||
|
||||
messagesList->GetItem( row_info );
|
||||
size_t line = row_info.m_text.empty() ? gd::String::npos : ToInt(string(row_info.m_text.mb_str()));
|
||||
size_t line = row_info.m_text.empty() ? gd::String::npos : gd::String(row_info.m_text).ToInt();
|
||||
gd::String file = messagesList->GetItemText(event.GetIndex());
|
||||
|
||||
if ( projectManager && wxFileExists(file) ) projectManager->EditSourceFile(gameAssociatedWithErrors, file, line);
|
||||
|
@@ -470,38 +470,38 @@ void ImportImage::OnDecomposeSSBtClick(wxCommandEvent& event)
|
||||
wxFileName filename(fileSSEdit->GetValue());
|
||||
wxString path = filename.GetPath();
|
||||
|
||||
int lineNb = ToInt(static_cast<string>(linesSSEdit->GetValue()));
|
||||
int lineNb = gd::String(linesSSEdit->GetValue()).ToInt();
|
||||
if ( lineNb <= 0 )
|
||||
{
|
||||
gd::LogWarning(_("The number of lines is invalid: The minimum is one line."));
|
||||
return;
|
||||
}
|
||||
|
||||
int columnNb = ToInt(static_cast<string>(columnsSSEdit->GetValue()));
|
||||
int columnNb = gd::String(columnsSSEdit->GetValue()).ToInt();
|
||||
if ( columnNb <= 0 )
|
||||
{
|
||||
gd::LogWarning(_("The number of columns is invalid: The minimum is one column."));
|
||||
return;
|
||||
}
|
||||
|
||||
int origineX = ToInt(static_cast<string>(origineXEdit->GetValue()));
|
||||
int origineY = ToInt(static_cast<string>(origineYEdit->GetValue()));
|
||||
int origineX = gd::String(origineXEdit->GetValue()).ToInt();
|
||||
int origineY = gd::String(origineYEdit->GetValue()).ToInt();
|
||||
|
||||
int width = ToInt(static_cast<string>(widthSSEdit->GetValue()));
|
||||
int height = ToInt(static_cast<string>(heightSSEdit->GetValue()));
|
||||
int width = gd::String(widthSSEdit->GetValue()).ToInt();
|
||||
int height = gd::String(heightSSEdit->GetValue()).ToInt();
|
||||
if ( width <= 0 || height <= 0)
|
||||
{
|
||||
gd::LogWarning(_("The size of a sprite is invalid."));
|
||||
return;
|
||||
}
|
||||
|
||||
int spaceH = ToInt(static_cast<string>(spaceHSSEdit->GetValue()));
|
||||
int spaceH = gd::String(spaceHSSEdit->GetValue()).ToInt();
|
||||
if ( spaceH < 0 )
|
||||
{
|
||||
gd::LogWarning(_("The horizontal spacing is invalid (must be greater than or equal to 0)."));
|
||||
return;
|
||||
}
|
||||
int spaceV = ToInt(static_cast<string>(spaceVSSEdit->GetValue()));
|
||||
int spaceV = gd::String(spaceVSSEdit->GetValue()).ToInt();
|
||||
if ( spaceV < 0 )
|
||||
{
|
||||
gd::LogWarning(_("The vertical spacing is invalid (must be greater than or equal to 0)."));
|
||||
|
@@ -1087,7 +1087,7 @@ void Preferences::OnOkBtClick( wxCommandEvent& event )
|
||||
}
|
||||
|
||||
gd::InstructionSentenceFormatter::Get()->SaveTypesFormattingToConfig();
|
||||
pConfig->Write("EventsEditor/ConditionColumnWidth", ToInt(gd::ToString(conditionsColumnWidthEdit->GetValue())));
|
||||
pConfig->Write("EventsEditor/ConditionColumnWidth", gd::String(conditionsColumnWidthEdit->GetValue()).ToInt());
|
||||
pConfig->Write("EventsEditor/HideContextPanelsLabels", hideContextPanelsLabels->GetValue());
|
||||
pConfig->Write("EventsEditor/Font", eventsEditorFontDialog->GetFontData().GetChosenFont());
|
||||
|
||||
|
Reference in New Issue
Block a user