adding src

This commit is contained in:
∇ince
2025-01-19 01:16:17 -08:00
parent bceb2d65db
commit fbe4130a35
3 changed files with 2390 additions and 0 deletions
+853
View File
@@ -0,0 +1,853 @@
'use strict';
import _ from 'underscore';
import {PFLog, PFConsole} from './PFLog';
import TAS from './TheAaronSheet.js';
import * as SWUtils from './SWUtils';
import PFConst from './PFConst';
import * as PFUtils from './PFUtils';
import * as PFCustom from './PFCustom';
import * as PFMigrate from './PFMigrate';
import * as PFDefense from './PFDefense';
import * as PFSize from './PFSize';
import * as PFUtilsAsync from './PFUtilsAsync';
import * as PFInitiative from './PFInitiative';
import * as PFSkills from './PFSkills';
import * as PFEncumbrance from './PFEncumbrance';
import * as PFInventory from './PFInventory';
import * as PFAbilityScores from './PFAbilityScores';
import * as PFBuffs from './PFBuffs';
import * as PFSaves from './PFSaves';
import * as PFHealth from './PFHealth';
import * as PFChecks from './PFChecks';
import * as PFAbility from './PFAbility';
import * as PFNPC from './PFNPC';
import * as PFAttackGrid from './PFAttackGrid';
import * as PFAttackOptions from './PFAttackOptions';
import * as PFAttacks from './PFAttacks';
import * as PFFeatures from './PFFeatures';
import * as PFSpells from './PFSpells';
import * as PFSpellCasterClasses from './PFSpellCasterClasses';
import * as PFPsionic from './PFPsionic';
import * as PFMythic from './PFMythic';
import * as PFClassRaceGrid from './PFClassRaceGrid';
import * as PFConditions from './PFConditions';
import * as PFHorror from './PFHorror';
import * as PFOccult from './PFOccult';
import * as PFMacros from './PFMacros';
function expandAll() {
getAttrs(['expandall'], function (v) {
var skilltab = '4',
setter = {};
if (parseInt(v['expandall'], 10)) {
//set expandall to 0
//set tabs to "all"
//set conditions and buffs to "show"
//set all others to default (which is "show")
SWUtils.setWrapper({
expandall: '0',
pagetab: '99',
buffs_tab: '99',
abilities_tab: '99',
'npc-abilities_tab': '99',
skills_tab: '99',
spellclass_tab: '99',
spells_tab: '99',
npc_spellclass_tab: '99',
equipment_tab: '99',
'conditions-show': 1,
'buffstop-show': 1,
'command-buttons-show': 1,
'NPC-command-buttons-show': 1,
'character-details-show': 1,
'ability-scores-show': 1,
'class-info-show': 1,
class1_show: 1,
class2_show: 1,
class3_show: 1,
'health-and-wounds-show': 1,
'initiative-show': 1,
'macro-text-show': 1,
'notes-show': 1,
'saves-show': 1,
'all-saves-macro-show': 1,
'save-notes-show': 1,
'defense-values-show': 1,
'armor-shield-show': 1,
'sanity-show': 1,
'defense-notes-show': 1,
'attack-bonuses-show': 1,
atkm2_show: 1,
ranged_2_show: 1,
cmb_2_show: 1,
'attack-notes-show': 1,
'attack-options-show': 1,
'two-weapon-show': 1,
'attacks-show': 1,
'skill-ranks-show': 1,
'skill_options-show': 1,
'skills-show': 1,
'artistry-show': 1,
'craft-show': 1,
'knowledge-show': 1,
'lore-show': 1,
'perform-show': 1,
'profession-show': 1,
'misc-show': 1,
'skill-notes-show': 1,
'ability-command-buttons-show': 1,
'NPC-ability-command-buttons-show': 1,
'feats-show': 1,
'mythic-info-show': 1,
'psionic-info-show': 1,
'burn-show': 1,
'abilities-show': 1,
'spellclasses-show': 1,
'spellclass-0-show': 1,
'spellclass-0-spellpoints-show': 1,
'spellclass-0-spells-notes-show': 1,
'spellclass-0-perday-show': 1,
'spellclass-0-domains-show': 1,
domain02_show: 1,
domain03_show: 1,
'spellclass-1-show': 1,
'spellclass-1-spellpoints-show': 1,
'spellclass-1-spells-notes-show': 1,
'spellclass-1-perday-show': 1,
'spellclass-1-domains-show': 1,
'spellclass-2-show': 1,
'spellclass-2-spellpoints-show': 1,
'spellclass-2-spells-notes-show': 1,
'spellclass-2-perday-show': 1,
'spellclass-2-domains-show': 1,
'spelloptions-show': 1,
'spell-lists-show': 1,
'currency-show': 1,
'carried-weight-show': 1,
'loads-show': 1,
'worn-items-show': 1,
'other-items-show': 1,
'equipment-show': 1,
'npc-compimport-show': 1,
'npc-details-show': 1,
'npc-defense-show': 1,
'npc-offense-show': 1,
'npc-speed-show': 1,
'npc-repeating-weapons-show': 1,
'npc-spells-show': 1,
'npc-spell-like-abilities-show': 1,
'npc-tactics-show': 1,
'npc-statistics-show': 1,
'npc-feats-show': 1,
'npc-mythic-feats-show': 1,
'npc-skills-show': 1,
'npc-ecology-show': 1,
'npc-special-abilities-show': 1,
'custom-attr-sect-a-show': 1,
'custom-attr-sect-c-show': 1,
'custom-attr-sect-b-show': 1,
'custom-attr-sect-d-show': 1,
'custom-attr-sect-n-show': 1,
'header-image-show': 1,
'sheet-import-show': 1,
'roll-template-info-show': 1,
'macros-show': 1,
'migrations-show': 1,
'cleanup-show': 1,
'san-show': 1,
'buff-min-show': 0,
'buff-expand-show': 0,
'buff-column-show': 0,
'weapon-min-show': 0,
'weapon-expand-show': 0,
'weapon-column-show': 0,
'abilities-min-show': 0,
'abilities-expand-show': 0,
'abilities-column-show': 0,
'class-ability-min-show': 0,
'class-ability-expand-show': 0,
'class-ability-column-show': 0,
'feat-min-show': 0,
'feat-expand-show': 0,
'feat-column-show': 0,
'mythic-feats-min-show': 0,
'mythic-feats-expand-show': 0,
'mythic-feats-column-show': 0,
'racial-trait-min-show': 0,
'racial-trait-expand-show': 0,
'racial-trait-column-show': 0,
'traits-min-show': 0,
'traits-expand-show': 0,
'traits-column-show': 0,
'npc-spell-like-abilities-min-show': 0,
'npc-spell-like-abilities-expand-show': 0,
'npc-spell-like-abilities-column-show': 0,
'mythic-min-show': 0,
'mythic-expand-show': 0,
'mythic-column-show': 0,
'newspells-min-show': 0,
'newspells-expand-show': 0,
'newspells-column-show': 0,
'item-min-show': 0,
'item-expand-show': 0,
'item-column-show': 0,
'npcweapon-min-show': 0,
'npcweapon-expand-show': 0,
'npcweapon-column-show': 0,
'npcnewspells-min-show': 0,
'npcnewspells-expand-show': 0,
'npcnewspells-column-show': 0,
'npcfeat-min-show': 0,
'npcfeat-expand-show': 0,
'npcfeat-column-show': 0,
'npcmythic-feats-min-show': 0,
'npcmythic-feats-expand-show': 0,
'npcmythic-feats-column-show': 0,
'npc-abilities-min-show': 0,
'npc-abilities-expand-show': 0,
'npc-abilities-column-show': 0,
'npc-special-abilities-min-show': 0,
'npc-special-abilities-expand-show': 0,
'npc-special-abilities-column-show': 0,
extra_fields_san_show: 1,
extra_fields_attacks_show: 1,
skill_onetimecolumns_show: 1,
extra_fields_saves_show: 1,
extra_fields_spells_show: 1,
extra_fields_caster_show: 1,
extra_fields_abilities_show: 1,
extra_fields_init_show: 1,
extra_fields_speeds_show: 1,
extra_fields_defense_show: 1,
extra_fields_conditions_show: 1,
});
//now go through repeating sections and expand those to be sure users can see them.
_.each(PFConst.repeatingSections, function (section) {
var rsection = 'repeating_' + section;
getSectionIDs(rsection, function (ids) {
var setter = _.reduce(
ids,
function (memo, id) {
var prefix = rsection + '_' + id + '_';
switch (section) {
case 'weapon':
memo[prefix + 'misc-show'] = 1;
memo[prefix + 'add-damage-show'] = 1;
memo[prefix + 'iterative-attacks-show'] = 1;
memo[prefix + 'advmacro-text-show'] = 1;
break;
case 'buff':
memo[prefix + 'options-show'] = 1;
memo[prefix + 'description-show'] = 1;
break;
case 'buff2':
memo[prefix + 'options-show'] = 1;
memo[prefix + 'description-show'] = 1;
break;
case 'spells':
memo[prefix + 'misc-show'] = 1;
memo[prefix + 'attack-show'] = 1;
memo[prefix + 'description-show'] = 1;
break;
case 'class-ability':
case 'feat':
case 'racial-trait':
case 'trait':
case 'mythic-ability':
case 'mythic-feat':
memo[prefix + 'description-show'] = 1;
break;
case 'item':
memo[prefix + 'description-show'] = 1;
memo[prefix + 'armor-attributes-show'] = 1;
memo[prefix + 'weapon-attributes-show'] = 1;
break;
case 'npc-spell-like-abilities':
memo[prefix + 'attack-show'] = 1;
break;
case 'ability':
memo[prefix + 'options-show'] = 1;
memo[prefix + 'description-show'] = 1;
memo[prefix + 'misc-show'] = 1;
memo[prefix + 'showextrafields'] = 1;
memo[prefix + 'range-show'] = 1;
memo[prefix + 'attack-show'] = 1;
break;
}
memo[prefix + 'row-show'] = 1;
memo[prefix + 'ids-show'] = 1;
if (section !== 'buff' && section !== 'buff2') {
memo[prefix + 'macro-text-show'] = 1;
}
return memo;
},
{},
);
SWUtils.setWrapper(setter, {
silent: true,
});
});
});
}
});
}
/** Sets any values if sheet created brand new. Makes sure all migrations up to date.
* makes sure NPC value set.
*/
function setupNewSheet(callback) {
var done = _.once(function () {
var setter = {is_newsheet: 0, is_v1: 1, use_buff_bonuses: 1, use_advanced_options: 0, modify_dmg_by_size: 1, PFSheet_Version: String(PFConst.version.toFixed(2))};
setter[PFConst.announcementVersionAttr] = 1;
SWUtils.setWrapper(setter, PFConst.silentParams, function () {
if (typeof callback === 'function') {
callback();
}
});
});
getAttrs(['is_npc', 'set_pfs'], function (v) {
var isNPC = parseInt(v.is_npc, 10) || 0,
isPFS = parseInt(v.set_pfs, 10) || 0;
PFMigrate.setAllMigrateFlags(function () {
PFSkills.migrate();
PFCustom.migrate();
if (isNPC) {
PFNPC.setToNPC(done);
} else if (isPFS) {
PFHealth.setToPFS(done);
} else {
done();
}
});
});
}
/** Only updates things between versions, normally things that are not part of migrate()
*@param {number} oldversion the current version attribute
*@param {function} callback when done if no errors
*@param {function} errorCallback call this if we get an error
*/
function migrate(oldversion, callback, errorCallback) {
var done = _.once(function () {
TAS.debug('leaving PFSheet.migrate');
if (typeof callback === 'function') {
callback();
}
}),
errorDone = _.once(function () {
TAS.warn('leaving PFSheet.migrate ERROR UPGRADE NOT FINISHED');
if (typeof errorCallback === 'function') {
errorCallback();
} else {
done();
}
}),
doneOne;
try {
//don't need to check if oldversion > 0 since this is only called if it is.
//TAS.debug("At PFSheet.migrate from oldversion:"+oldversion);
if (oldversion < 1.0) {
doneOne = _.after(7, function () {
TAS.info('PFSheet.migrate we finished calling all the migrates');
done();
});
PFMigrate.migrateConfigFlags(
TAS.callback(function () {
PFInventory.migrate(doneOne, oldversion);
PFSkills.migrate(doneOne, oldversion);
PFHealth.migrate(doneOne, oldversion);
PFAttacks.migrate(doneOne, oldversion);
PFAbility.migrate(doneOne, oldversion);
PFFeatures.migrate(doneOne, oldversion);
PFSpells.migrate(doneOne, oldversion);
}),
oldversion,
);
} else if (oldversion < 1.17) {
if (oldversion < 1.02) {
PFAbility.migrate(null, oldversion);
PFFeatures.migrate(null, oldversion);
}
if (oldversion < 1.05) {
PFAttackOptions.resetOptions();
}
if (oldversion < 1.07) {
PFInventory.migrate(null, oldversion);
}
if (oldversion < 1.1) {
PFMigrate.migrateAbilityListFlags();
PFFeatures.migrate(null, oldversion);
}
if (oldversion < 1.12) {
PFAbility.migrate(null, oldversion);
}
if (oldversion < 1.17) {
PFInventory.migrate(function () {
PFInventory.resetCommandMacro();
});
}
} else {
if (oldversion < 1.18) {
//future updates here. any above will recalc whole sheet after callback
PFInitiative.recalculate(null, false, oldversion);
PFHealth.recalculate(null, false, oldversion);
PFMigrate.migrateSpellPointFlag(null, oldversion);
}
if (oldversion < 1.2) {
PFHealth.recalculate();
}
if (oldversion < 1.4) {
PFMigrate.migrateWhisperDropdowns();
PFInventory.resetCommandMacro();
PFAttackGrid.resetCommandMacro();
PFAbility.resetCommandMacro();
PFFeatures.resetCommandMacro();
PFAttacks.recalculate();
PFClassRaceGrid.setHitPoints();
}
if (oldversion < 1.43) {
PFSpells.recalculate();
PFSkills.resetCommandMacro();
}
if (oldversion < 1.5) {
PFSpells.resetSpellsTotals(null, null, null, true);
PFInventory.updateRepeatingItems();
PFAttacks.migrateLinkedAttacks(null, oldversion);
}
if (oldversion < 1.53) {
PFSkills.migrate(null, oldversion);
PFSize.recalculate(function () {
PFEncumbrance.migrate();
});
}
if (oldversion < 1.54) {
PFBuffs.recalculate();
}
if (oldversion < 1.55) {
PFAttacks.recalculate();
PFSkills.migrate();
}
if (oldversion < 1.56) {
PFAttacks.updateRepeatingWeaponDamages();
}
if (oldversion < 1.57) {
PFDefense.updateDefenses();
}
if (oldversion <= 1.65) {
PFCustom.migrate(function () {
PFBuffs.migrate(function () {
PFConditions.migrate(function () {
PFBuffs.recalculate(function () {
PFCustom.recalculate(function () {
PFSkills.migrate(function () {
PFSkills.recalculateSkills();
}, oldversion);
PFAbility.setRuleTabs();
PFInventory.updateLocations();
PFAttackGrid.recalculate(function () {
PFAttacks.adjustAllDamageDiceAsync();
PFAttacks.updateDualWieldAttacks();
PFAttacks.recalculateRepeatingWeapons();
});
PFInventory.migrate();
});
});
}, oldversion);
}, oldversion);
}, oldversion);
}
if (oldversion < 1.68) {
PFCustom.migrate(function () {
PFSkills.recalculate(null, null, oldversion);
PFDefense.recalculate(null, null, oldversion);
PFAttackGrid.recalculate(null, null, oldversion);
});
}
if (oldversion < 1.69) {
PFSpellCasterClasses.recalculate(null, null, oldversion);
PFFeatures.recalculate(null, null, oldversion);
PFAttacks.recalculate(null, null, oldversion);
PFAbility.recalculate(null, null, oldversion);
PFInventory.recalculate(null, null, oldversion);
PFBuffs.recalculate(null, null, oldversion);
PFDefense.recalculate(null, null, oldversion);
}
if (oldversion < 1.693) {
PFCustom.fixProfessionDropdowns(PFSkills.recalculate);
}
if (oldversion < 1.697) {
PFAttacks.recalculate(null, null, oldversion);
}
if (oldversion < 1.72) {
PFSize.recalculate(oldversion, function () {
PFAttacks.adjustAllDamageDiceAsync(null, null);
});
PFSpells.resetSpellsTotals();
}
if (oldversion < 1.724) {
PFSkills.migrate(null, oldversion);
}
if (oldversion < 1.731) {
PFMacros.checkScrollDesc();
}
if (oldversion < 1.732) {
PFMacros.checkBaseAttacks();
}
if (oldversion < 1.787) {
PFAbility.updateIncludeLinkVersionCheck();
}
if (oldversion < 1.822) {
PFSpells.setCasterTypeSpells();
}
if (oldversion < 1.826) {
PFMacros.checkAbilityType2();
}
}
} catch (err) {
TAS.error('PFSheet.migrate', err);
errorDone();
} finally {
done();
}
}
function recalculateParallelModules(callback, silently, oldversion) {
var done = _.once(function () {
TAS.info('leaving PFSheet.recalculateParallelModules');
if (typeof callback === 'function') {
callback();
}
}),
parallelRecalcFuncs = [
PFSpellCasterClasses.recalculate,
PFSaves.recalculate,
PFFeatures.recalculate,
PFPsionic.recalculate,
PFSkills.recalculate,
PFAbility.recalculate,
PFInitiative.recalculate,
PFAttacks.recalculate,
PFHorror.recalculate,
PFOccult.recalculate,
],
numberModules = _.size(parallelRecalcFuncs),
doneOneModuleInner = _.after(numberModules, done),
curr = 0,
currstarted = 0,
doneOneModule = function () {
curr++;
TAS.info('PFSheet.recalculateParallelModules, finished ' + curr + ' modules');
doneOneModuleInner();
};
//TAS.debug("at recalculateParallelModules! there are "+numberModules +" modules");
try {
_.each(parallelRecalcFuncs, function (methodToCall) {
try {
currstarted++;
//TAS.info("starting " + currstarted + " parallel modules calling:"+methodToCall);
methodToCall(doneOneModule, silently, oldversion);
} catch (err) {
TAS.error('PFSheet.recalculateParallelModules error calling recalculate', err);
doneOneModule();
}
});
} catch (err2) {
TAS.error('PFSheet.recalculateParallelModules OUTER error!', err2);
done();
}
}
function recalculateDefenseAndEncumbrance(callback, silently, oldversion) {
var done = _.once(function () {
//TAS.debug("leaving PFSheet.recalculateDefenseAndEncumbrance");
if (typeof callback === 'function') {
callback();
}
}),
callEncumbrance = function () {
PFEncumbrance.recalculate(done, silently, oldversion);
},
doneBeforeEncumbrance = _.after(2, callEncumbrance);
try {
PFInventory.recalculate(doneBeforeEncumbrance, silently, oldversion);
PFDefense.recalculate(doneBeforeEncumbrance, silently, oldversion);
} catch (err) {
TAS.error('pfsheet.recalculateDefenseAndEncumbrance', err);
callEncumbrance();
}
}
function recalculateCore(callback, silently, oldversion) {
var done = _.once(function () {
//TAS.debug("leaving PFSheet.recalculateCore");
if (typeof callback === 'function') {
callback();
}
}),
sizeOnce = _.once(function () {
PFSize.recalculate(done, silently, oldversion);
}),
healthOnce = _.once(function () {
PFHealth.recalculate(sizeOnce, silently, oldversion);
}),
npcOnce = _.once(function () {
PFNPC.recalculate(healthOnce, silently, oldversion);
}),
mythicOnce = _.once(function () {
PFMythic.recalculate(npcOnce, silently, oldversion);
}),
customOnce = _.once(function () {
PFCustom.recalculate(mythicOnce, silently, oldversion);
}),
conditioncheckOnce = _.once(function () {
PFChecks.applyConditions(customOnce, silently, oldversion);
}),
classOnce = _.once(function () {
PFClassRaceGrid.recalculate(conditioncheckOnce, silently, oldversion);
}),
abilityScoresOnce = _.once(function () {
PFAbilityScores.recalculate(classOnce, silently, oldversion);
}),
abilityAffectingConditionsOnce = _.once(function () {
PFConditions.recalculate(abilityScoresOnce, silently, oldversion);
}),
buffsOnce = _.once(function () {
PFBuffs.recalculate(abilityAffectingConditionsOnce, silently, oldversion);
});
PFMigrate.migrateConfigFlags(buffsOnce, oldversion);
//TAS.debug("at recalculateCore!!!!");
}
/** recalculate - all pages in sheet!
*@param {number} oldversion the current version attribute
*@param {function} callback when done if no errors
*@param {function} errorCallback call this if we get an error
*/
export function recalculate(oldversion, callback, silently) {
var done = function () {
TAS.info('leaving PFSheet.recalculate');
if (typeof callback === 'function') {
callback();
}
},
callParallel = TAS.callback(function callRecalculateParallelModules() {
recalculateParallelModules(done, silently, oldversion);
}),
callEncumbrance = TAS.callback(function callRecalculateDefenseAndEncumbrance() {
recalculateDefenseAndEncumbrance(callParallel, silently, oldversion);
}),
callRecalcCore = TAS.callback(function callRecalculateCore() {
recalculateCore(callEncumbrance, silently, oldversion);
});
silently = true;
callRecalcCore();
}
/* checkForUpdate looks at current version of page in PFSheet_Version and compares to code PFConst.version
* calls recalculateSheet if versions don't match or if recalculate button was pressed.
* */
export function checkForUpdate(forceRecalc) {
var done = function () {
TAS.info('leaving PFSheet.checkForUpdate');
SWUtils.setWrapper({recalc1: 0, migrate1: 0, is_newsheet: 0}, PFConst.silentParams);
},
errorDone = _.once(function () {
TAS.warn('leaving PFSheet.checkForUpdate ERROR UPGRADE NOT FINISHED DO NOT RESET VERSION');
SWUtils.setWrapper({recalc1: 0, migrate1: 0}, {silent: true});
});
getAttrs(
[
'PFSheet_Version',
'migrate1',
'recalc1',
'is_newsheet',
'is_v1',
'hp',
'hp_max',
'npc-hd',
'npc-hd-num',
'race',
'class-0-name',
'npc-type',
'level',
'hide_announcements',
PFConst.announcementVersionAttr,
],
function (v) {
var setter = {},
setAny = 0,
migrateSheet = false,
newSheet = false,
recalc = false,
currVer = parseFloat(v.PFSheet_Version, 10) || 0,
setUpgradeFinished = function () {
SWUtils.setWrapper(
{recalc1: 0, migrate1: 0, is_newsheet: 0, character_sheet: 'Pathinder_Neceros v' + String(PFConst.version), PFSheet_Version: String(PFConst.version.toFixed(3))},
PFConst.silentParams,
function () {
if (currVer < 1.17) {
recalculate(currVer, null, false);
}
},
);
};
TAS.notice('Attributes at version: ' + currVer);
if (forceRecalc) {
recalc = true;
} else {
if (parseInt(v['recalc1'], 10)) {
//HIT RECALC
recalc = true;
}
if (parseInt(v['migrate1'], 10)) {
migrateSheet = true;
}
if (
parseInt(v['is_newsheet'], 10) ||
(currVer === 0 &&
(parseInt(v.is_v1, 10) ||
!(
parseInt(v.hp, 10) ||
parseInt(v.hp_max, 10) ||
parseInt(v['npc-hd'], 10) ||
parseInt(v['npc-hd-num'], 10) ||
v.race ||
v['class-0-name'] ||
v['npc-type'] ||
parseInt(v['level'], 10)
)))
) {
//NEW SHEET:
newSheet = true;
}
}
//force this on sheet open, not sure wtf is wrong
if (currVer !== PFConst.version) {
migrateSheet = true;
}
if (!newSheet && parseInt(v.hide_announcements, 10) && !parseInt(v[PFConst.announcementVersionAttr], 10)) {
setter[PFConst.announcementVersionAttr] = 1;
SWUtils.setWrapper(setter, PFConst.silentParams);
}
if (newSheet) {
setupNewSheet(done);
} else if (migrateSheet) {
TAS.notice('UPGRADE SHEET');
migrate(currVer, setUpgradeFinished, errorDone);
} else if (recalc) {
currVer = -1;
recalculate(currVer, done, true);
} else {
done();
}
},
);
}
function registerEventHandlers() {
var eventToWatch = '';
on(
'sheet:opened',
TAS.callback(function eventSheetOpened() {
//eventInfo has undefined values for this event.
checkForUpdate();
}),
);
on(
'change:recalc1 change:migrate1',
TAS.callback(function eventRecalculateSheet(eventInfo) {
TAS.debug('caught ' + eventInfo.sourceAttribute + ' event: ' + eventInfo.sourceType);
if (eventInfo.sourceType === 'player' || eventInfo.sourceType === 'api') {
checkForUpdate();
}
}),
);
on('change:expandall', function (eventInfo) {
TAS.debug('caught ' + eventInfo.sourceAttribute + ' event: ' + eventInfo.sourceType);
if (eventInfo.sourceType === 'player' || eventInfo.sourceType === 'api') {
expandAll();
}
});
on(
'change:repeating_weapon:source-item',
TAS.callback(function eventUpdateAttackSourceItem(eventInfo) {
if (eventInfo.sourceType === 'player' || eventInfo.sourceType === 'api') {
TAS.debug('caught ' + eventInfo.sourceAttribute + ' event: ' + eventInfo.sourceType);
getAttrs([eventInfo.sourceAttribute], function (v) {
var weaponId = SWUtils.getRowId(eventInfo.sourceAttribute),
sourceId = v[eventInfo.sourceAttribute];
//TAS.debug("PFSheet new item id: " + sourceId + " this row weapon id: "+weaponId, v);
if (sourceId) {
sourceId = 'repeating_item_' + sourceId + '_create-attack-entry';
PFInventory.createAttackEntryFromRow(sourceId, null, false, weaponId);
}
});
}
}),
);
on(
'change:repeating_weapon:source-ability',
TAS.callback(function eventUpdateAttackSourceAbility(eventInfo) {
if (eventInfo.sourceType === 'player' || eventInfo.sourceType === 'api') {
TAS.debug('caught ' + eventInfo.sourceAttribute + ' event: ' + eventInfo.sourceType);
getAttrs([eventInfo.sourceAttribute], function (v) {
var weaponId = SWUtils.getRowId(eventInfo.sourceAttribute),
sourceId = v[eventInfo.sourceAttribute];
if (sourceId) {
PFAbility.createAttackEntryFromRow(sourceId, null, false, null, weaponId);
}
});
}
}),
);
on(
'change:repeating_weapon:source-spell',
TAS.callback(function eventUpdateAttackSourceSpell(eventInfo) {
if (eventInfo.sourceType === 'player' || eventInfo.sourceType === 'api') {
TAS.debug('caught ' + eventInfo.sourceAttribute + ' event: ' + eventInfo.sourceType);
getAttrs([eventInfo.sourceAttribute], function (v) {
var weaponId = SWUtils.getRowId(eventInfo.sourceAttribute),
sourceId = v[eventInfo.sourceAttribute];
if (sourceId) {
PFSpells.createAttackEntryFromRow(sourceId, null, false, null, weaponId);
}
});
}
}),
);
//delete a list
on(
'change:delete_rep_spells change:delete_rep_weapon change:delete_rep_item change:delete_rep_ability change:delete_rep_mythic-feat change:delete_rep_mythic-ability change:delete_rep_buff change:delete_rep_buff2 change:delete_rep_trait change:delete_rep_racial-trait change:delete_rep_feat change:delete_rep_class-ability change:delete_rep_npc-spell-like-abilities',
TAS.callback(function eventDeleteOldList(eventInfo) {
TAS.debug('caught ' + eventInfo.sourceAttribute + ' event: ' + eventInfo.sourceType);
if (eventInfo.sourceType === 'player' || eventInfo.sourceType === 'api') {
getAttrs([eventInfo.sourceAttribute], function (v) {
var section = '';
if (parseInt(v[eventInfo.sourceAttribute], 10)) {
section = eventInfo.sourceAttribute.replace('delete_rep_', '');
SWUtils.deleteRepeating(function () {
var setter;
setter = {};
setter[eventInfo.sourceAttribute] = 0;
setter[eventInfo.sourceAttribute + '_btn'] = 0;
SWUtils.setWrapper(setter, {silent: true});
if (/buff/i.test(eventInfo.sourceAttribute)) {
PFBuffs.clearBuffTotals();
}
}, section);
}
});
}
}),
);
on('change:hide_announcements', function () {
var setter = {};
setter[PFConst.announcementVersionAttr] = 1;
setAttrs(setter, PFConst.silentParams);
});
}
registerEventHandlers();
+407
View File
@@ -0,0 +1,407 @@
'use strict';
import _ from 'underscore';
import {PFLog, PFConsole} from './PFLog';
import TAS from './TheAaronSheet.js';
import * as SWUtils from './SWUtils';
import PFConst from './PFConst';
import * as PFUtils from './PFUtils';
import * as PFMigrate from './PFMigrate';
import * as PFEncumbrance from './PFEncumbrance';
import * as PFAttacks from './PFAttacks';
//these use strings on the left so javascript doesn't confuse the number with array indices
//converts from the attack mod value to easy 0 through 8
export var sizeModToEasySizeMap={
'0':4, //medium
'1':3, //small
'2':2, //tiny
'-8':8, //colossal
'4':1, //diminutive
'-4':7, //gargantuan
'-2':6, //huge
'-1':5, //large
'8':0 //fine
},
reverseSizeMap={
'0':8, //fine
'1':4, //diminutive
'2':2, //tiny
'3':1, //small
'4':0, //medium
'5':-1, //large
'6':-2, //huge
'7':-4, //gargantuan
'8':-8 //colossal
},
skillSizeMap = {
'0':0, //medium
'1':2, //small
'2':4, //tiny
'8':8, //diminutive
'4':6, //fine
'-8':-8, //colossal
'-4':-6, //gargantuan
'-2':-4, //huge
'-1':-2 //large
},
sizeNameMap = {
'colossal':-8,
'gargantuan':-4,
'huge':-2,
'large':-1,
'medium':0,
'small':1,
'tiny':2,
'diminutive':4,
'fine':8
},
reverseSizeNameMap = {
'0':'medium',
'1':'small',
'2':'tiny',
'-8':'colossal',
'4':'diminutive',
'-4':'gargantuan',
'-2':'huge',
'-1':'large',
'8':'fine'
};
/** getSizeFromText - returns size mod based on size display name
* @param {string} sizeDisplay size in english (medium, large, gargantuan, tiny, etc)
* @returns {jsobj} map of {"size":size mod for AC,"skillSize": size mod for fly}
*/
export function getSizeFromText (sizeDisplay) {
var sizeMap = {
"size": 0,
"skillSize": 0
};
try {
if (sizeDisplay) {
sizeDisplay = SWUtils.trimBoth(sizeDisplay);
sizeDisplay = sizeDisplay.toLowerCase();
sizeMap.size=sizeNameMap[sizeDisplay];
sizeMap.skillSize = skillSizeMap[String(sizeMap.size)];
}
} catch (err) {
TAS.error("get size from text:" + sizeDisplay, err);
sizeMap.size = 0;
sizeMap.skillSize = 0;
} finally {
return sizeMap;
}
}
/**returns number of levels size went up or down
* ex: Med to Lg is +1, Med to Sm is -1, Md to Tiny is -2, etc
* @param {int} currSize new size mod , usually value of @{size}
* @param {int} defaultSize default size mod, for sheet it is value of @{default_char_size}
* for weapon it is @{repeating_weapon_$X_default_size}
* @returns {int} difference in sizes (not difference in size mods)
*/
export function getSizeLevelChange (currSize,defaultSize) {
var newSize,oldSize,levelChange;
newSize=sizeModToEasySizeMap[String(currSize)];
oldSize=sizeModToEasySizeMap[String(defaultSize)];
levelChange = newSize-oldSize;
return levelChange;
}
/**updateDamageDice returns new dice for weapon/attack damage change due to size
*@param {Number} sizediff difference in LEVELS of size (Medium to Large is 1, Medium to Small is -1)
*@param {Number} defaultSize size modifier, necessary since different rules for small
*@param {Number} currDice num dice from 1 to n
*@param {Number} currDie num sides of die : valid only from 1 to 12
*@returns {jsobj} {dice:n,die:n}
*/
export function updateDamageDice (sizediff,defaultSize,currDice,currDie){
var diceSizes = { 1:["1d1"], 2:["1d2"], 3:["1d3"],
4:["1d4"],
5:["1d6"],
6:["1d8","2d4"],
7:["1d10"],
8:["2d6","3d4","1d12"],
9:["2d8","4d4"], 10:["3d6","5d4"], 11:["3d8","6d4","2d10"],
12:["4d6","7d4","2d12"], 13:["4d8","8d4","9d4","5d6","3d10"],
14:["6d6","5d8","10d4","11d4","9d4","3d12"],
15:["6d8","7d6","12d4","13d4","4d10"],
16:["8d6","7d8","14d4","15d4","4d12"],
17:["8d8","16d4","9d6","10d6","11d6","5d10","17d4","18d4","19d4","5d12"],
18:["12d6","20d4","9d8","7d10","6d12","21d4","22d4","23d4"],
19:["12d8","24d4","13d6","14d6","15d6","8d10"],
20:["16d6","13d8","10d10","8d12"]
},
currSize=0,
dicestring="",
newDice=0,newDie=0,matches,
rowdiff=0, currow=0, newrow=0, newrowstring="",
reversedDiceSizes=_.reduce(diceSizes,function(memo,pairs,idx){
_.each(pairs,function(pair){ memo[pair]=idx; });
return memo;
},{});
try {
//TAS.debug("PFSize.updateDamageDice defSize:"+defaultSize+", diff:"+sizediff+", dice:"+currDice+"d"+currDie);
currDice=parseInt(currDice,10);
currDie=parseInt(currDie,10);
if(!(isNaN(currDice)||isNaN(currDie))){
dicestring=currDice+"d"+currDie;
currSize=sizeModToEasySizeMap[String(defaultSize)];
//TAS.debug("currSize now : "+currSize);
if (currDice<=0 || currDie > 12 ) {return null;}
if (currDie===4 && currDice >24){ currDice=24;}
else if (currDie===6 && currDice > 16) {currDice=16;}
else if (currDie===8 && currDice > 13) {currDice=13;}
else if (currDie===10 && currDice > 10) {currDice=10;}
else if (currDie===12 && currDice > 8) {currDice=8;}
currow=parseInt(reversedDiceSizes[dicestring],10)||0;
if (!currow){return null;}
while (sizediff !== 0){
if (sizediff > 0){
if ((currDie<=6 && currDice===1)|| currSize <=3) {
rowdiff=1;
} else {
rowdiff=2;
}
} else if (sizediff<0) {
if ((currDie<=8 && currDice===1)||currSize<=4 ) {
rowdiff=-1;
} else {
rowdiff = -2;
}
}
newrow = currow + rowdiff;
newrow = Math.min(Math.max(newrow,1),20);
dicestring = diceSizes[newrow][0];
//TAS.debug("PFSize "+currDice+"d"+currDie+" is currrow:"+currow+" going from size:"+currSize+" of diff:"+sizediff+", move "+rowdiff+" levels to "+ newrow+" dice is "+dicestring);
matches=dicestring.match(/(\d+)d(\d+)/);
currDice=parseInt(matches[1],10);
currDie=parseInt(matches[2],10);
currow =newrow;
if (sizediff >0 ) {
currSize++;
sizediff--;
if (currow>=20){
TAS.warn("PFSize.updateDamageDice increased off top of grid to row "+currow);
break;
}
} else {
currSize--;
sizediff++;
if (currow<=1) {
TAS.warn("PFSize.updateDamageDice decreased under bottom of grid to row "+currow);
break;
}
}
//TAS.debug("updateDamageDice: currow is now"+currow+", diff still:"+sizediff);
}
}
} catch(err){
TAS.error("updateDamageDice: ",err);
} finally {
return {"dice":currDice,"die":currDie};
}
}
/** sets the size variables based on the string passed in
*
* @param {string} str the name of the size in english
* @param {Map<string,int>} setter to pass to setAttrs
*/
export function setSizeFromString(str,setter){
var tempstr='',sizeMap={};
try {
sizeMap = getSizeFromText(str);
if (sizeMap && sizeMap.size !== 0) {
setter.size = sizeMap.size;
setter['default_char_size']=sizeMap.size;
setter.size_skill = sizeMap.skillSize;
setter["CMD-size"] = (sizeMap.size * -1);
setter.size_skill_double = (sizeMap.skillSize * 2);
} else {
setter['size']=0;
setter['default_char_size']=0;
setter.size_skill = 0;
setter["CMD-size"] = 0;
setter.size_skill_double =0;
if (!sizeMap){
sizeMap = {'size':0,'skillSize':0};
}
}
//tempstr=reverseSizeNameMap[String(sizeMap.size)];
setter['size_display']=SWUtils.getTranslated(str.toLowerCase());
} finally {
return sizeMap
}
}
function setSizeDisplay (size,v,setter){
var tempstr='',sizeDisplay='';
setter=setter||{};
tempstr=reverseSizeNameMap[String(size)];
sizeDisplay=SWUtils.getTranslated(tempstr);
if (sizeDisplay && (sizeDisplay!== v.size_display || !v.size_display)){
setter.size_display=sizeDisplay;
}
return setter;
}
/** Overwrites any current change to size with change to size from buffs
*
* @param {*} levelChange
* @param {*} v
* @param {*} eventInfo
* @param {*} setter
*/
export function updateSize (levelChange,v,eventInfo,setter) {
var size = 0,newSize=0, defaultSize=0,deflevel=0,newlevel=0, skillSize = 0;
try {
setter=setter||{};
defaultSize = parseInt(v.default_char_size,10)||0;
//if levelchange is 0, then we are resetting it to defaultSize
newSize=defaultSize;
if (levelChange!==0 ){
deflevel = sizeModToEasySizeMap[String(defaultSize)];
newlevel = deflevel+levelChange;
newSize = reverseSizeMap[String(newlevel)];
}
size = parseInt(v['size'], 10) || 0;
if (newSize!==size){
setter['size']=newSize;
setter["CMD-size"] = (newSize * -1);
skillSize = skillSizeMap[String(newSize)];
setter.size_skill = skillSize;
setter.size_skill_double = (2*skillSize);
} else {
//if the same, we may be resetting, so check each one:
if ((parseInt(v["CMD-size"],10)||0) !== (newSize *-1)){
setter["CMD-size"] = (newSize * -1);
}
skillSize = skillSizeMap[String(newSize)];
if ((parseInt(v.size_skill,10)||0) !== skillSize){
setter.size_skill = skillSize;
}
if ((parseInt(v.size_skill_double,10)||0) !== (2*skillSize)){
setter.size_skill_double = (2*skillSize);
}
}
setSizeDisplay(newSize,v,setter);
} catch (err) {
TAS.error("PFSize.updateSize", err);
} finally {
TAS.debug("PFSize.updateSize returning with ",setter);
return setter;
}
}
/**
*
* @param {function(Number)} callback call with the value of the change in sizes so if 0 we know there was no change
* @param {*} silently
* @param {*} eventInfo
*/
function updateSizeAsync (callback, silently,eventInfo) {
var done = function (change) {
if (typeof callback === "function") {
callback(change);
}
};
getAttrs(["size", "size_skill","size_skill_double", "default_char_size", "CMD-size", "buff_size-total","size_display"], function (v) {
var params = {},
setter = {},
levelChange=0,currSize=0,defSize=0,ddLevelChange=0,forceResize=0;
try {
//if updating buff just overwrite the size dropdown
if (eventInfo && eventInfo.sourceAttribute==='buff_size-total'){
levelChange=parseInt(v['buff_size-total'],10)||0;
updateSize(levelChange,v,eventInfo,setter);
} else if (!eventInfo || eventInfo.sourceAttribute==='size'){
//user must remove the buff if they want to use the dropdown
levelChange=parseInt(v['buff_size-total'],10)||0;
if (levelChange===0){
currSize=parseInt(v.size,10)||0;
defSize=parseInt(v.default_char_size,10)||0;
levelChange=getSizeLevelChange(currSize,defSize);
if (levelChange===0 ){
if (eventInfo){
if ((parseInt(eventInfo.previousValue,10)||0) !== (parseInt(eventInfo.newValue,10)||0)){
forceResize=(parseInt(eventInfo.newValue,10)||0) - (parseInt(eventInfo.previousValue,10)||0);
}
}
}
}
updateSize(levelChange,v,eventInfo,setter);
} else if (eventInfo.sourceAttribute==='default_char_size'){
//just pass the new level diff to callback
currSize=parseInt(v.size,10)||0;
defSize=parseInt(v.default_char_size,10)||0;
levelChange=getSizeLevelChange(currSize,defSize);
} else {
TAS.warn("Called updateSizeAsync with unexpected event:",eventInfo);
}
} catch (err) {
TAS.error("PFSize.updateSizeAsync", err);
} finally {
if (_.size(setter) > 0) {
//TAS.debug("PFSize.updateSizeAsync, setting:",setter);
if (silently) {
params = PFConst.silentParams;
}
SWUtils.setWrapper(setter, params, function(){done(levelChange);});
} else if (levelChange!==0 || forceResize !== 0){
done(1);
} else {
done(0);
}
}
});
}
function setNewSize(eventInfo){
updateSizeAsync(function(changed){
if (changed ){
PFEncumbrance.updateLoadsAndLift();
PFAttacks.adjustAllDamageDiceAsync(null,eventInfo);
}
},false,eventInfo);
// changing size back to medium would never update DamageDice
PFEncumbrance.updateLoadsAndLift();
PFAttacks.adjustAllDamageDiceAsync(null,eventInfo);
}
function applyNewSizeToSheet(eventInfo){
//TAS.debug("PFSize.applyNewSizeToSheet");
PFEncumbrance.updateLoadsAndLift();
PFAttacks.adjustAllDamageDiceAsync(null,eventInfo);
}
export function migrate (callback){
if (typeof callback === "function") {
callback();
}
}
export var recalculate = TAS.callback(function PFSizeRecalculate(callback, silently, oldversion) {
var done = _.once(function () {
TAS.info("leaving PFSize.recalculate");
if (typeof callback === "function") {
callback();
}
});
updateSizeAsync(done, silently,null);
});
function registerEventHandlers () {
//size
on("change:size change:default_char_size", TAS.callback(function eventUpdateSize(eventInfo) {
var prevv=0,newv=0;
TAS.debug("caught " + eventInfo.sourceAttribute + " event: " + eventInfo.sourceType );
TAS.debug(eventInfo);
if (eventInfo.sourceType === "player" ) {
setNewSize(eventInfo);
} else {
//if sheetworker then it may be a loop, so don't change size just make sure everything is using the new size.
//this will happen every time we call with buffs so it will be called twice
//applyNewSizeToSheet(eventInfo);
}
}));
on("change:size change:buff_size-total", TAS.callback(function eventUpdateSize(eventInfo) {
TAS.debug("caught " + eventInfo.sourceAttribute + " event: " + eventInfo.sourceType);
if (eventInfo.sourceType === "sheetworker" || eventInfo.sourceType === "api" ) {
setNewSize(eventInfo);
}
}));
}
registerEventHandlers();
File diff suppressed because it is too large Load Diff