From 87089190fc57f25ea2b06e11a0360eaa5c9c13c0 Mon Sep 17 00:00:00 2001 From: uriele Date: Sat, 14 Sep 2024 23:59:12 +0200 Subject: [PATCH] fix versioning 2.04 bonds updated with CHA instead of WP also if value of bond is >CHA and previous value of bond>CHA, keeps it, otherwise set it to CHA --- Delta Green 2/deltagreen.html | 67 +++++++++++++++---- .../src/js/sheetworkers_constants.dev.js | 2 +- .../src/js/sheetworkers_constants.js | 1 + .../src/js/sheetworkers_helpers.dev.js | 14 ++-- Delta Green 2/src/js/sheetworkers_helpers.js | 15 +++-- .../src/js/sheetworkers_versioning.dev.js | 60 +++++++++++------ .../src/js/sheetworkers_versioning.js | 51 ++++++++++++-- 7 files changed, 155 insertions(+), 55 deletions(-) diff --git a/Delta Green 2/deltagreen.html b/Delta Green 2/deltagreen.html index 4cebca19472d..ff3518e039bc 100644 --- a/Delta Green 2/deltagreen.html +++ b/Delta Green 2/deltagreen.html @@ -4769,6 +4769,7 @@

{{#subheader}}({{subheader}}%){{/subheader}}

const _score_info = [ `willpower_points_max`, + `charisma_score`, `character_creation_bonds`, `repeating_bonds_setScore`, `repeating_bonds_score`, @@ -5361,24 +5362,25 @@

{{#subheader}}({{subheader}}%){{/subheader}}

const updatebondscore = (values,update,manualscore=true) => { const character_creation_bonds = values[`character_creation_bonds`] === 'active' ? true : false; - const willpower_points_max = parseInt(values.willpower_points_max) || 0; - const initial_willpower = (character_creation_bonds) ? willpower_points_max : Math.floor(willpower_points_max/2); + const charisma_score = parseInt(values[`charisma_score`]) || 0; + const bond_value = (character_creation_bonds) ? charisma_score : Math.floor(charisma_score/2); const flag = (manualscore) ? 1 : parseInt(values[`repeating_bonds_setScore`]) || 0; const bond_score_old = parseInt(values[`repeating_bonds_score_old`]) || 0; var bond_score = 0; if (flag === 0) { - bond_score = initial_willpower; + bond_score = bond_value; } else { bond_score = parseInt(values[`repeating_bonds_score`]) || 0; - if (bond_score > willpower_points_max) { - if (willpower_points_max > bond_score_old) { - bond_score = willpower_points_max; + if (bond_score > charisma_score) { + if (bond_score_old<= charisma_score) { + bond_score = charisma_score; } + } } update[`repeating_bonds_score`] = bond_score; - update[`repeating_bonds_score_old`] = bond_score_old; + update[`repeating_bonds_score_old`] = bond_score; update[`repeating_bonds_setScore`] = 1; update[`repeating_bonds_color`] = BondButtonColor(bond_score); } @@ -5815,24 +5817,27 @@

{{#subheader}}({{subheader}}%){{/subheader}}

if (version < 1.05) { version_0_105(); } - if (version <1.5) { + else if (version <1.5) { version_105_150(); } - if (version<1.7) { + else if (version<1.7) { version_150_170(); } - if (version<2.0) { + else if (version<2.0) { version_170_200(); } - if (version<2.01) { + else if (version<2.01) { version_200_201(); } - if (version<2.02) { + else if (version<2.02) { version_201_202(); } - if (version<2.03) { + else if (version<2.03) { version_202_203(); } + else if (version<2.04) { + version_203_204(); + } }; // UPDATE TO VERSION 1.05 @@ -6126,7 +6131,7 @@

{{#subheader}}({{subheader}}%){{/subheader}}

const old_named_skills=['art','craft','pilot','military_science','science']; const old_adaptation = ['violence_1','violence_2','violence_3','helplessness_1','helplessness_2','helplessness_3']; const old_named_skills_names=old_named_skills.map(x=> `${x}_name`) - getAttrs(old_adaptation.concat(old_named_skills_names).concat(old_named_skills),(values) =>{ + getAttrs(old_adaptation.concat(old_named_skills_names).concat(old_named_skills).concat(['willpower_points_max','charisma_score']),(values) =>{ if (values.hasOwnProperty('art_name')){ const art_value=setMinMax(values[`art`]); const art_name = values[`art_name`]; @@ -6184,12 +6189,46 @@

{{#subheader}}({{subheader}}%){{/subheader}}

update[`helplessness`] = helplessness; if (helplessness ==2) {update[`helplessness_adapted`]==1} } + setAttrs(update, {silent:true}, () => { console.log('updated named skills and adaptations'); versioning(codeversion); console.info(update); }); + }); +}; + +const version_203_204= () => { + const codeversion = 2.04; + const update ={}; + console.log('verion:',codeversion); + update['version'] = codeversion; + + getAttrs(['willpower_points_max','charisma_score'],values => { + getSectionIDs('bonds',ids => { + const repfields=[]; + ids.forEach(id => { + repfields.push(`repeating_bonds_${id}_score`); + }); + getAttrs(repfields,bond_values => { + const willpower_points_max=values['willpower_points_max']; + const charisma_score = values['charisma_score']; + + repfields.forEach(field => { + if ((parseInt(bond_values[field])||0)>=willpower_points_max){ + update[field]=charisma_score; + update[`${field}_old`]=charisma_score; + } + }); + setAttrs(update, {silent:true}, () => { + console.log('updated named skills and adaptations'); + versioning(codeversion); + console.info(update); + }); + + }); + }); }); }; diff --git a/Delta Green 2/src/js/sheetworkers_constants.dev.js b/Delta Green 2/src/js/sheetworkers_constants.dev.js index b21471eb37c4..38d82d669830 100644 --- a/Delta Green 2/src/js/sheetworkers_constants.dev.js +++ b/Delta Green 2/src/js/sheetworkers_constants.dev.js @@ -95,7 +95,7 @@ var _repeating_sections = { 'weapons': 'weapons', 'ritual': 'rituals' }; -var _score_info = ["willpower_points_max", "character_creation_bonds", "repeating_bonds_setScore", "repeating_bonds_score", "repeating_bonds_score_old", "repeating_bonds_color"]; +var _score_info = ["willpower_points_max", "charisma_score", "character_creation_bonds", "repeating_bonds_setScore", "repeating_bonds_score", "repeating_bonds_score_old", "repeating_bonds_color"]; var _bond_attributes = ["name", "test", "score", "hurt"]; var _repeating_damages = ['damage', 'damage_critical', 'lethality_percent', 'lethality_percent_critical', 'double_barrel', 'double_barrel_critical', 'selective_fire', 'selective_fire_critical']; var _repeating_ammo = ['hasammo', 'ammo', 'ammo_total']; diff --git a/Delta Green 2/src/js/sheetworkers_constants.js b/Delta Green 2/src/js/sheetworkers_constants.js index ca9e3cdb8ec7..0f3cbec421cb 100644 --- a/Delta Green 2/src/js/sheetworkers_constants.js +++ b/Delta Green 2/src/js/sheetworkers_constants.js @@ -70,6 +70,7 @@ const _repeating_sections={ const _score_info = [ `willpower_points_max`, + `charisma_score`, `character_creation_bonds`, `repeating_bonds_setScore`, `repeating_bonds_score`, diff --git a/Delta Green 2/src/js/sheetworkers_helpers.dev.js b/Delta Green 2/src/js/sheetworkers_helpers.dev.js index d8a15740dedc..fbc4e72e89d6 100644 --- a/Delta Green 2/src/js/sheetworkers_helpers.dev.js +++ b/Delta Green 2/src/js/sheetworkers_helpers.dev.js @@ -699,26 +699,26 @@ var addTargetStat = function addTargetStat(values, names, attrName) { var updatebondscore = function updatebondscore(values, update) { var manualscore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; var character_creation_bonds = values["character_creation_bonds"] === 'active' ? true : false; - var willpower_points_max = parseInt(values.willpower_points_max) || 0; - var initial_willpower = character_creation_bonds ? willpower_points_max : Math.floor(willpower_points_max / 2); + var charisma_score = parseInt(values["charisma_score"]) || 0; + var bond_value = character_creation_bonds ? charisma_score : Math.floor(charisma_score / 2); var flag = manualscore ? 1 : parseInt(values["repeating_bonds_setScore"]) || 0; var bond_score_old = parseInt(values["repeating_bonds_score_old"]) || 0; var bond_score = 0; if (flag === 0) { - bond_score = initial_willpower; + bond_score = bond_value; } else { bond_score = parseInt(values["repeating_bonds_score"]) || 0; - if (bond_score > willpower_points_max) { - if (willpower_points_max > bond_score_old) { - bond_score = willpower_points_max; + if (bond_score > charisma_score) { + if (bond_score_old <= charisma_score) { + bond_score = charisma_score; } } } update["repeating_bonds_score"] = bond_score; - update["repeating_bonds_score_old"] = bond_score_old; + update["repeating_bonds_score_old"] = bond_score; update["repeating_bonds_setScore"] = 1; update["repeating_bonds_color"] = BondButtonColor(bond_score); }; diff --git a/Delta Green 2/src/js/sheetworkers_helpers.js b/Delta Green 2/src/js/sheetworkers_helpers.js index a9a0360c1419..db405bdabc7a 100644 --- a/Delta Green 2/src/js/sheetworkers_helpers.js +++ b/Delta Green 2/src/js/sheetworkers_helpers.js @@ -474,24 +474,25 @@ const addTargetStat=(values,names,attrName) => { const updatebondscore = (values,update,manualscore=true) => { const character_creation_bonds = values[`character_creation_bonds`] === 'active' ? true : false; - const willpower_points_max = parseInt(values.willpower_points_max) || 0; - const initial_willpower = (character_creation_bonds) ? willpower_points_max : Math.floor(willpower_points_max/2); + const charisma_score = parseInt(values[`charisma_score`]) || 0; + const bond_value = (character_creation_bonds) ? charisma_score : Math.floor(charisma_score/2); const flag = (manualscore) ? 1 : parseInt(values[`repeating_bonds_setScore`]) || 0; const bond_score_old = parseInt(values[`repeating_bonds_score_old`]) || 0; var bond_score = 0; if (flag === 0) { - bond_score = initial_willpower; + bond_score = bond_value; } else { bond_score = parseInt(values[`repeating_bonds_score`]) || 0; - if (bond_score > willpower_points_max) { - if (willpower_points_max > bond_score_old) { - bond_score = willpower_points_max; + if (bond_score > charisma_score) { + if (bond_score_old<= charisma_score) { + bond_score = charisma_score; } + } } update[`repeating_bonds_score`] = bond_score; - update[`repeating_bonds_score_old`] = bond_score_old; + update[`repeating_bonds_score_old`] = bond_score; update[`repeating_bonds_setScore`] = 1; update[`repeating_bonds_color`] = BondButtonColor(bond_score); } diff --git a/Delta Green 2/src/js/sheetworkers_versioning.dev.js b/Delta Green 2/src/js/sheetworkers_versioning.dev.js index 8283b18fa91e..15ed8b1e7a46 100644 --- a/Delta Green 2/src/js/sheetworkers_versioning.dev.js +++ b/Delta Green 2/src/js/sheetworkers_versioning.dev.js @@ -5,30 +5,20 @@ var versioning = function versioning(version) { if (version < 1.05) { version_0_105(); - } - - if (version < 1.5) { + } else if (version < 1.5) { version_105_150(); - } - - if (version < 1.7) { + } else if (version < 1.7) { version_150_170(); - } - - if (version < 2.0) { + } else if (version < 2.0) { version_170_200(); - } - - if (version < 2.01) { + } else if (version < 2.01) { version_200_201(); - } - - if (version < 2.02) { + } else if (version < 2.02) { version_201_202(); - } - - if (version < 2.03) { + } else if (version < 2.03) { version_202_203(); + } else if (version < 2.04) { + version_203_204(); } }; // UPDATE TO VERSION 1.05 @@ -345,7 +335,7 @@ var version_202_203 = function version_202_203() { var old_named_skills_names = old_named_skills.map(function (x) { return "".concat(x, "_name"); }); - getAttrs(old_adaptation.concat(old_named_skills_names).concat(old_named_skills), function (values) { + getAttrs(old_adaptation.concat(old_named_skills_names).concat(old_named_skills).concat(['willpower_points_max', 'charisma_score']), function (values) { if (values.hasOwnProperty('art_name')) { var art_value = setMinMax(values["art"]); var art_name = values["art_name"]; @@ -440,4 +430,36 @@ var version_202_203 = function version_202_203() { console.info(update); }); }); +}; + +var version_203_204 = function version_203_204() { + var codeversion = 2.04; + var update = {}; + console.log('verion:', codeversion); + update['version'] = codeversion; + getAttrs(['willpower_points_max', 'charisma_score'], function (values) { + getSectionIDs('bonds', function (ids) { + var repfields = []; + ids.forEach(function (id) { + repfields.push("repeating_bonds_".concat(id, "_score")); + }); + getAttrs(repfields, function (bond_values) { + var willpower_points_max = values['willpower_points_max']; + var charisma_score = values['charisma_score']; + repfields.forEach(function (field) { + if ((parseInt(bond_values[field]) || 0) >= willpower_points_max) { + update[field] = charisma_score; + update["".concat(field, "_old")] = charisma_score; + } + }); + setAttrs(update, { + silent: true + }, function () { + console.log('updated named skills and adaptations'); + versioning(codeversion); + console.info(update); + }); + }); + }); + }); }; \ No newline at end of file diff --git a/Delta Green 2/src/js/sheetworkers_versioning.js b/Delta Green 2/src/js/sheetworkers_versioning.js index 3119f29f5d72..159d7a5ca5d7 100644 --- a/Delta Green 2/src/js/sheetworkers_versioning.js +++ b/Delta Green 2/src/js/sheetworkers_versioning.js @@ -3,24 +3,27 @@ const versioning = (version) => { if (version < 1.05) { version_0_105(); } - if (version <1.5) { + else if (version <1.5) { version_105_150(); } - if (version<1.7) { + else if (version<1.7) { version_150_170(); } - if (version<2.0) { + else if (version<2.0) { version_170_200(); } - if (version<2.01) { + else if (version<2.01) { version_200_201(); } - if (version<2.02) { + else if (version<2.02) { version_201_202(); } - if (version<2.03) { + else if (version<2.03) { version_202_203(); } + else if (version<2.04) { + version_203_204(); + } }; // UPDATE TO VERSION 1.05 @@ -314,7 +317,7 @@ const version_202_203 = () => { const old_named_skills=['art','craft','pilot','military_science','science']; const old_adaptation = ['violence_1','violence_2','violence_3','helplessness_1','helplessness_2','helplessness_3']; const old_named_skills_names=old_named_skills.map(x=> `${x}_name`) - getAttrs(old_adaptation.concat(old_named_skills_names).concat(old_named_skills),(values) =>{ + getAttrs(old_adaptation.concat(old_named_skills_names).concat(old_named_skills).concat(['willpower_points_max','charisma_score']),(values) =>{ if (values.hasOwnProperty('art_name')){ const art_value=setMinMax(values[`art`]); const art_name = values[`art_name`]; @@ -372,11 +375,45 @@ const version_202_203 = () => { update[`helplessness`] = helplessness; if (helplessness ==2) {update[`helplessness_adapted`]==1} } + setAttrs(update, {silent:true}, () => { console.log('updated named skills and adaptations'); versioning(codeversion); console.info(update); }); + }); +}; +const version_203_204= () => { + const codeversion = 2.04; + const update ={}; + console.log('verion:',codeversion); + update['version'] = codeversion; + + getAttrs(['willpower_points_max','charisma_score'],values => { + getSectionIDs('bonds',ids => { + const repfields=[]; + ids.forEach(id => { + repfields.push(`repeating_bonds_${id}_score`); + }); + getAttrs(repfields,bond_values => { + const willpower_points_max=values['willpower_points_max']; + const charisma_score = values['charisma_score']; + + repfields.forEach(field => { + if ((parseInt(bond_values[field])||0)>=willpower_points_max){ + update[field]=charisma_score; + update[`${field}_old`]=charisma_score; + } + }); + + setAttrs(update, {silent:true}, () => { + console.log('updated named skills and adaptations'); + versioning(codeversion); + console.info(update); + }); + + }); + }); }); }; \ No newline at end of file