fix of validate crash and validate dialogues and personnages

This commit is contained in:
Giovanni JOSSERAND
2025-06-21 12:28:21 +02:00
parent 2f1b9b2097
commit 04fcf40798
7 changed files with 80 additions and 146 deletions
+45 -4
View File
@@ -137,7 +137,7 @@ void MainWindow::loadPath(Path* p) {
ui->longitudeSpin->setValue(firstStep.getLongitude());
for(int i = 0; i < firstStep.getTexte().length(); i++) {
QString q = firstStep.getPersonnage().at(i) + ": " + firstStep.getTexte().at(i);
QString q = "[" + firstStep.getPersonnage().at(i) + "] : " + firstStep.getTexte().at(i);
ui->dialogEdit->appendPlainText(q);
}
@@ -602,8 +602,51 @@ void MainWindow::on_validateBtn_clicked()
currentPath->setDuration(ui->durationSpin->value());
currentPath->getStep()[ui->stepNumber->value()-1].setTitle(ui->stepTitle->text());
currentPath->getStep()[ui->stepNumber->value()-1].setResponse(ui->responseSpin->value());
currentPath->getStep()[ui->stepNumber->value()-1].clearPersonnages();
currentPath->getStep()[ui->stepNumber->value()-1].clearTextes();
extractDialogue();
}
void MainWindow::extractDialogue() {
std::string texte = ui->dialogEdit->toPlainText().toStdString();
size_t currentPosition = 0;
while (currentPosition < texte.length()) {
size_t startPersonnage = texte.find('[', currentPosition);
if (startPersonnage == std::string::npos) break;
size_t endPersonnage = texte.find(']', startPersonnage);
if (endPersonnage == std::string::npos) break;
std::string nomPersonnage = texte.substr(startPersonnage + 1, endPersonnage - startPersonnage - 1);
size_t startDialogue = texte.find(':', endPersonnage);
if (startDialogue == std::string::npos) break;
startDialogue += 2;
size_t endDialogue = startDialogue;
while (endDialogue < texte.length()) {
size_t nextNewLine = texte.find('\n', endDialogue);
if (nextNewLine == std::string::npos) {
endDialogue = texte.length();
break;
}
size_t nextPersonnageStart = texte.find('[', nextNewLine);
if (nextPersonnageStart != std::string::npos && nextPersonnageStart < nextNewLine + nomPersonnage.length() + 3) {
endDialogue = nextNewLine;
break;
}
endDialogue = nextNewLine + 1;
}
std::string dialogue = texte.substr(startDialogue, endDialogue - startDialogue);
currentPath->getStep()[ui->stepNumber->value()-1].addPersonnage(QString::fromStdString(nomPersonnage));
currentPath->getStep()[ui->stepNumber->value()-1].addTexte(QString::fromStdString(dialogue));
currentPosition = endDialogue;
}
}
void MainWindow::loadAndExportPaths(QStringList fichiers) {
@@ -897,6 +940,7 @@ void MainWindow::newPath(){
currentPath = p;
path.append(p);
loadPath(p);
p->addStep();
int pathCount = path.length();
ui->pathNumber->setMaximum(pathCount);
@@ -920,6 +964,3 @@ void MainWindow::on_actionFont_color_triggered()
{
this->setColor();
}