Created
September 10, 2021 17:38
-
-
Save Mejari/cac90f00c10ed5f583b28a3b9f880a7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(!game.users.current.isGM) { | |
| ui.notifications.error('Must execute as GM'); | |
| } | |
| const actorUnits = game.actors.filter(a=>a.sheet.constructor.name === 'KW_WarfareUnitSheet'); | |
| const tokenUnits = game.collections.get("Scene").map(s=>s.tokens).flatMap(tm=>tm.contents).map(t=>t.actor).filter(a=>a.sheet.constructor.name === 'KW_WarfareUnitSheet'); | |
| const units = [... new Set(actorUnits.concat(tokenUnits))]; | |
| let content = ` | |
| <div> | |
| <h2>Units: | |
| <ul>`; | |
| units.forEach(o=>{ | |
| content += `<li><input type="checkbox" id="${o.id}" value="${o.id}" checked=true> | |
| <label for="${o.id}">${o.name}</label></li>` | |
| }); | |
| content += '</ul></div>'; | |
| const buttons = { | |
| cancel: { | |
| icon: '<i class="fas fa-times"></i>', | |
| label: '', | |
| callback: () => {} | |
| }, | |
| start: { | |
| icon: '<i class="fas fa-play"></i>', | |
| label: 'Migrate', | |
| callback: async (html) => { | |
| const selectedUnits = html.find('input:checkbox:checked') | |
| .get().map(cb=>game.actors.get(cb.value)); | |
| const {setKWWarfareUnitDefaults} = await import('/modules/kw-warfare/module/KW_WarfareUnitSheet.js'); | |
| selectedUnits.forEach(u=>{ | |
| const oldStats = u.getFlag('kw-warfare', 'stats'); | |
| const oldDetails = u.getFlag('kw-warfare', 'details'); | |
| setKWWarfareUnitDefaults(u); | |
| if(oldStats) { | |
| u.setFlag('kw-warfare', 'unit.stats.attack.value', oldStats.attack); | |
| u.setFlag('kw-warfare', 'unit.stats.defense.value', oldStats.defense); | |
| u.setFlag('kw-warfare', 'unit.stats.morale.value', oldStats.morale); | |
| u.setFlag('kw-warfare', 'unit.stats.power.value', oldStats.power); | |
| u.setFlag('kw-warfare', 'unit.stats.toughness.value', oldStats.toughness); | |
| u.setFlag('kw-warfare', 'unit.stats.command.value', oldStats.command); | |
| u.setFlag('kw-warfare', 'unit.tier', oldStats.tier); | |
| u.setFlag('kw-warfare', 'unit.damage', oldStats.damage); | |
| u.setFlag('kw-warfare', 'unit.numberOfAttacks', oldStats.numberOfAttacks); | |
| } | |
| if(oldDetails) { | |
| u.setFlag('kw-warfare', 'unit.experience', oldDetails.experience); | |
| u.setFlag('kw-warfare', 'unit.type', oldDetails.type); | |
| u.setFlag('kw-warfare', 'unit.ancestry', oldDetails.ancestry); | |
| u.setFlag('kw-warfare', 'unit.equipment', oldDetails.equipment); | |
| u.setFlag('kw-warfare', 'unit.commander', oldDetails.commander); | |
| } | |
| }); | |
| } | |
| } | |
| }; | |
| let d = new Dialog({ | |
| title: 'K&W Data Migration 0.8.1=>1.0', | |
| content, | |
| buttons, | |
| default: "start" | |
| }); | |
| d.render(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment