feat: add effects exchange controls
Roll20 Sheet Build Successful The Ravenous Roll20 sheet was generated and validated successfully.
Ravenous/ravenous_roll20/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-09-20 04:44:12 +02:00
parent 0e4912c5c9
commit 24170454c6
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
6 changed files with 97 additions and 9 deletions

View File

@ -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

View File

@ -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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
handout.set(isGM ? 'gmnotes' : 'notes', '<pre>' + readable + '</pre>');
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);

View File

@ -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; }

View File

@ -15,14 +15,20 @@
</div>
</div>
<div class="motto">
<div class="character-io-actions">
<span>Fiche</span>
<button type="roll" name="roll_export_character" value="!ravenous-export --id @{character_id}">Export</button>
<button type="roll" name="roll_replace_character" value="!ravenous-import --replace --id @{character_id} --handout ?{ID du handout personnage}">Restaurer</button>
<span>Artisanat</span>
<button type="roll" name="roll_export_craft" value="!ravenous-export-craft --id @{character_id}">Export</button>
<button type="roll" name="roll_import_craft" value="!ravenous-import-craft --id @{character_id} --handout ?{ID du handout artisanat}">Import</button>
</div>
<details class="character-io-menu">
<summary>Échanges JSON</summary>
<div class="character-io-actions">
<span>Fiche</span>
<button type="roll" name="roll_export_character" value="!ravenous-export --id @{character_id}">Export</button>
<button type="roll" name="roll_replace_character" value="!ravenous-import --replace --id @{character_id} --handout ?{ID du handout personnage}">Restaurer</button>
<span>Artisanat</span>
<button type="roll" name="roll_export_craft" value="!ravenous-export-craft --id @{character_id}">Export</button>
<button type="roll" name="roll_import_craft" value="!ravenous-import-craft --id @{character_id} --handout ?{ID du handout artisanat}">Import</button>
<span>Effets</span>
<button type="roll" name="roll_export_effects" value="!ravenous-export-effects --id @{character_id}">Export</button>
<button type="roll" name="roll_import_effects" value="!ravenous-import-effects --id @{character_id} --handout ?{ID du handout effets}">Import</button>
</div>
</details>
<label class="secret-rolls">Jets secrets<input type="checkbox" name="attr_secret_rolls" value="1"></label>
</div>
</header>

View File

@ -49,6 +49,9 @@ class BuildTests(unittest.TestCase):
self.assertIn('value="!ravenous-export --id @{character_id}"', sheet)
self.assertIn('value="!ravenous-import --replace --id @{character_id} --handout ?{ID du handout personnage}"', sheet)
self.assertIn('value="!ravenous-export-craft --id @{character_id}"', sheet)
self.assertIn('value="!ravenous-export-effects --id @{character_id}"', sheet)
self.assertIn('value="!ravenous-import-effects --id @{character_id} --handout ?{ID du handout effets}"', sheet)
self.assertIn('<summary>Échanges JSON</summary>', sheet)
self.assertIn('value="!ravenous-import-craft --id @{character_id} --handout ?{ID du handout artisanat}"', sheet)
def test_origins_and_powers_are_imported(self):

View File

@ -24,6 +24,8 @@ function session() {
on(event, callback) { assert.equal(event, 'chat:message'); handler = callback; },
playerIsGM: id => id === 'gm', createObj,
getObj: (type, id) => objects.get(id)?.type === type ? objects.get(id) : undefined,
findObjs: query => [...objects.values()].filter(object => object.type === query.type &&
object.get('characterid') === query.characterid),
sendChat: (speaker, content) => chat.push({ speaker, content }),
Date, Math, Number, parseInt, String,
});
@ -83,6 +85,29 @@ test('fills every sheet field with safe defaults', () => {
assert.ok(values.includes('0'));
});
test('exports reusable effects to a private handout that can be imported again', () => {
const game = session();
const player = game.createObj('player', { _displayname: 'Alice' });
const source = game.createObj('character', { name: 'Ariane', controlledby: player.id });
const fields = { enabled: '1', effect_id: 'al_combustion', type: 'dot', name: 'Combustion',
duration: '2 tours', description: 'Brûle.', duration_type: 'turns', remaining: '2',
countdown_phase: 'start', start_reminder: 'Subissez 4 dégâts.', end_reminder: '',
apply_reminder: '', removal_reminder: 'Les flammes cessent.' };
for (const [field, current] of Object.entries(fields)) {
game.createObj('attribute', { characterid: source.id,
name: `repeating_sharedeffects_row1_${field}`, current, max: '' });
}
game.send(`!ravenous-export-effects --id ${source.id}`, player.id);
const handout = [...game.objects.values()].find(object => object.type === 'handout');
assert.equal(handout.get('controlledby'), player.id);
assert.match(handout.get('notes'), /"effect_id": "al_combustion"/);
assert.match(game.chat.at(-1).content, /Exported 1 reusable effect/);
const destination = game.createObj('character', { name: 'Destination', controlledby: player.id });
game.send(`!ravenous-import-effects --id ${destination.id} --handout ${handout.id}`, player.id);
assert.ok(attributes(game, destination.id).some(attribute => attribute.get('current') === 'Combustion'));
});
test('a player can import an HTML-escaped accessible handout into a controlled character', () => {
const game = session();
const player = game.createObj('player', { _displayname: 'Alice' });