diff --git a/README.md b/README.md index 6a9caf8..0046cc9 100644 --- a/README.md +++ b/README.md @@ -146,13 +146,17 @@ personnage destinataire ou indiquez son ID : !ravenous-import-effects {"format":"ravenous-roll20-effects","version":1,"effects":[{"effect_id":"combustion","type":"dot","name":"Combustion"}]} !ravenous-import-effects --handout ID_DU_HANDOUT !ravenous-import-effects --id ID_DU_PERSONNAGE --handout ID_DU_HANDOUT +!ravenous-export-effects --id ID_DU_PERSONNAGE ``` Chaque entrée est ajoutée à **DoT & effets** avec son ID, son type, sa durée structurée et ses rappels. Le script refuse les champs inconnus, les valeurs hors limites, les personnages non contrôlés et les handouts inaccessibles. Le JSON exporté prépare une bibliothèque réutilisable ; il n'active pas les effets -dans le suivi des tours. Vérification locale : +dans le suivi des tours. L'export crée un handout privé contenant toutes les +entrées de **DoT & effets**. Les actions Fiche, Artisanat et Effets sont regroupées +dans le menu **Échanges JSON** de l'en-tête afin de ne pas surcharger la fiche. +Vérification locale : ```sh node tests/test_effects_import.mjs diff --git a/roll20_mod/ravenous_effects_import.js b/roll20_mod/ravenous_effects_import.js index 5785a96..759ce69 100644 --- a/roll20_mod/ravenous_effects_import.js +++ b/roll20_mod/ravenous_effects_import.js @@ -3,6 +3,7 @@ * !ravenous-import-effects --id CHARACTER_ID JSON * !ravenous-import-effects --handout HANDOUT_ID * !ravenous-import-effects --id CHARACTER_ID --handout HANDOUT_ID + * !ravenous-export-effects --id CHARACTER_ID * * Without --id, exactly one token representing the destination character must * be selected. Players may only use characters they control and handouts they @@ -11,6 +12,7 @@ (function () { 'use strict'; var COMMAND = '!ravenous-import-effects'; + var EXPORT_COMMAND = '!ravenous-export-effects'; var FORMAT = 'ravenous-roll20-effects'; var VERSION = 1; var LIMITS = { effects: 100, id: 80, name: 120, duration: 120, description: 1000, reminder: 500 }; @@ -113,6 +115,39 @@ }); whisper('Imported ' + data.effects.length + ' reusable effect(s) into ' + character.get('name') + '.', playerId); } + function exportEffects(characterId, playerId) { + var character = getObj('character', characterId); + if (!character) return whisper('Character not found. Select a linked token or use --id CHARACTER_ID.', playerId); + if (!canControl(character, playerId)) return whisper('Permission denied: the player does not control that character.', playerId); + var rows = {}; + findObjs({ type: 'attribute', characterid: characterId }).forEach(function (attribute) { + var match = String(attribute.get('name') || '').match(/^repeating_sharedeffects_([^_]+)_(.+)$/); + if (!match || FIELDS.indexOf(match[2]) < 0) return; + rows[match[1]] = rows[match[1]] || {}; + rows[match[1]][match[2]] = attribute.get('current'); + }); + var effects = Object.keys(rows).sort().map(function (id) { + var row = rows[id]; + return { + enabled: row.enabled !== '0', effect_id: row.effect_id || id, type: TYPES.indexOf(row.type) >= 0 ? row.type : 'other', + name: row.name || row.effect_id || 'Effet', duration: row.duration || '', description: row.description || '', + duration_type: DURATION_TYPES.indexOf(row.duration_type) >= 0 ? row.duration_type : 'manual', + remaining: Math.max(0, Math.min(999, Math.floor(Number(row.remaining) || 0))), + countdown_phase: PHASES.indexOf(row.countdown_phase) >= 0 ? row.countdown_phase : 'end', + start_reminder: row.start_reminder || '', end_reminder: row.end_reminder || '', + apply_reminder: row.apply_reminder || '', removal_reminder: row.removal_reminder || '' + }; + }).filter(validEffect); + if (!effects.length) return whisper('No reusable effects found on that character.', playerId); + var data = { format: FORMAT, version: VERSION, name: character.get('name') + ' — effets', effects: effects }; + var isGM = playerIsGM(playerId); + var handout = createObj('handout', { name: 'Ravenous effects - ' + character.get('name'), + inplayerjournals: isGM ? '' : playerId, controlledby: isGM ? '' : playerId }); + if (!handout) return whisper('Roll20 could not create the effects handout.', playerId); + var readable = JSON.stringify(data, null, 2).replace(/&/g, '&').replace(//g, '>'); + handout.set(isGM ? 'gmnotes' : 'notes', '
' + readable + ''); + whisper('Exported ' + effects.length + ' reusable effect(s) to handout ' + handout.id + '.', playerId); + } function selectedCharacterId(message) { var selected = message.selected || []; if (selected.length !== 1 || selected[0]._type !== 'graphic') { @@ -141,6 +176,15 @@ on('chat:message', function (message) { if (message.type !== 'api') return; var content = message.content.trim(); + if (content === EXPORT_COMMAND || content.indexOf(EXPORT_COMMAND + ' ') === 0) { + var exportArgument = content.slice(EXPORT_COMMAND.length).trim(); + var exportId = ''; + if (exportArgument.indexOf('--id ') === 0) exportId = exportArgument.slice('--id '.length).trim(); + else if (exportArgument) return whisper('Usage: ' + EXPORT_COMMAND + ' [--id CHARACTER_ID].', message.playerid); + exportId = exportId || selectedCharacterId(message); + if (exportId) return exportEffects(exportId, message.playerid); + return; + } if (content !== COMMAND && content.indexOf(COMMAND + ' ') !== 0) return; var args = argumentsFrom(content.slice(COMMAND.length)); if (!args) return whisper('Usage: ' + COMMAND + ' [--id CHARACTER_ID] JSON or --handout HANDOUT_ID.', message.playerid); diff --git a/src/ravenous.css b/src/ravenous.css index c147e3d..a7f1093 100644 --- a/src/ravenous.css +++ b/src/ravenous.css @@ -19,6 +19,12 @@ .identity-grid { display:grid; grid-template-columns:2fr 2fr 1.5fr 1fr; gap:8px; margin-top:6px; } .identity-grid label,.ravenous-sheet label { color:var(--muted); font-size:10px; text-transform:uppercase; letter-spacing:.05em; } .motto { color:var(--dark-gold); text-align:center; } +.character-io-menu { position:relative; text-align:left; } +.character-io-menu summary { padding:6px 8px; color:var(--light); border:1px solid var(--dark-gold); border-radius:2px; background:var(--blood); font:700 9px "Cinzel",Georgia,serif; text-align:center; text-transform:uppercase; cursor:pointer; list-style:none; } +.character-io-menu summary::-webkit-details-marker { display:none; } +.character-io-menu summary::after { content:" ▾"; } +.character-io-menu[open] summary::after { content:" ▴"; } +.character-io-menu[open] .character-io-actions { margin-top:4px; } .character-io-actions { display:grid; grid-template-columns:58px repeat(2,minmax(0,1fr)); gap:4px; align-items:center; } .character-io-actions>span { color:var(--muted); font:700 8px "Cinzel",Georgia,serif; text-align:left; text-transform:uppercase; letter-spacing:.04em; } .ravenous-sheet .character-io-actions button[type=roll] { width:100%; min-width:0; margin:0; padding:4px 3px; color:var(--light); border:1px solid var(--dark-gold); border-radius:2px; background:var(--blood); font:700 8px "Cinzel",Georgia,serif; white-space:nowrap; box-shadow:none; } diff --git a/src/ravenous.html b/src/ravenous.html index 265dcf7..94a73b0 100644 --- a/src/ravenous.html +++ b/src/ravenous.html @@ -15,14 +15,20 @@