From ec7c98004b3ef53e1a61702325ddfb956eb4054b Mon Sep 17 00:00:00 2001 From: Stexinator Date: Wed, 29 Mar 2023 09:23:30 +0200 Subject: [PATCH 1/7] [SalvageUnion] minor bug fixes + add heat to systems/modules --- SalvageUnion/SalvageUnion.css | 8 +++++ SalvageUnion/SalvageUnion.html | 58 +++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/SalvageUnion/SalvageUnion.css b/SalvageUnion/SalvageUnion.css index e77b1b8ed5..e071d570ab 100644 --- a/SalvageUnion/SalvageUnion.css +++ b/SalvageUnion/SalvageUnion.css @@ -19,6 +19,14 @@ summary{ margin-left: 10px; } +details summary { + cursor: pointer; +} + +details > div { + padding-left: 1rem; +} + /* Chrome, Safari, Edge, Opera */ input:disabled::-webkit-outer-spin-button, input:disabled::-webkit-inner-spin-button { diff --git a/SalvageUnion/SalvageUnion.html b/SalvageUnion/SalvageUnion.html index d8cf53dd3c..58804d8097 100644 --- a/SalvageUnion/SalvageUnion.html +++ b/SalvageUnion/SalvageUnion.html @@ -90,7 +90,7 @@ - @@ -222,8 +222,8 @@
- - + +
@@ -252,7 +252,7 @@ -
@@ -302,7 +302,7 @@ - + @@ -319,6 +319,10 @@
+
+ + +
@@ -367,6 +371,10 @@
+
+ + +
@@ -440,7 +448,7 @@ -
@@ -530,6 +538,14 @@ Show Shield +
+ Importer + + + + + +

@@ -543,14 +559,6 @@
-
- Importer - - - - - -
@@ -688,13 +696,18 @@ on('clicked:repeating_modules:use-module clicked:repeating_systems:use-system', var trigger = event.triggerName.slice(8); // this always starts with 'clicked:' var prefix = trigger.split('_').slice(0,3).join('_') + '_' - let attrs = await asw.getAttrs(['character_name', 'energy', prefix+'name', prefix+'cost', prefix+'has-uses']); + let attrs = await asw.getAttrs(['character_name', 'energy', 'heat', prefix+'name', prefix+'cost', prefix+'heat', prefix+'has-uses']); let cost = parseInt(attrs[prefix+'cost']); + let heat = parseInt(attrs[prefix+'heat']); let toSet = {} let rollBase = `/w ${attrs.character_name} &{template:info}{{info= You activated ${attrs[prefix+'name']} for `; - if(attrs[prefix+'has-uses'] ==! 'on') { + if(heat !== 0) { + rollBase += `${heat} heat and ` + toSet.heat = attrs['heat'] + heat + } + if(attrs[prefix+'has-uses'] !== 'on') { toSet.energy = attrs['energy'] - cost; rollBase += `${cost} EP. ${toSet.energy} Energy remaining}}` } @@ -702,6 +715,7 @@ on('clicked:repeating_modules:use-module clicked:repeating_systems:use-system', toSet[prefix+'cost'] = cost-1; rollBase += `1 use. ${toSet[prefix+'cost']} Uses remaining}}` } + toSet[prefix+'active'] = 'on'; asw.setAttrs(toSet); @@ -710,9 +724,9 @@ on('clicked:repeating_modules:use-module clicked:repeating_systems:use-system', finishRoll(roll.rollId, {}); }); -///////////////////// -// IMPORTER //// -///////////////////// +/////////////////////// +// MECH IMPORTER //// +/////////////////////// on('clicked:import-mech-stats', async (ev) => { @@ -1007,7 +1021,7 @@ const asw = (() => { @@ -1076,13 +1090,13 @@ const asw = (() => {
{{#rollTotal() heatroll 0}}
- [Push](~{{callsign}}|reactPushWeapon) + [Push](~{{name}}|reactPushWeapon)
{{/rollTotal() heatroll 0}} {{#^rollGreater() heatroll heat}}
- [Reactor Overload](~{{callsign}}|reactOverload) + [Reactor Overload](~{{name}}|reactOverload)
{{/^rollGreater() heatroll heat}}
From a9746d729712dcca03b9375e6cbe5e8a1704f520 Mon Sep 17 00:00:00 2001 From: Stexinator Date: Wed, 29 Mar 2023 19:16:00 +0200 Subject: [PATCH 2/7] [SalvageUnion] revamp heat system --- SalvageUnion/SalvageUnion.css | 12 +- SalvageUnion/SalvageUnion.html | 500 +++++++++++++++++++-------------- 2 files changed, 301 insertions(+), 211 deletions(-) diff --git a/SalvageUnion/SalvageUnion.css b/SalvageUnion/SalvageUnion.css index e071d570ab..023b5db2f4 100644 --- a/SalvageUnion/SalvageUnion.css +++ b/SalvageUnion/SalvageUnion.css @@ -23,10 +23,19 @@ details summary { cursor: pointer; } +details > details { + margin-left: 10px; +} + details > div { padding-left: 1rem; } +.characterviewer details > div > label { + font-weight: normal; + font-size: 1em; +} + /* Chrome, Safari, Edge, Opera */ input:disabled::-webkit-outer-spin-button, input:disabled::-webkit-inner-spin-button { @@ -39,9 +48,6 @@ input[type=number]:disabled { -moz-appearance: textfield; } -.subdetails { - margin-left: 10px; -} input[type="checkbox"] { margin-left: 10px; diff --git a/SalvageUnion/SalvageUnion.html b/SalvageUnion/SalvageUnion.html index 58804d8097..6536f0ba34 100644 --- a/SalvageUnion/SalvageUnion.html +++ b/SalvageUnion/SalvageUnion.html @@ -179,7 +179,7 @@

Mech - +

@@ -252,25 +252,31 @@ - -
+
- Settings +

Settings

-
- - -
-
- - -
-
- - -
+
+

Cost

+
+ + +
+
+ + +
+
+
+

Heat

+
+ + +
+
@@ -307,22 +313,28 @@ -
+
- Settings +

Settings

-
- - -
-
- - -
-
- - -
+
+

Cost

+
+ + +
+
+ + +
+
+
+

Heat

+
+ + +
+
@@ -359,22 +371,28 @@ -
+
- Settings +

Settings

-
- - -
-
- - -
-
- - -
+
+

Cost

+
+ + +
+
+ + +
+
+
+

Heat

+
+ + +
+
@@ -451,7 +469,7 @@ -
+
Settings @@ -623,13 +641,15 @@ on('clicked:repeating_mechweapons:roll', // prefix gets an empty string for normal attributes, and repeating_section_ID_ for repeating attributes var prefix = event.sourceAttribute.split('_').slice(0,3).join('_') + '_' + let attrs = await asw.getAttrs([`${prefix}heat`]); + let weaponheat = attrs[Object.keys(attrs)[0]] + let overheat = await overheatCheck(weaponheat); + let rollPart = event.htmlAttributes.value.replaceAll('prefix-', `${prefix}`); - let results = await startRoll(rollPart); + let results = await startRoll(rollPart + overheat.queryMod); - let attrs = await asw.getAttrs(['heat']); - let resultingHeat = parseInt(attrs.heat) + results.results.weaponheat.result; asw.setAttrs({ - heat: resultingHeat + heat: overheat.resultingHeat }); finishRoll( @@ -638,58 +658,6 @@ on('clicked:repeating_mechweapons:roll', ); }); -on('clicked:reactPush', async (ev) => { - await push(ev, 'roll'); -}); - -on('clicked:reactPushWeapon', async (ev) => { - await push(ev, 'weapon'); -}); - -const push = async (ev, template) => { - - let attrs = await asw.getAttrs(['character_name', 'heat']); - - let resultingHeat = parseInt(attrs.heat) + 2; - - let rollBase = `&{template:${template}}{{name=${attrs.character_name}}}{{roll=[[1d20]]}}{{mech=1}}{{heatroll=[[1d20]]}}{{heat=[[${resultingHeat}]]}}`; - let roll = await startRoll(rollBase); - - asw.setAttrs({ - heat: resultingHeat - }); - - finishRoll(roll.rollId, { - - }); -} - -on('clicked:reactOverload', async (ev) => { - await reactOverload(ev); -}); - -const reactOverload = async (ev) => { - - let attrs = await asw.getAttrs(['character_name', 'heat', 'heat_max']); - - let rollBase = `&{template:overload}{{name=${attrs.character_name}}}{{roll=[[1d20]]}}{{heat=${attrs.heat}}}{{maxheat=${attrs.heat_max}}}`; - let roll = await startRoll(rollBase); - - finishRoll(roll.rollId, {}); -} - -on('clicked:downtime', async (ev) => { - let attrs = await asw.getAttrs(['health_max', 'abilitypts_max', 'structure_max', 'energy_max']); - - asw.setAttrs({ - health: attrs['health_max'], - abilitypts: attrs['abilitypts_max'], - structure: attrs['structure_max'], - energy: parseInt(attrs['energy_max']), - heat: 0, - }); -}); - on('clicked:repeating_modules:use-module clicked:repeating_systems:use-system', async (event) => { // prefix gets an empty string for normal attributes, and repeating_section_ID_ for repeating attributes @@ -700,12 +668,21 @@ on('clicked:repeating_modules:use-module clicked:repeating_systems:use-system', let cost = parseInt(attrs[prefix+'cost']); let heat = parseInt(attrs[prefix+'heat']); + let overheat = await overheatCheck(heat); + + if(overheat.queryMod.includes("{{toMuchHeat=[[1]]}}")) { + let rollBase = `/w ${attrs.character_name} &{template:info}{{info= You have to much heat to use ${attrs[prefix+'name']} }}`; + let roll = await startRoll(rollBase); + finishRoll(roll.rollId, {}); + return; + } + let toSet = {} let rollBase = `/w ${attrs.character_name} &{template:info}{{info= You activated ${attrs[prefix+'name']} for `; if(heat !== 0) { rollBase += `${heat} heat and ` - toSet.heat = attrs['heat'] + heat + toSet.heat = overheat.resultingHeat; } if(attrs[prefix+'has-uses'] !== 'on') { toSet.energy = attrs['energy'] - cost; @@ -724,6 +701,86 @@ on('clicked:repeating_modules:use-module clicked:repeating_systems:use-system', finishRoll(roll.rollId, {}); }); +on('clicked:reactPush', async (ev) => { + await push(ev, 'roll'); +}); + +on('clicked:reactPushWeapon', async (ev) => { + await push(ev, 'weapon'); +}); + +const push = async (ev, template) => { + + let attrs = await asw.getAttrs(['character_name']); + + let overheat = await overheatCheck(2); + + let rollBase = `&{template:${template}}{{name=${attrs.character_name}}}{{roll=[[1d20]]}}{{mech=1}}` + overheat.queryMod ; + let roll = await startRoll(rollBase); + + await asw.setAttrs({ + heat: overheat.resultingHeat + }); + + finishRoll(roll.rollId, { + + }); +} + +const overheatCheck = async (heatchange) => { + + console.log(heatchange); + + let attrs = await asw.getAttrs(['heat', 'heat_max']); + let resultingHeat = parseInt(attrs.heat) + parseInt(heatchange); + + if(resultingHeat > parseInt(attrs.heat_max)) { + return { + resultingHeat: parseInt(attrs.heat), + queryMod: '{{toMuchHeat=[[1]]}}' + } + } + + if(resultingHeat === parseInt(attrs.heat_max)) { + return { + resultingHeat: resultingHeat, + queryMod: `{{heatroll=[[1d20]]}}{{heat=[[${resultingHeat}]]}}{{toMuchHeat=[[0]]}}`, + + } + } + + return { + resultingHeat: resultingHeat, + queryMod: '{{toMuchHeat=[[0]]}}', + } +} + +on('clicked:reactOverload', async (ev) => { + await reactOverload(ev); +}); + +const reactOverload = async (ev) => { + + let attrs = await asw.getAttrs(['character_name']); + + let rollBase = `&{template:overload}{{name=${attrs.character_name}}}{{roll=[[1d20]]}}`; + let roll = await startRoll(rollBase); + + finishRoll(roll.rollId, {}); +} + +on('clicked:downtime', async (ev) => { + let attrs = await asw.getAttrs(['health_max', 'abilitypts_max', 'structure_max', 'energy_max']); + + asw.setAttrs({ + health: attrs['health_max'], + abilitypts: attrs['abilitypts_max'], + structure: attrs['structure_max'], + energy: parseInt(attrs['energy_max']), + heat: 0, + }); +}); + /////////////////////// // MECH IMPORTER //// /////////////////////// @@ -789,10 +846,10 @@ on('clicked:import-mech-weapon', async (ev) => { weapon[row + "damage"] = toImport[1].split('//')[1].replaceAll(/[a-zA-Z]*:/g, '').trim(); if(toImport[1].includes("Hot (")) { - weapon[row + "weaponheat"] = toImport[1].match(/Hot \(\d\)/g).pop().match(/\d+/).pop(); + weapon[row + "heat"] = toImport[1].match(/Hot \(\d\)/g).pop().match(/\d+/).pop(); } else { - weapon[row + "weaponheat"] = 0; + weapon[row + "heat"] = 0; } weapon[row + "weapondetails"] = toImport[1].split('//').slice(2).join('//').trim() + "\n" + toImport.slice(2).join(' ').trim(); @@ -957,62 +1014,76 @@ const asw = (() => { {{name}} rolls
+ + {{#rollTotal() toMuchHeat 1}} - - + + + + - - {{#heat}} - - - - - - - {{/heat}} + {{#rollBetween() roll 2 5}} + Failure ({{roll}}) - You’ve failed at what you were attempting, and you’ll face a consequence of The Mediator’s choice. + {{/rollBetween() roll 2 5}} + + {{#rollBetween() roll 1 1}} + Cascade Failure ({{roll}}) - You have not only failed, but something has gone terribly wrong. You will suffer a severe consequence of The Mediator’s choice. + {{/rollBetween() roll 1 1}} + {{/^rollWasCrit() roll}} + + + {{#heat}} + + + + + + + {{/heat}} + {{/rollTotal() toMuchHeat 0}}
- {{callsign}} rolls an attack on range {{range}} with {{weapon_name}} + {{name}} rolls an attack on range {{range}} with {{weapon_name}}
-
+ You cannot make this roll due to heat.
- {{#rollBetween() roll 20 20}} - Nailed it ({{roll}})
- You have overcome the odds and managed an outstanding success. You may achieve an additional bonus of your choice to the action. When dealing damage you double it. - {{/rollBetween() roll 20 20}} + {{/rollTotal() toMuchHeat 1}} - {{#rollBetween() roll 11 19}} - Success ({{roll}}) - You’ve achieved your goal without any compromises. - {{/rollBetween() roll 11 19}} + {{#rollTotal() toMuchHeat 0}} +
+
+
+ {{#rollWasCrit() roll}} + Nailed it ({{roll}})
+ You have overcome the odds and managed an outstanding success. You may achieve an additional bonus of your choice to the action. When dealing damage you double it. + {{/rollWasCrit() roll}} - {{#rollBetween() roll 6 10}} - Tough Choice ({{roll}}) - You succeed in your action but at a cost. The Mediator will give you a tough choice with some kind of consequence. - {{/rollBetween() roll 6 10}} + {{#^rollWasCrit() roll}} + {{#rollBetween() roll 11 19}} + Success ({{roll}}) - You’ve achieved your goal without any compromises. + {{/rollBetween() roll 11 19}} - {{#rollBetween() roll 2 5}} - Failure ({{roll}}) - You’ve failed at what you were attempting, and you’ll face a consequence of The Mediator’s choice. - {{/rollBetween() roll 2 5}} + {{#rollBetween() roll 6 10}} + Tough Choice ({{roll}}) - You succeed in your action but at a cost. The Mediator will give you a tough choice with some kind of consequence. + {{/rollBetween() roll 6 10}} - {{#rollBetween() roll 1 1}} - Cascade Failure ({{roll}}) - You have not only failed, but something has gone terribly wrong. You will suffer a severe consequence of The Mediator’s choice. - {{/rollBetween() roll 1 1}} -
-
-
- Heat Check: {{heat}} vs {{heatroll}} -
+
+
+ Heat Check: {{heat}} vs {{heatroll}} +
{{#mech}}
+ {{#rollTotal() toMuchHeat 0}} + {{#rollTotal() heatroll 0}} +
+ [Push](~{{name}}|reactPush) +
+ {{/rollTotal() heatroll 0}} - {{#rollTotal() heatroll 0}} -
- [Push](~{{name}}|reactPush) -
- {{/rollTotal() heatroll 0}} - - {{#^rollGreater() heatroll heat}} -
- [Reactor Overload](~{{name}}|reactOverload) -
- {{/^rollGreater() heatroll heat}} + {{#^rollGreater() heatroll heat}} +
+ [Reactor Overload](~{{name}}|reactOverload) +
+ {{/^rollGreater() heatroll heat}} + {{/rollTotal() toMuchHeat 0}}
{{/mech}} @@ -1029,76 +1100,89 @@ const asw = (() => {
+ {{#rollTotal() toMuchHeat 1}} - {{#rollBetween() roll 20 20}} - Nailed it ({{roll}})
- You have overcome the odds and managed an outstanding success. You may achieve an additional bonus of your choice to the action e.g. double the damage. - {{/rollBetween() roll 20 20}} + You cannot make this roll due to heat. + + + {{/rollTotal() toMuchHeat 1}} + {{#rollTotal() toMuchHeat 0}} + + + {{#rollWasCrit() roll}} + Nailed it ({{roll}})
+ You have overcome the odds and managed an outstanding success. You may achieve an additional bonus of your choice to the action e.g. double the damage. + {{/rollWasCrit() roll}} - {{#rollBetween() roll 11 19}} - Success ({{roll}}) - You hit the target and deal standard damage - {{/rollBetween() roll 11 19}} + {{#^rollWasCrit() roll}} + {{#rollBetween() roll 11 19}} + Success ({{roll}}) - You hit the target and deal standard damage + {{/rollBetween() roll 11 19}} - {{#rollBetween() roll 6 10}} - Tough Choice ({{roll}}) - You succeed in your action but at a cost. The Mediator will give you a tough choice with some kind of consequence. You hit but something has - gone wrong. - {{/rollBetween() roll 6 10}} + {{#rollBetween() roll 6 10}} + Tough Choice ({{roll}}) - You succeed in your action but at a cost. The Mediator will give you a tough choice with some kind of consequence. You hit but something has + gone wrong. + {{/rollBetween() roll 6 10}} - {{#rollBetween() roll 2 5}} - Failure ({{roll}}) - You miss the target. - {{/rollBetween() roll 2 5}} + {{#rollBetween() roll 2 5}} + Failure ({{roll}}) - You miss the target. + {{/rollBetween() roll 2 5}} - {{#rollBetween() roll 1 1}} - Cascade Failure ({{roll}}) - You miss the target and something has gone wrong. - {{/rollBetween() roll 1 1}} - - - {{#damage}} - - -
- - - - - Weapondamage: {{damage}} - - - {{/damage}} - {{#^rollTotal() weaponheat 0}} - - - Weaponheat: {{weaponheat}} - - - {{/^rollTotal() weaponheat 0}} - {{#heat}} - - -
- - - - - Heat Check: {{heat}} vs {{heatroll}} - - - {{/heat}} + {{#rollBetween() roll 1 1}} + Cascade Failure ({{roll}}) - You miss the target and something has gone wrong. + {{/rollBetween() roll 1 1}} + {{/^rollWasCrit() roll}} + + + {{#damage}} + + +
+ + + + + Weapondamage: {{damage}} + + + {{/damage}} + {{#^rollTotal() weaponheat 0}} + + + Weaponheat: {{weaponheat}} + + + {{/^rollTotal() weaponheat 0}} + {{#heat}} + + +
+ + + + + Heat Check: {{heat}} vs {{heatroll}} + + + {{/heat}} + {{/rollTotal() toMuchHeat 0}} {{#mech}}
- {{#rollTotal() heatroll 0}} -
- [Push](~{{name}}|reactPushWeapon) -
- {{/rollTotal() heatroll 0}} + {{#rollTotal() toMuchHeat 0}} + {{#rollTotal() heatroll 0}} +
+ [Push](~{{name}}|reactPushWeapon) +
+ {{/rollTotal() heatroll 0}} - {{#^rollGreater() heatroll heat}} -
- [Reactor Overload](~{{name}}|reactOverload) -
- {{/^rollGreater() heatroll heat}} + {{#^rollGreater() heatroll heat}} +
+ [Reactor Overload](~{{name}}|reactOverload) +
+ {{/^rollGreater() heatroll heat}} + {{/rollTotal() toMuchHeat 0}}
{{/mech}} From 7fe1e2a576b84b564da209fa90709f4ead065505 Mon Sep 17 00:00:00 2001 From: Stexinator Date: Wed, 29 Mar 2023 19:44:23 +0200 Subject: [PATCH 3/7] [SalvageUnion] add heatspike --- SalvageUnion/SalvageUnion.html | 131 ++++++++++++++++++++++++++------- 1 file changed, 105 insertions(+), 26 deletions(-) diff --git a/SalvageUnion/SalvageUnion.html b/SalvageUnion/SalvageUnion.html index 6536f0ba34..ff005a4e7b 100644 --- a/SalvageUnion/SalvageUnion.html +++ b/SalvageUnion/SalvageUnion.html @@ -179,7 +179,7 @@

Mech - +

@@ -252,7 +252,7 @@ -
@@ -276,6 +276,10 @@
+
+ + +
@@ -334,6 +338,10 @@
+
+ + +
@@ -392,6 +400,10 @@
+
+ + +
@@ -641,9 +653,10 @@ on('clicked:repeating_mechweapons:roll', // prefix gets an empty string for normal attributes, and repeating_section_ID_ for repeating attributes var prefix = event.sourceAttribute.split('_').slice(0,3).join('_') + '_' - let attrs = await asw.getAttrs([`${prefix}heat`]); - let weaponheat = attrs[Object.keys(attrs)[0]] - let overheat = await overheatCheck(weaponheat); + let attrs = await asw.getAttrs([prefix+'heat', prefix+'heatspike']); + let overheat = await overheatCheck( attrs[prefix+'heat'], attrs[prefix+'heatspike']); + + console.log(overheat); let rollPart = event.htmlAttributes.value.replaceAll('prefix-', `${prefix}`); let results = await startRoll(rollPart + overheat.queryMod); @@ -664,11 +677,12 @@ on('clicked:repeating_modules:use-module clicked:repeating_systems:use-system', var trigger = event.triggerName.slice(8); // this always starts with 'clicked:' var prefix = trigger.split('_').slice(0,3).join('_') + '_' - let attrs = await asw.getAttrs(['character_name', 'energy', 'heat', prefix+'name', prefix+'cost', prefix+'heat', prefix+'has-uses']); + let attrs = await asw.getAttrs(['character_name', 'energy', 'heat', prefix+'name', prefix+'cost', prefix+'heat', prefix+'heatspike', prefix+'has-uses']); let cost = parseInt(attrs[prefix+'cost']); let heat = parseInt(attrs[prefix+'heat']); + let heatspike = attrs[prefix+'heatspike']; - let overheat = await overheatCheck(heat); + let overheat = await overheatCheck(heat, heatspike); if(overheat.queryMod.includes("{{toMuchHeat=[[1]]}}")) { let rollBase = `/w ${attrs.character_name} &{template:info}{{info= You have to much heat to use ${attrs[prefix+'name']} }}`; @@ -679,7 +693,7 @@ on('clicked:repeating_modules:use-module clicked:repeating_systems:use-system', let toSet = {} - let rollBase = `/w ${attrs.character_name} &{template:info}{{info= You activated ${attrs[prefix+'name']} for `; + let rollBase = `/w ${attrs.character_name} &{template:info}{{name=${attrs.character_name}}}{{info= You activated ${attrs[prefix+'name']} for `; if(heat !== 0) { rollBase += `${heat} heat and ` toSet.heat = overheat.resultingHeat; @@ -697,7 +711,7 @@ on('clicked:repeating_modules:use-module clicked:repeating_systems:use-system', asw.setAttrs(toSet); - let roll = await startRoll(rollBase); + let roll = await startRoll(rollBase + overheat.queryMod); finishRoll(roll.rollId, {}); }); @@ -727,31 +741,35 @@ const push = async (ev, template) => { }); } -const overheatCheck = async (heatchange) => { - - console.log(heatchange); +const overheatCheck = async (heatchange, heatspike) => { let attrs = await asw.getAttrs(['heat', 'heat_max']); let resultingHeat = parseInt(attrs.heat) + parseInt(heatchange); + let queryMod = ''; + + if(heatspike === 'on') { + queryMod = `{{heat=[[${resultingHeat}]]}}{{heatspike=[[1d20]]}}`; + } + if(resultingHeat > parseInt(attrs.heat_max)) { return { resultingHeat: parseInt(attrs.heat), - queryMod: '{{toMuchHeat=[[1]]}}' + queryMod: queryMod + '{{toMuchHeat=[[1]]}}' } } if(resultingHeat === parseInt(attrs.heat_max)) { return { resultingHeat: resultingHeat, - queryMod: `{{heatroll=[[1d20]]}}{{heat=[[${resultingHeat}]]}}{{toMuchHeat=[[0]]}}`, + queryMod: queryMod + `{{heatroll=[[1d20]]}}{{heat=[[${resultingHeat}]]}}{{toMuchHeat=[[0]]}}`, } } return { resultingHeat: resultingHeat, - queryMod: '{{toMuchHeat=[[0]]}}', + queryMod: queryMod +'{{toMuchHeat=[[0]]}}', } } @@ -1055,7 +1073,7 @@ const asw = (() => { {{/^rollWasCrit() roll}} - {{#heat}} + {{#heatroll}}
@@ -1066,23 +1084,41 @@ const asw = (() => { Heat Check: {{heat}} vs {{heatroll}} - {{/heat}} + {{/heatroll}} + {{#heatspike}} + + +
+ + + + + Heat Spike: {{heat}} vs {{heatspike}} + + + {{/heatspike}} {{/rollTotal() toMuchHeat 0}} {{#mech}}
{{#rollTotal() toMuchHeat 0}} - {{#rollTotal() heatroll 0}} + {{#pushable}}
- [Push](~{{name}}|reactPush) + [Push](~{{name}}|reactPushWeapon)
- {{/rollTotal() heatroll 0}} + {{/pushable}} - {{#^rollGreater() heatroll heat}} + {{#^rollGreater() heatspike heat}}
[Reactor Overload](~{{name}}|reactOverload)
- {{/^rollGreater() heatroll heat}} + {{/^rollGreater() heatspike heat}} + + {{#^rollGreater() heatspike heat}} +
+ [Heat Spike](~{{name}}|reactOverload) +
+ {{/^rollGreater() heatspike heat}} {{/rollTotal() toMuchHeat 0}}
{{/mech}} @@ -1154,7 +1190,7 @@ const asw = (() => { {{/^rollTotal() weaponheat 0}} - {{#heat}} + {{#heatroll}}
@@ -1165,23 +1201,41 @@ const asw = (() => { Heat Check: {{heat}} vs {{heatroll}} - {{/heat}} + {{/heatroll}} + {{#heatspike}} + + +
+ + + + + Heat Spike: {{heat}} vs {{heatspike}} + + + {{/heatspike}} {{/rollTotal() toMuchHeat 0}} {{#mech}}
{{#rollTotal() toMuchHeat 0}} - {{#rollTotal() heatroll 0}} + {{#pushable}}
[Push](~{{name}}|reactPushWeapon)
- {{/rollTotal() heatroll 0}} + {{/pushable}} {{#^rollGreater() heatroll heat}}
[Reactor Overload](~{{name}}|reactOverload)
{{/^rollGreater() heatroll heat}} + + {{#^rollGreater() heatspike heat}} +
+ [Heat Spike](~{{name}}|reactOverload) +
+ {{/^rollGreater() heatspike heat}} {{/rollTotal() toMuchHeat 0}}
{{/mech}} @@ -1307,5 +1361,30 @@ const asw = (() => {
{{info}} +
+ {{#heatroll}} +
+ Heat Check: {{heat}} vs {{heatroll}} + {{/heatroll}} + {{#heatspike}} +
+ Heat Spike: {{heat}} vs {{heatspike}} + {{/heatspike}} +

+
+ {{#rollTotal() toMuchHeat 0}} + {{#^rollGreater() heatroll heat}} +
+ [Reactor Overload](~{{name}}|reactOverload) +
+ {{/^rollGreater() heatroll heat}} + + {{#^rollGreater() heatspike heat}} +
+ [Heat Spike](~{{name}}|reactOverload) +
+ {{/^rollGreater() heatspike heat}} + {{/rollTotal() toMuchHeat 0}} +
\ No newline at end of file From 847d50eb5afb7e443516feee3c55d510033386fd Mon Sep 17 00:00:00 2001 From: Stexinator Date: Thu, 30 Mar 2023 08:54:03 +0200 Subject: [PATCH 4/7] [SalvageUnion] import heatspike --- SalvageUnion/SalvageUnion.html | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/SalvageUnion/SalvageUnion.html b/SalvageUnion/SalvageUnion.html index ff005a4e7b..cbbfdfb7cd 100644 --- a/SalvageUnion/SalvageUnion.html +++ b/SalvageUnion/SalvageUnion.html @@ -87,10 +87,10 @@
- + - @@ -249,10 +249,10 @@
- + -
@@ -475,10 +475,10 @@
- + -
@@ -859,7 +859,7 @@ on('clicked:import-mech-weapon', async (ev) => { toImport = toImport.replaceAll(/[\r\n]/gm, '#').split('#'); - weapon[row + "weaponname"] = toImport[0]; + weapon[row + "name"] = toImport[0]; weapon[row + "range"] = toImport[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim(); weapon[row + "damage"] = toImport[1].split('//')[1].replaceAll(/[a-zA-Z]*:/g, '').trim(); @@ -869,6 +869,9 @@ on('clicked:import-mech-weapon', async (ev) => { else { weapon[row + "heat"] = 0; } + if(toImport[1].includes("Heat Spike")) { + weapon[row + "heatspike"] = "on"; + } weapon[row + "weapondetails"] = toImport[1].split('//').slice(2).join('//').trim() + "\n" + toImport.slice(2).join(' ').trim(); weapon["importerText"] ='Values imported' @@ -899,6 +902,10 @@ on('clicked:import-mech-system', async (ev) => { rules = rules.split('//').slice(1).join('//').trim() } + if(rules.includes("Heat Spike")) { + system[row + "heatspike"] = "on"; + } + if(/T\d/.test(toImport)) { let tier = toImport.match(/T\d/).pop(); @@ -940,6 +947,10 @@ let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).imp rules = rules.split('//').slice(1).join('//').trim() } + if(rules.includes("Heat Spike")) { + module[row + "heatspike"] = "on"; + } + if(/T\d/.test(toImport)) { let tier = toImport.match(/T\d/).pop(); From 082562234e9b50aa18304763aac0c1d025618f6b Mon Sep 17 00:00:00 2001 From: Stexinator Date: Thu, 30 Mar 2023 12:30:57 +0200 Subject: [PATCH 5/7] [SalvageUnion] formatting --- SalvageUnion/SalvageUnion.html | 227 ++++++++++++++++----------------- 1 file changed, 113 insertions(+), 114 deletions(-) diff --git a/SalvageUnion/SalvageUnion.html b/SalvageUnion/SalvageUnion.html index cbbfdfb7cd..ccb5c16e5d 100644 --- a/SalvageUnion/SalvageUnion.html +++ b/SalvageUnion/SalvageUnion.html @@ -805,179 +805,178 @@ on('clicked:downtime', async (ev) => { on('clicked:import-mech-stats', async (ev) => { - let mech = {}; + let mech = {}; - let toImport = (await asw.getAttrs(['importerText'])).importerText; - let stats = toImport.replaceAll(/[a-zA-Z]/g, '').replaceAll(/\./g, '').replaceAll(/^\s*[\r\n]/gm, '').trim().split(/\r?\n|\s+/); + let toImport = (await asw.getAttrs(['importerText'])).importerText; + let stats = toImport.replaceAll(/[a-zA-Z]/g, '').replaceAll(/\./g, '').replaceAll(/^\s*[\r\n]/gm, '').trim().split(/\r?\n|\s+/); - if(stats.length < 6) { - asw.setAttrs({ - importerText: 'Could not parse input: Not enough values' - }); - return; - } + if(stats.length < 6) { + asw.setAttrs({ + importerText: 'Could not parse input: Not enough values' + }); + return; + } - if(!toImport.startsWith(' ') && !/^\d+/g.test(toImport)) { - let name = toImport.split(/\r?\n/)[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); - mech.character_name = name; - mech.chassis = name; - } + if(!toImport.startsWith(' ') && !/^\d+/g.test(toImport)) { + let name = toImport.split(/\r?\n/)[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); + mech.character_name = name; + mech.chassis = name; + } - if(/CHASSIS\s*ABILITY/.test(toImport)) { - mech.chassisDetails = toImport.split(/CHASSIS\s*ABILITY/)[1].replaceAll(/[\r\n]/gm, '').trim(); - } + if(/CHASSIS\s*ABILITY/.test(toImport)) { + mech.chassisDetails = toImport.split(/CHASSIS\s*ABILITY/)[1].replaceAll(/[\r\n]/gm, '').trim(); + } - mech.structure = stats[0]; - mech.structure_max = stats[0]; - mech.energy = stats[1]; - mech.energy_max = stats[1]; - mech.heat_max = stats[2]; - mech.systems_max = stats[3]; - mech.modules_max = stats[4]; - mech.maxcargo = stats[5]; - mech.importerText = "Values imported"; + mech.structure = stats[0]; + mech.structure_max = stats[0]; + mech.energy = stats[1]; + mech.energy_max = stats[1]; + mech.heat_max = stats[2]; + mech.systems_max = stats[3]; + mech.modules_max = stats[4]; + mech.maxcargo = stats[5]; + mech.importerText = "Values imported"; - await asw.setAttrs(mech); + await asw.setAttrs(mech); }); on('clicked:import-mech-weapon', async (ev) => { - let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).importerText); + let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).importerText); - var row = "repeating_mechweapons_" + generateRowID() + "_"; - let weapon = {}; + var row = "repeating_mechweapons_" + generateRowID() + "_"; + let weapon = {}; - if(/T\d/.test(toImport)) { - let tier = toImport.match(/T\d/).pop(); + if(/T\d/.test(toImport)) { + let tier = toImport.match(/T\d/).pop(); - let associatedCost = toImport.split(/T\d/)[1].trim().split(/\r?\n|\s+/) - weapon[row + "scrap"] = associatedCost[1] + " " + tier; - weapon[row + "slots"] = parseInt(associatedCost[0]); + let associatedCost = toImport.split(/T\d/)[1].trim().split(/\r?\n|\s+/) + weapon[row + "scrap"] = associatedCost[1] + " " + tier; + weapon[row + "slots"] = parseInt(associatedCost[0]); - toImport = toImport.split(/T\d/)[0].trim() - } + toImport = toImport.split(/T\d/)[0].trim() + } - toImport = toImport.replaceAll(/[\r\n]/gm, '#').split('#'); + toImport = toImport.replaceAll(/[\r\n]/gm, '#').split('#'); - weapon[row + "name"] = toImport[0]; - weapon[row + "range"] = toImport[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim(); - weapon[row + "damage"] = toImport[1].split('//')[1].replaceAll(/[a-zA-Z]*:/g, '').trim(); + weapon[row + "name"] = toImport[0]; + weapon[row + "range"] = toImport[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim(); + weapon[row + "damage"] = toImport[1].split('//')[1].replaceAll(/[a-zA-Z]*:/g, '').trim(); - if(toImport[1].includes("Hot (")) { - weapon[row + "heat"] = toImport[1].match(/Hot \(\d\)/g).pop().match(/\d+/).pop(); - } - else { - weapon[row + "heat"] = 0; - } - if(toImport[1].includes("Heat Spike")) { - weapon[row + "heatspike"] = "on"; - } + if(toImport[1].includes("Hot (")) { + weapon[row + "heat"] = toImport[1].match(/Hot \(\d\)/g).pop().match(/\d+/).pop(); + } + else { + weapon[row + "heat"] = 0; + } + if(toImport[1].includes("Heat Spike")) { + weapon[row + "heatspike"] = "on"; + } - weapon[row + "weapondetails"] = toImport[1].split('//').slice(2).join('//').trim() + "\n" + toImport.slice(2).join(' ').trim(); - weapon["importerText"] ='Values imported' + weapon[row + "weapondetails"] = toImport[1].split('//').slice(2).join('//').trim() + "\n" + toImport.slice(2).join(' ').trim(); + weapon["importerText"] ='Values imported' - asw.setAttrs(weapon); + asw.setAttrs(weapon); }); on('clicked:import-mech-system', async (ev) => { - let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).importerText); + let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).importerText); - var row = "repeating_systems_" + generateRowID() + "_"; - let system = {}; + var row = "repeating_systems_" + generateRowID() + "_"; + let system = {}; - system[row + "name"] = toImport.split(/\r?\n/)[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); + system[row + "name"] = toImport.split(/\r?\n/)[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); - if(toImport.split(/\r?\n/)[1].includes("EP")) { - system[row + "cost"] = toImport.split(/\r?\n/)[1].trim(); - toImport = toImport.replaceAll(toImport.split(/\r?\n/)[1], ''); - } + if(toImport.split(/\r?\n/)[1].includes("EP")) { + system[row + "cost"] = toImport.split(/\r?\n/)[1].trim(); + toImport = toImport.replaceAll(toImport.split(/\r?\n/)[1], ''); + } - toImport = toImport.replaceAll(/^\s*[\r\n]/gm, ''); + toImport = toImport.replaceAll(/^\s*[\r\n]/gm, ''); - let rules = toImport.split(/\r?\n/)[1].trim(); + let rules = toImport.split(/\r?\n/)[1].trim(); - if(rules.includes("Range:")) { - system[row + "range"] = rules.split('Range:')[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim() - rules = rules.split('//').slice(1).join('//').trim() - } + if(rules.includes("Range:")) { + system[row + "range"] = rules.split('Range:')[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim() + rules = rules.split('//').slice(1).join('//').trim() + } - if(rules.includes("Heat Spike")) { - system[row + "heatspike"] = "on"; - } + if(rules.includes("Heat Spike")) { + system[row + "heatspike"] = "on"; + } - if(/T\d/.test(toImport)) { - let tier = toImport.match(/T\d/).pop(); + if(/T\d/.test(toImport)) { + let tier = toImport.match(/T\d/).pop(); - let associatedCost = toImport.split(/T\d/)[1].trim().split(/\r?\n|\s+/) - system[row + "scrap"] = associatedCost[1] + " " + tier; - system[row + "slots"] = associatedCost[0]; + let associatedCost = toImport.split(/T\d/)[1].trim().split(/\r?\n|\s+/) + system[row + "scrap"] = associatedCost[1] + " " + tier; + system[row + "slots"] = associatedCost[0]; - toImport = toImport.split(/T\d/)[0].trim() - } + toImport = toImport.split(/T\d/)[0].trim() + } - let longtext = toImport.split('\n').slice(2).join('').trim(); - system[row + "details"] = rules + "\n" + longtext; + let longtext = toImport.split('\n').slice(2).join('').trim(); + system[row + "details"] = rules + "\n" + longtext; - system.importerText = 'Values imported' + system.importerText = 'Values imported' - asw.setAttrs(system); + asw.setAttrs(system); }); on('clicked:import-mech-module', async (ev) => { -let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).importerText); + let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).importerText); - var row = "repeating_modules_" + generateRowID() + "_"; - let module = {}; + var row = "repeating_modules_" + generateRowID() + "_"; + let module = {}; - module[row + "name"] = toImport.split(/\r?\n/)[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); + module[row + "name"] = toImport.split(/\r?\n/)[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); - if(toImport.split(/\r?\n/)[1].includes("EP")) { - module[row + "cost"] = toImport.split(/\r?\n/)[1].trim(); - toImport = toImport.replaceAll(toImport.split(/\r?\n/)[1], ''); - } + if(toImport.split(/\r?\n/)[1].includes("EP")) { + module[row + "cost"] = toImport.split(/\r?\n/)[1].trim(); + toImport = toImport.replaceAll(toImport.split(/\r?\n/)[1], ''); + } - toImport = toImport.replaceAll(/^\s*[\r\n]/gm, ''); + toImport = toImport.replaceAll(/^\s*[\r\n]/gm, ''); - let rules = toImport.split(/\r?\n/)[1].trim(); + let rules = toImport.split(/\r?\n/)[1].trim(); - if(rules.includes("Range:")) { - module[row + "range"] = rules.split('Range:')[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim() - rules = rules.split('//').slice(1).join('//').trim() - } + if(rules.includes("Range:")) { + module[row + "range"] = rules.split('Range:')[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim() + rules = rules.split('//').slice(1).join('//').trim() + } - if(rules.includes("Heat Spike")) { - module[row + "heatspike"] = "on"; - } + if(rules.includes("Heat Spike")) { + module[row + "heatspike"] = "on"; + } - if(/T\d/.test(toImport)) { - let tier = toImport.match(/T\d/).pop(); + if(/T\d/.test(toImport)) { + let tier = toImport.match(/T\d/).pop(); - let associatedCost = toImport.split(/T\d/)[1].trim().split(/\r?\n|\s+/) - module[row + "scrap"] = associatedCost[1] + " " + tier; - module[row + "slots"] = associatedCost[0]; + let associatedCost = toImport.split(/T\d/)[1].trim().split(/\r?\n|\s+/) + module[row + "scrap"] = associatedCost[1] + " " + tier; + module[row + "slots"] = associatedCost[0]; - toImport = toImport.split(/T\d/)[0].trim() - } + toImport = toImport.split(/T\d/)[0].trim() + } - let longtext = toImport.split('\n').slice(2).join('').trim(); - module[row + "details"] = rules + "\n" + longtext; + let longtext = toImport.split('\n').slice(2).join('').trim(); + module[row + "details"] = rules + "\n" + longtext; - module.importerText = 'Values imported' + module.importerText = 'Values imported' - asw.setAttrs(module); + asw.setAttrs(module); }); - -/////////////////// -// HELPER //// -/////////////////// - const removeLineBreakInRules = (toImport) => { return toImport.replaceAll(/\/\/\s*[\r\n]/gm, '// ').replaceAll(/[\r\n]/gm, '#').replaceAll(/#\/\//g, '//').replaceAll(/#/g, '\n') }; +/////////////////// +// HELPER //// +/////////////////// + async function repeatingSum (destination, fieldsum, ...sections){ // destination = the name of the attribute that stores the total // fieldsum = the name of the field to be summed From 791713dbae638ae6a5a3e75d6fd2730c7b2767ed Mon Sep 17 00:00:00 2001 From: Stexinator Date: Thu, 30 Mar 2023 13:51:40 +0200 Subject: [PATCH 6/7] [SalvageUnion] refactor importer --- SalvageUnion/SalvageUnion.html | 226 ++++++++++++++++++--------------- 1 file changed, 127 insertions(+), 99 deletions(-) diff --git a/SalvageUnion/SalvageUnion.html b/SalvageUnion/SalvageUnion.html index ccb5c16e5d..0299d81f33 100644 --- a/SalvageUnion/SalvageUnion.html +++ b/SalvageUnion/SalvageUnion.html @@ -93,7 +93,7 @@ - +
@@ -282,7 +282,7 @@
- + @@ -570,7 +570,7 @@
Importer - + @@ -656,8 +656,6 @@ on('clicked:repeating_mechweapons:roll', let attrs = await asw.getAttrs([prefix+'heat', prefix+'heatspike']); let overheat = await overheatCheck( attrs[prefix+'heat'], attrs[prefix+'heatspike']); - console.log(overheat); - let rollPart = event.htmlAttributes.value.replaceAll('prefix-', `${prefix}`); let results = await startRoll(rollPart + overheat.queryMod); @@ -842,136 +840,166 @@ on('clicked:import-mech-stats', async (ev) => { on('clicked:import-mech-weapon', async (ev) => { - let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).importerText); + let toImport = formatImporterText((await asw.getAttrs(['importerText'])).importerText); var row = "repeating_mechweapons_" + generateRowID() + "_"; let weapon = {}; - if(/T\d/.test(toImport)) { - let tier = toImport.match(/T\d/).pop(); + toImport = importName(toImport, weapon, row); + toImport = importCost(toImport, weapon, row); - let associatedCost = toImport.split(/T\d/)[1].trim().split(/\r?\n|\s+/) - weapon[row + "scrap"] = associatedCost[1] + " " + tier; - weapon[row + "slots"] = parseInt(associatedCost[0]); + let rules = toImport.split(/\r?\n/)[0].trim(); + rules = importRange(rules, weapon, row); + rules = importDamage(rules, weapon, row); - toImport = toImport.split(/T\d/)[0].trim() - } + importHeat(rules, weapon, row); + importDetails(rules, toImport, weapon, row); - toImport = toImport.replaceAll(/[\r\n]/gm, '#').split('#'); - - weapon[row + "name"] = toImport[0]; - weapon[row + "range"] = toImport[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim(); - weapon[row + "damage"] = toImport[1].split('//')[1].replaceAll(/[a-zA-Z]*:/g, '').trim(); - - if(toImport[1].includes("Hot (")) { - weapon[row + "heat"] = toImport[1].match(/Hot \(\d\)/g).pop().match(/\d+/).pop(); - } - else { - weapon[row + "heat"] = 0; - } - if(toImport[1].includes("Heat Spike")) { - weapon[row + "heatspike"] = "on"; - } - - weapon[row + "weapondetails"] = toImport[1].split('//').slice(2).join('//').trim() + "\n" + toImport.slice(2).join(' ').trim(); weapon["importerText"] ='Values imported' asw.setAttrs(weapon); }); on('clicked:import-mech-system', async (ev) => { - - let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).importerText); - - var row = "repeating_systems_" + generateRowID() + "_"; - let system = {}; - - system[row + "name"] = toImport.split(/\r?\n/)[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); - - if(toImport.split(/\r?\n/)[1].includes("EP")) { - system[row + "cost"] = toImport.split(/\r?\n/)[1].trim(); - toImport = toImport.replaceAll(toImport.split(/\r?\n/)[1], ''); - } - - toImport = toImport.replaceAll(/^\s*[\r\n]/gm, ''); - - let rules = toImport.split(/\r?\n/)[1].trim(); - - if(rules.includes("Range:")) { - system[row + "range"] = rules.split('Range:')[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim() - rules = rules.split('//').slice(1).join('//').trim() - } - - if(rules.includes("Heat Spike")) { - system[row + "heatspike"] = "on"; - } - - if(/T\d/.test(toImport)) { - let tier = toImport.match(/T\d/).pop(); - - let associatedCost = toImport.split(/T\d/)[1].trim().split(/\r?\n|\s+/) - system[row + "scrap"] = associatedCost[1] + " " + tier; - system[row + "slots"] = associatedCost[0]; - - toImport = toImport.split(/T\d/)[0].trim() - } - - let longtext = toImport.split('\n').slice(2).join('').trim(); - system[row + "details"] = rules + "\n" + longtext; - - system.importerText = 'Values imported' - - asw.setAttrs(system); + importModuleSystem("systems"); }); on('clicked:import-mech-module', async (ev) => { + importModuleSystem("modules"); +}); - let toImport = removeLineBreakInRules((await asw.getAttrs(['importerText'])).importerText); +const importModuleSystem = async (type) => { + let toImport = formatImporterText((await asw.getAttrs(['importerText'])).importerText); - var row = "repeating_modules_" + generateRowID() + "_"; - let module = {}; + let row = "repeating_" + type + "_" + generateRowID() + "_"; + let object = {}; - module[row + "name"] = toImport.split(/\r?\n/)[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); + toImport = importName(toImport, object, row); + toImport = importCost(toImport, object, row); - if(toImport.split(/\r?\n/)[1].includes("EP")) { - module[row + "cost"] = toImport.split(/\r?\n/)[1].trim(); - toImport = toImport.replaceAll(toImport.split(/\r?\n/)[1], ''); - } + toImport = importEp(toImport, object, row); + let rules = toImport.split(/\r?\n/)[0].trim(); - toImport = toImport.replaceAll(/^\s*[\r\n]/gm, ''); + rules = importAction(rules, object, row); + rules = importRange(rules, object, row); - let rules = toImport.split(/\r?\n/)[1].trim(); - - if(rules.includes("Range:")) { - module[row + "range"] = rules.split('Range:')[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim() + if(rules.includes("Passive")) { + object[row + "is-passive"] = "on"; rules = rules.split('//').slice(1).join('//').trim() } - if(rules.includes("Heat Spike")) { - module[row + "heatspike"] = "on"; + importHeat(rules, object, row); + importDetails(rules, toImport, object, row); + + object.importerText = 'Values imported' + + asw.setAttrs(object); +}; + +const formatImporterText = (toImport) => { + let formatted = toImport.replaceAll(/\/\/\s*[\r\n]/gm, '// ').replaceAll(/[\r\n]/gm, '#').replaceAll(/#\/\//g, '//').replaceAll(/#/g, '\n').replaceAll(/^\s*\n/gm,''); + + let multilineName = formatted.split(/\r?\n/); + if(multilineName[2].includes("Range") || multilineName[2].includes("Passive") || multilineName[2].includes("EP")) { + formatted = multilineName.slice(0,2).join(' ') + "\n" + multilineName.slice(2).join("\n"); } - if(/T\d/.test(toImport)) { + let multilineRules = formatted.split(/\r?\n/); + if(multilineRules[2].includes("//") && !multilineRules[1].includes("EP")) { + formatted = multilineRules[0] + "\n" + multilineRules.slice(1,3).join('') + "\n" + multilineRules.slice(3).join("\n"); + } + + return formatted; +}; + +const importName = (toImport, object, row) => { + let textSplits = toImport.split(/\r?\n/); + object[row + "name"] = textSplits[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); + + return textSplits.slice(1).join('\n'); +}; + +const importCost = (toImport, object, row) => { + if(/T\d/.test(toImport)) { let tier = toImport.match(/T\d/).pop(); let associatedCost = toImport.split(/T\d/)[1].trim().split(/\r?\n|\s+/) - module[row + "scrap"] = associatedCost[1] + " " + tier; - module[row + "slots"] = associatedCost[0]; + object[row + "scrap"] = associatedCost[1] + " " + tier; + object[row + "slots"] = parseInt(associatedCost[0]); - toImport = toImport.split(/T\d/)[0].trim() + return toImport.split(/T\d/)[0].trim() } - let longtext = toImport.split('\n').slice(2).join('').trim(); - module[row + "details"] = rules + "\n" + longtext; + return toImport; +} - module.importerText = 'Values imported' +const importEp = (toImport, object, row) => { - asw.setAttrs(module); -}); + if(toImport.split(/\r?\n/)[0].includes("EP")) { + object[row + "cost"] = toImport.split(/\r?\n/)[0].trim(); + return toImport.split(/\r?\n/).slice(1).join("\n"); + } + return toImport; +} -const removeLineBreakInRules = (toImport) => { - return toImport.replaceAll(/\/\/\s*[\r\n]/gm, '// ').replaceAll(/[\r\n]/gm, '#').replaceAll(/#\/\//g, '//').replaceAll(/#/g, '\n') -}; +const importRange = (rules, object, row) => { + if(rules.includes("Range:")) { + object[row + "range"] = rules.split('Range:')[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim() + let index = rules.split(' // ').indexOf('Range: '+ object[row + "range"]); + rules = rules.split(' // '); + rules.splice(index, 1); + return rules.join(' // ').trim() + } + + return rules; +} + +const importDamage = (rules, object, row) => { + if(rules.includes("Damage:")) { + let damage = rules.split('Damage:')[1].split('//')[0].replaceAll(/[a-zA-Z]*:/g, '').trim(); + if(damage.match(/\d+[d]\d+/g)) { + damage = "[[" + damage + "]]"; + } + object[row + "damage"] = damage; + return rules.split('//').slice(1).join('//').trim() + } + + return rules; +} + +const importAction = (rules, object, row) => { + + if(rules.includes("Reaction")) { + object[row + "action"] = "Reaction"; + return rules.replaceAll("Reaction //", '').replaceAll("Reaction", '').trim(); + } + + if(rules.includes("Turn Action")) { + object[row + "action"] = "Turn Action"; + return rules.replaceAll("Turn Action //", '').replaceAll("Turn Action", '').trim(); + } + + return rules; +} + +const importHeat = (rules, object, row) => { + + if(rules.includes("Hot (")) { + object[row + "heat"] = rules.match(/Hot \(\d\)/g).pop().match(/\d+/).pop(); + } + else { + object[row + "heat"] = 0; + } + + if(rules.includes("Heat Spike")) { + object[row + "heatspike"] = "on"; + } +} + +const importDetails = (rules, toImport, object, row) => { + let longtext = toImport.split('\n').slice(1).join('').trim(); + object[row + "details"] = rules + "\n" + longtext; +} /////////////////// // HELPER //// From 3f41eccd65cdcd1fa61030b305059098bea3c562 Mon Sep 17 00:00:00 2001 From: Stexinator Date: Sun, 2 Apr 2023 20:36:03 +0200 Subject: [PATCH 7/7] [SalvageUnion] import multi EP items as single items --- SalvageUnion/SalvageUnion.html | 48 ++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/SalvageUnion/SalvageUnion.html b/SalvageUnion/SalvageUnion.html index 0299d81f33..2685b09691 100644 --- a/SalvageUnion/SalvageUnion.html +++ b/SalvageUnion/SalvageUnion.html @@ -329,7 +329,7 @@
- +
@@ -391,7 +391,7 @@
- +
@@ -861,19 +861,27 @@ on('clicked:import-mech-weapon', async (ev) => { }); on('clicked:import-mech-system', async (ev) => { - importModuleSystem("systems"); + importFromImporter("systems"); }); on('clicked:import-mech-module', async (ev) => { - importModuleSystem("modules"); + importFromImporter("modules"); }); -const importModuleSystem = async (type) => { +const importFromImporter = async(type) => { let toImport = formatImporterText((await asw.getAttrs(['importerText'])).importerText); + await importModuleSystem(type, toImport); +} + +const importModuleSystem = async (type, toImport) => { let row = "repeating_" + type + "_" + generateRowID() + "_"; let object = {}; + if(checkForMultipleEP(toImport)) { + importMultipleEp(type, toImport); + } + toImport = importName(toImport, object, row); toImport = importCost(toImport, object, row); @@ -896,6 +904,22 @@ const importModuleSystem = async (type) => { asw.setAttrs(object); }; +const importMultipleEp = async (type, toImport) => { + let template = {}; + let name = importName(toImport, template, ''); + //remove cost + toImport = importCost(toImport, template, ''); + + let splitByEp = toImport.split(/(?=^\dEP|XEP)/gm).slice(1); + + for (const ability of splitByEp) { + let perLine = ability.split(/\r?\n/g); + let firstLine = perLine[0].split(/\s+/g); + let importerText = template.name + " "+ firstLine[1] + "\n" + firstLine[0] + "\n" + perLine.slice(1).join("\n"); + await importModuleSystem(type, importerText); + } +} + const formatImporterText = (toImport) => { let formatted = toImport.replaceAll(/\/\/\s*[\r\n]/gm, '// ').replaceAll(/[\r\n]/gm, '#').replaceAll(/#\/\//g, '//').replaceAll(/#/g, '\n').replaceAll(/^\s*\n/gm,''); @@ -912,6 +936,10 @@ const formatImporterText = (toImport) => { return formatted; }; +const checkForMultipleEP = (toImport) => { + return (toImport.match(/^\dEP|XEP/gm) || []).length > 1; +} + const importName = (toImport, object, row) => { let textSplits = toImport.split(/\r?\n/); object[row + "name"] = textSplits[0].trim().replace(/(\w)(\w*)/g, (_, firstChar, rest) => firstChar + rest.toLowerCase()); @@ -979,6 +1007,16 @@ const importAction = (rules, object, row) => { return rules.replaceAll("Turn Action //", '').replaceAll("Turn Action", '').trim(); } + if(rules.includes("Short Action")) { + object[row + "action"] = "Short Action"; + return rules.replaceAll("Short Action //", '').replaceAll("Short Action", '').trim(); + } + + if(rules.includes("Long Action")) { + object[row + "action"] = "Long Action"; + return rules.replaceAll("Long Action //", '').replaceAll("Long Action", '').trim(); + } + return rules; }