diff --git a/AD&D_1E/1ESheet.css b/AD&D_1E/1ESheet.css index 9be99e0a3d..eec9b826b5 100644 --- a/AD&D_1E/1ESheet.css +++ b/AD&D_1E/1ESheet.css @@ -343,4 +343,11 @@ textarea.sheet-macro-text {width:5.5em; resize:vertical; height:1.3em; overflow: .sheet-rolltemplate-general .sheet-savethrow { vertical-align:inherit; font-weight:bold; +} +.sheet-version { + max-width: 3em; + height: 1.5em; + border: none; + background-color: transparent; + text-align: left; } \ No newline at end of file diff --git a/AD&D_1E/1ESheet.html b/AD&D_1E/1ESheet.html index 43e1ac16d3..72c6c85a67 100644 --- a/AD&D_1E/1ESheet.html +++ b/AD&D_1E/1ESheet.html @@ -273,7 +273,7 @@
Weapon
To-Hit Bonus
Magic Bonus -
DMG Bonus +
DMG Bonus /w gm?
-
Macro-Text +
Macro-Text
DMG vs S/M @@ -708,7 +708,10 @@ @@ -1504,4 +1508,90 @@ on('change:normal_load change:heavy_load change:very_heavy_load change:max_load }); }); +var Sheet = Sheet || (function() { + + var version= 1.10, + Debug = false, + +// copy DmgBonus value to AttackDmgBonus + dmgSwap = function() { + getSectionIDs("repeating_weapon", function(idarray) { //Get oldSectionID + var update={}; + _.each(idarray, function(currentID, i) { + getAttrs(['repeating_weapon_' + currentID + '_DmgBonus'], function(v) { //Get oldAttribute from FieldID + update['repeating_weapon_' + currentID + '_AttackDmgBonus'] = v['repeating_weapon_' + currentID + '_DmgBonus']; //replaces old attribute value with new + setAttrs(update,{silent:true}); //Update + }); + }); + }); +// replace all instances of @{DmgBonus} with @{AttackDmgBonus} in macro-text + var update = {}, attrs = []; + getSectionIDs("repeating_weapon", function(idarray) { + _.each(idarray, function(itemid) { + attrs.push("repeating_weapon_" + itemid + "_macro-text"); + }); + getAttrs(attrs, function(v) { + _.each(idarray, function(id) { + update["repeating_weapon_" + id + "_macro-text"] = v["repeating_weapon_" + id + "_macro-text"].replace(new RegExp('@{DmgBonus}', 'g'), '@{AttackDmgBonus}'); + }); + setAttrs(update,{silent:true}); + }); + }); + }, + +/* recalculateSheet */ + recalculateSheet = function(oldversion) { + if (oldversion < 0.1) { +//call your functions here + dmgSwap(); + } + }, + +/* checkForUpdate looks at current version of page in + * sheet_version and compares to code Sheet.version calls + * recalulateSheet if versions don't match or if recalculate + * button was pressed. */ + checkForUpdate = function() { + getAttrs(["sheet_version","sheet_forcesync","recalc1"],function(v){ + var setter={},currVer=0,setAny=0,recalc=false; + currVer=parseFloat(v["sheet_version"],10)||0; + console.log("Current sheet data version:"+currVer+", Sheet code version:" + version ); + + if ( currVer!== version ) { + recalc=true; + setter["sheet_version"]= version; + setAny=1; + } + if (v["recalc1"] && v["recalc1"]!="0" ) { + currVer=-1; + recalc=true; + setter["recalc1"]=0; + setAny=1; + } + if (v["sheet_forcesync"] && v["sheet_forcesync"]!="0" ) { + currVer=-1; + recalc=true; + setter["sheet_forcesync"]=0; + setAny=1; + } + if (setAny) { + setAttrs( setter); + } + if (recalc) { + recalculateSheet(currVer); + } + }); + }; + return { + version:version, + checkForUpdate:checkForUpdate, + dmgSwap:dmgSwap + }; +}()); + +//sheet +on("sheet:opened",function() {Sheet.checkForUpdate();}); +on("change:recalc1",function() {Sheet.checkForUpdate();}); +console.log("...recalc checking for update"); + \ No newline at end of file