From 04fcf40798107f4c4e07c3810394ec6fb8fd543d Mon Sep 17 00:00:00 2001 From: Giovanni JOSSERAND Date: Sat, 21 Jun 2025 12:28:21 +0200 Subject: [PATCH] fix of validate crash and validate dialogues and personnages --- index.html | 3 +- mainwindow.cpp | 49 +++++++++++++++-- mainwindow.h | 1 + pages/parcours0.html | 29 +++++----- pages/parcours1.html | 124 ------------------------------------------- step.cpp | 16 ++++++ step.h | 4 ++ 7 files changed, 80 insertions(+), 146 deletions(-) delete mode 100644 pages/parcours1.html diff --git a/index.html b/index.html index 376df10..733d2f7 100644 --- a/index.html +++ b/index.html @@ -46,8 +46,7 @@

Liste des parcours

diff --git a/mainwindow.cpp b/mainwindow.cpp index f5d94f2..5eea6e6 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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(); } - - - diff --git a/mainwindow.h b/mainwindow.h index 8090e39..f7c92a3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -51,6 +51,7 @@ public: void setFont(); void saveFile(); void newPath(); + void extractDialogue(); private slots: void on_pushButton_clicked(); diff --git a/pages/parcours0.html b/pages/parcours0.html index 7f4959a..33bbe7c 100644 --- a/pages/parcours0.html +++ b/pages/parcours0.html @@ -74,26 +74,22 @@
-

parcous123

-

Ville : Bourg en bresse

+

+

Ville :

Département : 0

-

Difficulté : 2

-

Durée (heures) : 2.3

-

Longueur (km) : 17.3

- +

Difficulté : 5

+

Durée (heures) : 0

+

Longueur (km) : 0

+

Étape 1

Personnages :

-
  • Quentin
  • +
    • Gio
    • +
    • 4

    Dialogues :

    -
    • ok c'est cool
    • -
    -

    Étape 2

    -

    Personnages :

    -
    • Quentin
    • -
    -

    Dialogues :

    -
    • ok c'est cool
    • +
      • zhfzui
      • +
      • lkzopk ,k op j j, i + jiojijfiozjop
@@ -106,7 +102,8 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }).addTo(map); -L.marker([0, 0]).addTo(map).bindPopup("Étape 1
"); +L.marker([0, 0]).addTo(map).bindPopup("Étape 1
Personnages :Textes :"); var latlngs = [ [0, 0], ]; diff --git a/pages/parcours1.html b/pages/parcours1.html deleted file mode 100644 index 7f4959a..0000000 --- a/pages/parcours1.html +++ /dev/null @@ -1,124 +0,0 @@ - - - - - Carte du parcours - - - - - -

Fiche du parcours

-
-
-
-

parcous123

-

Ville : Bourg en bresse

-

Département : 0

-

Difficulté : 2

-

Durée (heures) : 2.3

-

Longueur (km) : 17.3

- -

Étape 1

-

Personnages :

-
  • Quentin
  • -
-

Dialogues :

-
  • ok c'est cool
  • -
-

Étape 2

-

Personnages :

-
  • Quentin
  • -
-

Dialogues :

-
  • ok c'est cool
  • -
- -
-
- - - - - diff --git a/step.cpp b/step.cpp index 419f676..18c87b5 100644 --- a/step.cpp +++ b/step.cpp @@ -37,6 +37,22 @@ QList Step::getTexte() const return texte; } +void Step::addPersonnage(const QString& pers) { + personnage.append(pers); +} + +void Step::addTexte(const QString& txt) { + texte.append(txt); +} + +void Step::clearPersonnages() { + personnage.clear(); +} + +void Step::clearTextes() { + texte.clear(); +} + void Step::setTitle(const QString &newTitle) { title = newTitle; diff --git a/step.h b/step.h index eb2bc9e..6746ed9 100644 --- a/step.h +++ b/step.h @@ -33,6 +33,10 @@ public: void setPersonnage(const QList &newPersonnage); void setTexte(const QList &newTexte); QString toGPSFormat(); + void addPersonnage(const QString& pers) ; + void addTexte(const QString& txt); + void clearPersonnages(); + void clearTextes(); }; #endif // STEP_H