Simplifie les événements : notification pure, sans paramètre
Retour de l'utilisateur sur le premier jet : "Déclencher un événement" ne doit JAMAIS faire choisir un élément — c'est une notification pure, rien de plus. C'est à l'ÉCOUTEUR (déclencheur "Sur un événement personnalisé" → condition → action) de décider quoi faire ensuite, avec ses réglages habituels (cible fixe, "Ligne cliquée"...), jamais à l'événement de transporter un paramètre. Retire donc tout le mécanisme de transmission ajouté au tour précédent (has_element_param, target_element_from_event, EVENT_ROW_ID, window.lastEventParams) : - db/custom_events/ : _custom_events perd sa colonne has_element_param — un événement n'est plus qu'un nom + une description. - screens/flow/ : retire target_element_from_event (colonne ajoutée par ALTER TABLE, laissée inerte sur les bases déjà migrées — sans conséquence, plus jamais lue ni écrite) et la constante EVENT_ROW_ID. - routes/flow/flow_node_run_data.py : retire la résolution EVENT_ROW_ID, revient à sa forme d'origine (seul CLICKED_ROW_ID reste géré). - templates/screen_edit.html : le nœud Action "Déclencher un événement" n'a plus qu'un sélecteur d'événement — plus de champs élément/ligne. Le nœud Action "Modifier un élément" perd la case "Utiliser l'élément transmis par l'événement en cours". L'onglet Événements perd la case à cocher "Paramètre" (création et édition). - templates/play.html : window.dispatchGameEvent(eventId) ne prend plus que l'id de l'événement — scan global inchangé, mais ne pose plus aucun window.lastEventParams. modifier_element et readFieldValue reviennent à leur résolution d'origine (plus de branche event-aware). 208 tests au total (2 tests retirés, devenus sans objet : la persistance de target_element_from_event et la résolution serveur d'EVENT_ROW_ID). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
666aa892e0
commit
2c59e54556
+19
-64
@@ -788,46 +788,16 @@
|
||||
bindHoverTexts();
|
||||
bindHoverTriggers();
|
||||
return Promise.resolve();
|
||||
} else if (node.action_type === 'modifier_element' && (node.target_element_id || node.target_element_from_event)) {
|
||||
// target_element_from_event (voir screens/custom_events/) : résout
|
||||
// dynamiquement "l'élément transmis par l'événement en cours"
|
||||
// (window.lastEventParams, posé par dispatchGameEvent() juste avant
|
||||
// d'exécuter ce graphe) plutôt qu'une cible fixe choisie dans
|
||||
// l'éditeur — contourne la contrainte de clé étrangère de
|
||||
// target_element_id, qui empêche d'y stocker un sentinel comme
|
||||
// EVENT_ROW_ID directement (voir screens/flow/ensure_flow_schema.py).
|
||||
//
|
||||
// data-element-id N'EST PAS unique quand l'élément vit dans un
|
||||
// Répéteur : chaque ligne rejoue le MÊME modèle, donc le MÊME
|
||||
// data-element-id se répète à l'identique sur chaque ligne (voir
|
||||
// render_repeater.py, seul data-row-id — posé sur .repeaterItem,
|
||||
// l'englobant — distingue réellement une ligne d'une autre). Un
|
||||
// simple document.querySelector('[data-element-id]') global
|
||||
// prendrait toujours la PREMIÈRE ligne, jamais la bonne — sans
|
||||
// rapport avec l'événement reçu. Quand l'événement transmet aussi
|
||||
// une ligne (row_id), la recherche est donc scopée à L'INTÉRIEUR de
|
||||
// ce .repeaterItem précis ; sinon (élément fixe, ou événement sans
|
||||
// paramètre de ligne), recherche globale comme avant.
|
||||
const resolvedElementId = node.target_element_from_event
|
||||
? (window.lastEventParams ? window.lastEventParams.element_id : null)
|
||||
: node.target_element_id;
|
||||
const resolvedRowId = node.target_element_from_event && window.lastEventParams
|
||||
? window.lastEventParams.row_id : null;
|
||||
let targetEl = null;
|
||||
if (resolvedElementId != null) {
|
||||
if (resolvedRowId != null) {
|
||||
const rowEl = document.querySelector('.repeaterItem[data-row-id="' + resolvedRowId + '"]');
|
||||
targetEl = rowEl ? rowEl.querySelector('[data-element-id="' + resolvedElementId + '"]') : null;
|
||||
} else {
|
||||
targetEl = document.querySelector('[data-element-id="' + resolvedElementId + '"]');
|
||||
}
|
||||
}
|
||||
} else if (node.action_type === 'modifier_element' && node.target_element_id) {
|
||||
const targetEl = document.querySelector('[data-element-id="' + node.target_element_id + '"]');
|
||||
if (targetEl) applyElementProperty(targetEl, node.element_property, node.element_value);
|
||||
return Promise.resolve();
|
||||
} else if (node.action_type === 'declencher_evenement' && node.target_custom_event_id) {
|
||||
let dispatchRowId = node.target_row_id;
|
||||
if (dispatchRowId === -1) dispatchRowId = window.lastClickedRowId; // CLICKED_ROW_ID
|
||||
window.dispatchGameEvent(node.target_custom_event_id, node.target_element_id || null, dispatchRowId != null ? dispatchRowId : null);
|
||||
// Notification pure (voir screens/custom_events/) : ne fait que
|
||||
// signaler l'événement, jamais choisir un élément — c'est à
|
||||
// l'écouteur (déclencheur → condition → action) de décider quoi
|
||||
// faire, avec ses propres réglages habituels.
|
||||
window.dispatchGameEvent(node.target_custom_event_id);
|
||||
return Promise.resolve();
|
||||
} else if (node.action_type === 'activer_onglet' && node.target_element_id) {
|
||||
// 2.3 — panneau à onglets / visibilité mutuellement exclusive : montre
|
||||
@@ -864,16 +834,12 @@
|
||||
return new Promise(function(resolve) { setTimeout(resolve, ms); });
|
||||
} else if (node.action_type === 'modifier_donnee') {
|
||||
const runDataUrl = "{{ url_for('flow_node_run_data', slug=game.slug, node_id=999999) }}".replace('999999', node.id);
|
||||
// clicked_row_id/event_row_id : utilisés côté serveur SEULEMENT si ce
|
||||
// nœud vise respectivement CLICKED_ROW_ID ou EVENT_ROW_ID (voir
|
||||
// flow_node_run_data.py) — sans effet sinon, donc toujours transmis
|
||||
// sans condition ici.
|
||||
// clicked_row_id : utilisé côté serveur SEULEMENT si ce nœud vise la
|
||||
// ligne cliquée (CLICKED_ROW_ID, voir flow_node_run_data.py) — sans
|
||||
// effet sinon, donc toujours transmis sans condition ici.
|
||||
return fetch(runDataUrl, {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
clicked_row_id: window.lastClickedRowId,
|
||||
event_row_id: window.lastEventParams ? window.lastEventParams.row_id : null,
|
||||
})
|
||||
body: JSON.stringify({ clicked_row_id: window.lastClickedRowId })
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(() => refreshRuntimeData());
|
||||
@@ -896,12 +862,6 @@
|
||||
// résolue seulement au moment de l'évaluation via le dernier clic
|
||||
// capturé (voir bindClicks() plus haut).
|
||||
if (rowId === -1) rowId = window.lastClickedRowId;
|
||||
// EVENT_ROW_ID (-2, voir screens/flow/constants.py) : "la ligne de
|
||||
// Répéteur transmise par l'événement personnalisé en cours" — même
|
||||
// principe que CLICKED_ROW_ID ci-dessus, résolue via
|
||||
// window.lastEventParams (posé par dispatchGameEvent()) plutôt que le
|
||||
// dernier clic capturé.
|
||||
if (rowId === -2) rowId = window.lastEventParams ? window.lastEventParams.row_id : null;
|
||||
const rows = gameData.data[String(definitionId)] || [];
|
||||
const row = rows.find(r => r.id === rowId);
|
||||
return row ? row[fieldName] : undefined;
|
||||
@@ -1056,25 +1016,20 @@
|
||||
}
|
||||
|
||||
// Déclenche un événement personnalisé (voir screens/custom_events/,
|
||||
// action "declencher_evenement") : scan GLOBAL de gameData.flows, même
|
||||
// principe que findTriggerNode()/runScreenShowTriggers() ci-dessus — un
|
||||
// action "declencher_evenement") : une pure NOTIFICATION, sans aucun
|
||||
// paramètre — scan GLOBAL de gameData.flows, même principe que
|
||||
// findTriggerNode()/runScreenShowTriggers() ci-dessus, puisqu'un
|
||||
// écouteur (nœud Déclencheur trigger_event="evenement") peut vivre sur
|
||||
// N'IMPORTE QUELLE autre scène ou modèle, pas seulement l'écran affiché.
|
||||
// elementId/rowId (potentiellement null si l'événement n'a pas de
|
||||
// paramètre) sont posés sur window.lastEventParams AVANT de lancer
|
||||
// chaque graphe trouvé, pour que les nœuds en aval (ex. "Modifier un
|
||||
// élément" avec target_element_from_event, voir applyElementProperty
|
||||
// plus haut/runActionNode plus bas) puissent le résoudre — au même
|
||||
// titre que window.lastClickedRowId pour "Ligne cliquée (Répéteur)".
|
||||
window.dispatchGameEvent = function(eventId, elementId, rowId) {
|
||||
// C'est à CHAQUE écouteur de décider quoi faire ensuite (via sa propre
|
||||
// suite condition/action, avec ses réglages habituels — cible fixe,
|
||||
// "Ligne cliquée"...), jamais à l'événement lui-même de le dicter.
|
||||
window.dispatchGameEvent = function(eventId) {
|
||||
for (const screenIdKey in gameData.flows) {
|
||||
const flow = gameData.flows[screenIdKey];
|
||||
flow.nodes
|
||||
.filter(function(n){ return n.node_type === 'trigger' && n.trigger_event === 'evenement' && n.trigger_custom_event_id === eventId; })
|
||||
.forEach(function(n) {
|
||||
window.lastEventParams = { element_id: elementId, row_id: rowId };
|
||||
runFlowFrom(n.id, screenIdKey);
|
||||
});
|
||||
.forEach(function(n) { runFlowFrom(n.id, screenIdKey); });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+18
-84
@@ -297,10 +297,6 @@
|
||||
</select>
|
||||
|
||||
<div id="nf-action-element-fields" style="display:none;">
|
||||
<label id="nf-action-event-param-row" style="display:none; align-items:center; gap:6px; margin-bottom:6px;">
|
||||
<input type="checkbox" id="nf-action-element-from-event" style="width:auto;" onchange="toggleFlowActionElementFromEvent()">
|
||||
Utiliser l'élément transmis par l'événement en cours (nœud "Sur un événement personnalisé")
|
||||
</label>
|
||||
<select id="nf-action-target-element">
|
||||
{% for e2 in elements %}
|
||||
<option value="{{ e2.id }}">{{ e2|elabel }} (elt-{{ e2.id }})</option>
|
||||
@@ -391,24 +387,16 @@
|
||||
{% if not custom_events %}
|
||||
<p class="hint">Aucun événement pour l'instant — <a href="javascript:void(0)" onclick="switchBuilderTab('events'); return false;">crées-en un dans l'onglet Événements</a>.</p>
|
||||
{% else %}
|
||||
<select id="nf-action-custom-event" onchange="toggleFlowEventDispatchFields()">
|
||||
<!-- Déclencher un événement = notifier, rien d'autre : aucun
|
||||
élément/ligne à choisir ici, c'est à l'ÉCOUTEUR (nœud
|
||||
Déclencheur "Sur un événement personnalisé", plus bas dans
|
||||
son propre graphe) de décider quoi faire, avec ses propres
|
||||
réglages habituels — voir screens/custom_events/. -->
|
||||
<select id="nf-action-custom-event">
|
||||
{% for ev in custom_events %}
|
||||
<option value="{{ ev.id }}">{{ ev.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div id="nf-action-event-param-fields" style="margin-top:6px;">
|
||||
<label>Élément concerné<select id="nf-action-event-element">
|
||||
{% for e2 in elements %}
|
||||
<option value="{{ e2.id }}">{{ e2|elabel }} (elt-{{ e2.id }})</option>
|
||||
{% endfor %}
|
||||
</select></label>
|
||||
<label style="margin-top:6px;">Ligne concernée (si l'élément vient d'un Répéteur)
|
||||
<select id="nf-action-event-row">
|
||||
<option value="">Ne s'applique pas</option>
|
||||
<option value="-1">🖱️ Ligne cliquée (Répéteur)</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -526,10 +514,6 @@
|
||||
<input type="hidden" name="screen_id" value="{{ screen.id }}">
|
||||
<input type="text" name="name" placeholder="NOM (ex. NEED_ACTION)" required autocomplete="off">
|
||||
<input type="text" name="description" placeholder="Description (optionnel)">
|
||||
<label style="display:flex; align-items:center; gap:6px; white-space:nowrap; font-size:12.5px;">
|
||||
<input type="checkbox" name="has_element_param" style="width:auto;">
|
||||
Paramètre : élément (+ ligne de Répéteur)
|
||||
</label>
|
||||
<button type="submit" class="primary">Créer</button>
|
||||
</form>
|
||||
|
||||
@@ -541,18 +525,12 @@
|
||||
{% endfor %}
|
||||
<div class="fieldsTableWrap">
|
||||
<table class="table is-fullwidth is-hoverable fieldsTable">
|
||||
<thead><tr><th>Nom</th><th>Description</th><th>Paramètre</th><th>Utilisé par</th><th></th></tr></thead>
|
||||
<thead><tr><th>Nom</th><th>Description</th><th>Utilisé par</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{% for ev in custom_events %}
|
||||
<tr>
|
||||
<td><code>{{ ev.name }}</code></td>
|
||||
<td><input type="text" form="eventEditForm{{ ev.id }}" name="description" value="{{ ev.description or '' }}" placeholder="Description" aria-label="Description de « {{ ev.name }} »"></td>
|
||||
<td>
|
||||
<label style="display:flex; align-items:center; gap:4px; white-space:nowrap;">
|
||||
<input type="checkbox" form="eventEditForm{{ ev.id }}" name="has_element_param" style="width:auto;" {{ 'checked' if ev.has_element_param else '' }}>
|
||||
élément
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
{% set usages = custom_event_usages.get(ev.id, []) %}
|
||||
{% if usages %}
|
||||
@@ -2241,8 +2219,7 @@ function nodeLabel(node) {
|
||||
} else if (node.action_type === 'activer_onglet') {
|
||||
base += ' → ' + (ELEMENTS_LABELS[node.target_element_id] || '?') + ' (masque ses frères)';
|
||||
} else if (node.action_type === 'modifier_element') {
|
||||
var elementLabel = node.target_element_from_event ? "l'élément transmis par l'événement" : (ELEMENTS_LABELS[node.target_element_id] || '?');
|
||||
base += ' → ' + elementLabel + ' : ' + (ELEMENT_PROPERTY_LABELS_MAP[node.element_property] || node.element_property);
|
||||
base += ' → ' + (ELEMENTS_LABELS[node.target_element_id] || '?') + ' : ' + (ELEMENT_PROPERTY_LABELS_MAP[node.element_property] || node.element_property);
|
||||
if (node.element_property === 'visibilite') {
|
||||
base += ' = ' + (ELEMENT_VISIBILITY_LABELS_MAP[node.element_value] || node.element_value);
|
||||
} else if (node.element_property === 'surbrillance') {
|
||||
@@ -2264,11 +2241,11 @@ function nodeLabel(node) {
|
||||
} else if (node.action_type === 'attendre') {
|
||||
base += ' (' + (node.data_value || '0') + ' s)';
|
||||
} else if (node.action_type === 'declencher_evenement') {
|
||||
// Notification pure : rien d'autre à afficher que le nom de
|
||||
// l'événement (voir screens/custom_events/) — aucun élément/ligne
|
||||
// n'est jamais transmis au déclenchement.
|
||||
var dispatchedEvent = CUSTOM_EVENTS_MAP[node.target_custom_event_id];
|
||||
base += ' « ' + (dispatchedEvent ? dispatchedEvent.name : '?') + ' »';
|
||||
if (dispatchedEvent && dispatchedEvent.has_element_param && node.target_element_id) {
|
||||
base += ' (' + (ELEMENTS_LABELS[node.target_element_id] || '?') + ')';
|
||||
}
|
||||
}
|
||||
return base;
|
||||
}
|
||||
@@ -2621,51 +2598,16 @@ function toggleFlowActionFields() {
|
||||
var waitFields = document.getElementById('nf-action-wait-fields');
|
||||
var eventFields = document.getElementById('nf-action-event-fields');
|
||||
var isOnglet = typeSel.value === 'activer_onglet';
|
||||
var isModifierElement = typeSel.value === 'modifier_element';
|
||||
screenSel.style.display = (typeSel.value === 'aller_a' || typeSel.value === 'ouvrir_ligne') ? 'block' : 'none';
|
||||
elementFields.style.display = (isModifierElement || isOnglet) ? 'block' : 'none';
|
||||
elementFields.style.display = (typeSel.value === 'modifier_element' || isOnglet) ? 'block' : 'none';
|
||||
dataFields.style.display = typeSel.value === 'modifier_donnee' ? 'block' : 'none';
|
||||
variableFields.style.display = typeSel.value === 'modifier_variable' ? 'block' : 'none';
|
||||
waitFields.style.display = typeSel.value === 'attendre' ? 'block' : 'none';
|
||||
if (eventFields) eventFields.style.display = typeSel.value === 'declencher_evenement' ? 'block' : 'none';
|
||||
document.getElementById('nf-action-onglet-hint').style.display = isOnglet ? 'block' : 'none';
|
||||
document.getElementById('nf-action-element-property-wrap').style.display = isOnglet ? 'none' : 'block';
|
||||
// v1 : seule "Modifier un élément" sait résoudre "l'élément transmis par
|
||||
// l'événement en cours" (target_element_from_event) — pas encore
|
||||
// "Activer cet onglet" (voir le plan, extensible plus tard sans nouveau
|
||||
// changement de schéma).
|
||||
var eventParamRow = document.getElementById('nf-action-event-param-row');
|
||||
if (eventParamRow) eventParamRow.style.display = isModifierElement ? 'flex' : 'none';
|
||||
if (!isModifierElement) document.getElementById('nf-action-element-from-event').checked = false;
|
||||
if (isModifierElement) { toggleFlowElementPropertyValue(); toggleFlowActionElementFromEvent(); }
|
||||
if (typeSel.value === 'modifier_element') toggleFlowElementPropertyValue();
|
||||
if (typeSel.value === 'modifier_donnee') onFlowDefinitionChange('action');
|
||||
if (typeSel.value === 'declencher_evenement') toggleFlowEventDispatchFields();
|
||||
}
|
||||
|
||||
// "Utiliser l'élément transmis par l'événement en cours" (voir
|
||||
// nf-action-event-param-row ci-dessus) : quand coché, le sélecteur
|
||||
// d'élément fixe n'a plus de sens (target_element_from_event résout
|
||||
// dynamiquement l'élément côté client, voir play.html) — masqué plutôt
|
||||
// que laissé visible mais ignoré, pour ne pas laisser croire qu'il compte.
|
||||
function toggleFlowActionElementFromEvent() {
|
||||
var checked = document.getElementById('nf-action-element-from-event').checked;
|
||||
document.getElementById('nf-action-target-element').style.display = checked ? 'none' : 'block';
|
||||
}
|
||||
|
||||
// L'élément/la ligne concernés ne sont utiles que si l'événement choisi a
|
||||
// réellement un paramètre (voir has_element_param, CUSTOM_EVENTS_MAP) —
|
||||
// sans ça, rien à transmettre au déclenchement (voir target_element_id/
|
||||
// target_row_id du nœud Action "declencher_evenement"). Pas de "définition
|
||||
// d'objet" ici (contrairement à "Modifier une donnée") : la ligne
|
||||
// concernée ne peut donc être que "Ligne cliquée" (CLICKED_ROW_ID, si ce
|
||||
// nœud est lui-même exécuté suite à un clic sur une ligne de Répéteur) ou
|
||||
// "ne s'applique pas" — jamais une ligne fixe choisie dans une liste.
|
||||
function toggleFlowEventDispatchFields() {
|
||||
var sel = document.getElementById('nf-action-custom-event');
|
||||
var paramFields = document.getElementById('nf-action-event-param-fields');
|
||||
if (!sel || !paramFields) return;
|
||||
var eventInfo = CUSTOM_EVENTS_MAP[sel.value];
|
||||
paramFields.style.display = (eventInfo && eventInfo.has_element_param) ? 'block' : 'none';
|
||||
}
|
||||
|
||||
function toggleFlowElementPropertyValue() {
|
||||
@@ -2768,11 +2710,7 @@ function submitNodeForm() {
|
||||
} else if (actionType === 'activer_onglet') {
|
||||
payload.target_element_id = parseInt(document.getElementById('nf-action-target-element').value, 10);
|
||||
} else if (actionType === 'modifier_element') {
|
||||
var fromEvent = document.getElementById('nf-action-element-from-event').checked;
|
||||
payload.target_element_from_event = fromEvent ? 1 : 0;
|
||||
if (!fromEvent) {
|
||||
payload.target_element_id = parseInt(document.getElementById('nf-action-target-element').value, 10);
|
||||
}
|
||||
payload.target_element_id = parseInt(document.getElementById('nf-action-target-element').value, 10);
|
||||
var prop = document.getElementById('nf-action-element-property').value;
|
||||
payload.element_property = prop;
|
||||
var isColorProp = prop === 'bg_color' || prop === 'border_color';
|
||||
@@ -2811,14 +2749,10 @@ function submitNodeForm() {
|
||||
} else if (actionType === 'attendre') {
|
||||
payload.data_value = document.getElementById('nf-action-wait-seconds').value;
|
||||
} else if (actionType === 'declencher_evenement') {
|
||||
var evId = parseInt(document.getElementById('nf-action-custom-event').value, 10);
|
||||
payload.target_custom_event_id = evId;
|
||||
var evInfo = CUSTOM_EVENTS_MAP[evId];
|
||||
if (evInfo && evInfo.has_element_param) {
|
||||
payload.target_element_id = parseInt(document.getElementById('nf-action-event-element').value, 10);
|
||||
var evRow = document.getElementById('nf-action-event-row').value;
|
||||
if (evRow) payload.target_row_id = parseInt(evRow, 10);
|
||||
}
|
||||
// Notification pure : aucun élément/ligne à transmettre (voir
|
||||
// screens/custom_events/) — c'est à l'écouteur de décider quoi
|
||||
// faire, avec ses propres réglages habituels.
|
||||
payload.target_custom_event_id = parseInt(document.getElementById('nf-action-custom-event').value, 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user