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

View File

@ -46,8 +46,7 @@
<body>
<h1>Liste des parcours</h1>
<ul>
<li><a href="./pages/parcours0.html">azea</a></li>
<li><a href="./pages/parcours1.html">parcous123</a></li>
<li><a href="./pages/parcours0.html"></a></li>
</ul>
</body>
</html>

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();
}

View File

@ -51,6 +51,7 @@ public:
void setFont();
void saveFile();
void newPath();
void extractDialogue();
private slots:
void on_pushButton_clicked();

View File

@ -74,26 +74,22 @@
<div id="container">
<div id="map"></div>
<div id="fiche">
<h2>parcous123</h2>
<p><strong>Ville :</strong> Bourg en bresse</p>
<h2></h2>
<p><strong>Ville :</strong> </p>
<p><strong>Département :</strong> 0</p>
<p><strong>Difficulté :</strong> 2</p>
<p><strong>Durée (heures) :</strong> 2.3</p>
<p><strong>Longueur (km) :</strong> 17.3</p>
<img src="data/parcours1.png">
<p><strong>Difficulté :</strong> 5</p>
<p><strong>Durée (heures) :</strong> 0</p>
<p><strong>Longueur (km) :</strong> 0</p>
<img src="data/images/logo.png">
<h3>Étape 1</h3>
<p><strong>Personnages :</strong></p>
<ul><li>Quentin</li>
<ul><li>Gio</li>
<li>4</li>
</ul>
<p><strong>Dialogues :</strong></p>
<ul><li>ok c'est cool</li>
</ul>
<h3>Étape 2</h3>
<p><strong>Personnages :</strong></p>
<ul><li>Quentin</li>
</ul>
<p><strong>Dialogues :</strong></p>
<ul><li>ok c'est cool</li>
<ul><li>zhfzui</li>
<li>lkzopk ,k op j j, i
jiojijfiozjop</li>
</ul>
</div>
@ -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("<b>Étape 1</b><br>");
L.marker([0, 0]).addTo(map).bindPopup("<b>Étape 1</b><br><b>Personnages :</b><ul><li>Gio</li><li>4</li></ul><b>Textes :</b><ul><li>zhfzui</li><li>lkzopk ,k op j j, i
jiojijfiozjop</li></ul>");
var latlngs = [
[0, 0],
];

View File

@ -1,124 +0,0 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Carte du parcours</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: whitesmoke;
}
#container {
display: flex;
gap: 20px;
}
#map {
height: 600px;
width: 60%;
border-radius: 5%;
border: 1px solid #aaa;
}
#fiche {
padding-right:20px;
width: 40%;
max-height: 600px;
overflow-y: auto;
border: 1px solid #aaa;
padding: 10px;
box-sizing: border-box;
background-color:#095228;
border-radius: 5%;
}
#fiche ul {
padding-left: 20px;
list-style-type: disc;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
white-space: normal;
max-width: 90%;
}
#fiche li {
white-space: normal;
overflow-wrap: break-word;
}
body h1 {
display:flex;
align-items:center;
justify-content:center;
text-align: center;
color: black;
font-style: bold;
margin-bottom: 20px;
background-color:brown;
border-radius:12px;
height: 75px;
}
#fiche h2, #fiche h3, #fiche p, #fiche li {
color: white;
}
#fiche img {
max-width: 100%;
height: auto;
margin-top: 10px;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>Fiche du parcours</h1>
<div id="container">
<div id="map"></div>
<div id="fiche">
<h2>parcous123</h2>
<p><strong>Ville :</strong> Bourg en bresse</p>
<p><strong>Département :</strong> 0</p>
<p><strong>Difficulté :</strong> 2</p>
<p><strong>Durée (heures) :</strong> 2.3</p>
<p><strong>Longueur (km) :</strong> 17.3</p>
<img src="data/parcours1.png">
<h3>Étape 1</h3>
<p><strong>Personnages :</strong></p>
<ul><li>Quentin</li>
</ul>
<p><strong>Dialogues :</strong></p>
<ul><li>ok c'est cool</li>
</ul>
<h3>Étape 2</h3>
<p><strong>Personnages :</strong></p>
<ul><li>Quentin</li>
</ul>
<p><strong>Dialogues :</strong></p>
<ul><li>ok c'est cool</li>
</ul>
</div>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
var map = L.map('map').setView([45.5, 1.5], 10); // Vue centrée
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
L.marker([0, 0]).addTo(map).bindPopup("<b>Étape 1</b><br>");
var latlngs = [
[0, 0],
];
var polyline = L.polyline(latlngs, {
color: 'purple',
weight: 2,
dashArray: '10, 10',
opacity: 0.7
}).addTo(map);
map.fitBounds(polyline.getBounds());
</script>
</body>
</html>

View File

@ -37,6 +37,22 @@ QList<QString> 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;

4
step.h
View File

@ -33,6 +33,10 @@ public:
void setPersonnage(const QList<QString> &newPersonnage);
void setTexte(const QList<QString> &newTexte);
QString toGPSFormat();
void addPersonnage(const QString& pers) ;
void addTexte(const QString& txt);
void clearPersonnages();
void clearTextes();
};
#endif // STEP_H