Starting on web worker code.

This commit is contained in:
Cazra
2016-09-23 01:32:59 -04:00
parent bdf6606336
commit 4c508e7184
9 changed files with 511 additions and 167 deletions
-1
View File
@@ -24,4 +24,3 @@ table.abilityScores
+abilityScoreRow('Intelligence', 'int')
+abilityScoreRow('Wisdom', 'wis')
+abilityScoreRow('Charisma', 'cha')
// +labelledAbove('Ability Score Notes')(style='width: 100%;'): +textarea('appearance')(style='height: 0.6in;')
+1 -1
View File
@@ -14,7 +14,7 @@
td: .mathOperator +
td: +readOnlyBox(abilityShortName + '_mod')(style='width: 0.25in;')
td: .mathOperator +
td: +readOnlyBox('attack_size')(style='width: 0.25in;')
td: +readOnlyBox('size')(style='width: 0.25in;')
td: .mathOperator +
td: +fieldBox('number', attackName + '_equipment')
td: .mathOperator +
+8 -8
View File
@@ -1,10 +1,10 @@
+labelledUnderlined('Size')(style='width: 1.2in;'): +select('size')
option(value=4) Colossal
option(value=3) Gargantuan
option(value=2) Huge
option(value=1) Large
option(value=-8) Colossal
option(value=-4) Gargantuan
option(value=-2) Huge
option(value=-1) Large
option(value=0, selected=true) Medium
option(value=-1) Small
option(value=-2) Tiny
option(value=-3) Diminuitive
option(value=-4) Fine
option(value=1) Small
option(value=2) Tiny
option(value=4) Diminuitive
option(value=8) Fine
+4 -3
View File
@@ -2,7 +2,7 @@ mixin fieldBox(type, name, label)
.fieldBox(style=attributes.style)
if(label)
label= label
.inner: input(type=type, name='attr_' + name)
.inner: input(type=type, name='attr_' + name, value=attributes.value)
mixin fraction(name)
.fraction
@@ -11,7 +11,7 @@ mixin fraction(name)
input(type='number', name='attr_' + name + '_max')
mixin input(type, name)
input(type=type, name='attr_' + name, placeholder=attributes.placeholder, style=attributes.style)
input(type=type, name='attr_' + name, placeholder=attributes.placeholder, style=attributes.style, value=attributes.value)
mixin labelledAbove(label)
.labelledAbove(style=attributes.style)
@@ -41,7 +41,8 @@ mixin option(view, value)
option(value=value)= view
mixin readOnlyBox(name)
.readOnlyBox(style=attributes.style): span(name='attr_' + name) 0
.readOnlyBox(style=attributes.style): span(name='attr_' + name)
+input('number', name)(value='0', style='display:none;')
mixin repeating(name)
fieldset(class='repeating_' + name)
+6 -1
View File
@@ -1,6 +1,8 @@
include fields.pug
include tabs.pug
+input('text', 'debug')(value=' ', style='display: none;')
.top
.pfLogo
.topStats(style='margin-bottom: 1em;')
@@ -27,4 +29,7 @@ include tabs.pug
+tab('Magic', 'mainTabs')
include magic/index.pug
+tab('Notes', 'mainTabs')
.test Notes
include notes/index.pug
script(type='text/worker')
include ../worker_test.js
+2
View File
@@ -0,0 +1,2 @@
.notesTab
+textarea('notes')(style='height: 6in;')
+338 -153
View File
File diff suppressed because it is too large Load Diff
+113
View File
@@ -0,0 +1,113 @@
(() => {
'use strict';
function _debug(msg) {
return _setAttrs({
debug: msg
});
}
/**
* Promise-wrapped getAttrs.
*/
function _getAttrs(attrs) {
return new Promise((resolve, reject) => {
getAttrs(attrs, resolve);
});
}
/**
* Promise-wrapped getSectionIDs.
*/
function _getSectionIds(sectionName) {
return new Promise((resolve, reject) => {
getSectionIDs(sectionName, resolve);
});
}
function _onChange(attrNames, cb) {
let list = _.chain(attrNames)
.map(name => {
return 'change:' + name
})
.value();
on(list.join(' '), cb);
}
/**
* Promise-wrapped setAttrs.
*/
function _setAttrs(values) {
return new Promise((resolve, reject) => {
log(values);
setAttrs(values, undefined, resolve);
});
}
function updateAbilityMod(abilityName) {
return _getAttrs([abilityName, abilityName + '_temp'])
.then(values => {
let base = values[abilityName];
let temp = values[abilityName + '_temp'];
return _setAttrs({
[abilityName] + '_mod': Math.floor((base + temp - 10)/2)
}});
});
}
function updateChaMod() {
return updateAbilityMod('cha');
}
function updateConMod() {
return updateAbilityMod('con');
}
function updateDexMod() {
return updateAbilityMod('dex');
}
function updateIntMod() {
return updateAbilityMod('int');
}
function updateStrMod() {
return updateAbilityMod('str');
}
function updateWisMod() {
return updateAbilityMod('wis');
}
_onChange(['cha', 'cha_temp'], () => {
return updateChaMod();
});
_onChange(['con', 'con_temp'], () => {
return updateConMod();
});
_onChange(['dex', 'dex_temp'], () => {
return updateDexMod();
});
_onChange(['int', 'int_temp'], () => {
return updateIntMod();
});
_onChange(['str', 'str_temp'], () => {
return updateStrMod();
});
_onChange(['wis', 'wis_temp'], () => {
return updateWisMod();
});
on('sheet:opened', () => {
updateAll();
});
})();
+39
View File
@@ -0,0 +1,39 @@
(() => {
'use strict';
/**
* Promise-wrapped getAttrs.
*/
function _getAttrs(attrs) {
return new Promise((resolve, reject) => {
getAttrs(attrs, resolve);
});
}
/**
* Promise-wrapped setAttrs.
*/
function _setAttrs(values) {
return new Promise(resolve, reject => {
setAttrs(values, undefined, () => {
resolve();
});
});
}
on('sheet:opened', () => {
(new Promise((resolve, reject) => {
resolve(42);
}))
.then(value => {
return _setAttrs({
debug: value
});
})
.then(() => {
setAttrs({
debug: 11
});
});
});
})();