ENH: Creation summary
parent
2f3c91d72c
commit
642c368f38
|
@ -252,7 +252,6 @@
|
||||||
"OSE.messages.InflictsDamage": "Inflicts damage!",
|
"OSE.messages.InflictsDamage": "Inflicts damage!",
|
||||||
"OSE.messages.applyDamage": "Apply Damage",
|
"OSE.messages.applyDamage": "Apply Damage",
|
||||||
"OSE.messages.applyHealing": "Apply Healing",
|
"OSE.messages.applyHealing": "Apply Healing",
|
||||||
"OSE.messages.creationFinished": "Character {name} creation finished",
|
|
||||||
|
|
||||||
"OSE.colors.green": "Green",
|
"OSE.colors.green": "Green",
|
||||||
"OSE.colors.red": "Red",
|
"OSE.colors.red": "Red",
|
||||||
|
|
|
@ -5,7 +5,7 @@ export class OseCharacterCreator extends FormApplication {
|
||||||
static get defaultOptions() {
|
static get defaultOptions() {
|
||||||
const options = super.defaultOptions;
|
const options = super.defaultOptions;
|
||||||
options.classes = ["ose", "dialog", "creator"],
|
options.classes = ["ose", "dialog", "creator"],
|
||||||
options.id = 'character-creator';
|
options.id = 'character-creator';
|
||||||
options.template =
|
options.template =
|
||||||
'systems/ose/templates/actors/dialogs/character-creation.html';
|
'systems/ose/templates/actors/dialogs/character-creation.html';
|
||||||
options.width = 235;
|
options.width = 235;
|
||||||
|
@ -41,6 +41,11 @@ export class OseCharacterCreator extends FormApplication {
|
||||||
con: 0,
|
con: 0,
|
||||||
gold: 0
|
gold: 0
|
||||||
}
|
}
|
||||||
|
data.stats = {
|
||||||
|
sum: 0,
|
||||||
|
avg: 0,
|
||||||
|
std: 0
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,20 +61,27 @@ export class OseCharacterCreator extends FormApplication {
|
||||||
})
|
})
|
||||||
|
|
||||||
let n = values.length;
|
let n = values.length;
|
||||||
let sum = values.reduce((a,b) => a+b);
|
let sum = values.reduce((a, b) => a + b);
|
||||||
let mean = parseFloat(sum) / n;
|
let mean = parseFloat(sum) / n;
|
||||||
let std = Math.sqrt(values.map(x => Math.pow(x-mean,2)).reduce((a,b) => a+b)/n);
|
let std = Math.sqrt(values.map(x => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n);
|
||||||
|
|
||||||
let stats = list.siblings('.roll-stats');
|
let stats = list.siblings('.roll-stats');
|
||||||
stats.find('.sum').text(sum);
|
stats.find('.sum').text(sum);
|
||||||
stats.find('.avg').text(Math.round(10 * sum / n) / 10);
|
stats.find('.avg').text(Math.round(10 * sum / n) / 10);
|
||||||
stats.find('.std').text(Math.round(100 * std) / 100);
|
stats.find('.std').text(Math.round(100 * std) / 100);
|
||||||
|
|
||||||
if (n >= 6) {
|
if (n >= 6) {
|
||||||
$(ev.currentTarget).closest('form').find('button[type="submit"]').removeAttr('disabled');
|
$(ev.currentTarget).closest('form').find('button[type="submit"]').removeAttr('disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.object.data.stats = {
|
||||||
|
sum: sum,
|
||||||
|
avg: Math.round(10 * sum / n) / 10,
|
||||||
|
std: Math.round(100 * std) / 100
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rollScore(score, options={}) {
|
rollScore(score, options = {}) {
|
||||||
// Increase counter
|
// Increase counter
|
||||||
this.object.data.counters[score]++;
|
this.object.data.counters[score]++;
|
||||||
|
|
||||||
|
@ -90,16 +102,32 @@ export class OseCharacterCreator extends FormApplication {
|
||||||
data: data,
|
data: data,
|
||||||
skipDialog: true,
|
skipDialog: true,
|
||||||
speaker: ChatMessage.getSpeaker({ actor: this }),
|
speaker: ChatMessage.getSpeaker({ actor: this }),
|
||||||
flavor: game.i18n.format('OSE.dialog.generateScore', {score: label, count: this.object.data.counters[score]}),
|
flavor: game.i18n.format('OSE.dialog.generateScore', { score: label, count: this.object.data.counters[score] }),
|
||||||
title: game.i18n.format('OSE.dialog.generateScore', {score: label, count: this.object.data.counters[score]}),
|
title: game.i18n.format('OSE.dialog.generateScore', { score: label, count: this.object.data.counters[score] }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
super.close();
|
super.close();
|
||||||
|
// Gather scores
|
||||||
|
let scores = {};
|
||||||
|
$(this.form.children).find(".score-roll").each((_, d) => {
|
||||||
|
let gr = $(d).closest('.form-group');
|
||||||
|
let val = gr.find(".score-value").val();
|
||||||
|
scores[gr.data("score")] = val;
|
||||||
|
})
|
||||||
|
const gold = $(this.form.children).find('.gold-value').val();
|
||||||
const speaker = ChatMessage.getSpeaker({ actor: this });
|
const speaker = ChatMessage.getSpeaker({ actor: this });
|
||||||
|
const templateData = {
|
||||||
|
config: CONFIG.OSE,
|
||||||
|
scores: scores,
|
||||||
|
title: game.i18n.localize("OSE.dialog.generator"),
|
||||||
|
stats: this.object.data.stats,
|
||||||
|
gold: gold
|
||||||
|
}
|
||||||
|
const content = await renderTemplate("/systems/ose/templates/chat/roll-creation.html", templateData)
|
||||||
ChatMessage.create({
|
ChatMessage.create({
|
||||||
content: game.i18n.format("OSE.messages.creationFinished", {name: this.object.name}),
|
content: content,
|
||||||
speaker,
|
speaker,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -110,14 +138,14 @@ export class OseCharacterCreator extends FormApplication {
|
||||||
html.find('a.score-roll').click((ev) => {
|
html.find('a.score-roll').click((ev) => {
|
||||||
let el = ev.currentTarget.parentElement.parentElement;
|
let el = ev.currentTarget.parentElement.parentElement;
|
||||||
let score = el.dataset.score;
|
let score = el.dataset.score;
|
||||||
this.rollScore(score, {event: ev}).then(r => {
|
this.rollScore(score, { event: ev }).then(r => {
|
||||||
$(el).find('input').val(r.total).trigger('change');
|
$(el).find('input').val(r.total).trigger('change');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
html.find('a.gold-roll').click((ev) => {
|
html.find('a.gold-roll').click((ev) => {
|
||||||
let el = ev.currentTarget.parentElement.parentElement.parentElement;
|
let el = ev.currentTarget.parentElement.parentElement.parentElement;
|
||||||
this.rollScore("gold", {event: ev}).then(r => {
|
this.rollScore("gold", { event: ev }).then(r => {
|
||||||
$(el).find('.gold-value').val(r.total * 10);
|
$(el).find('.gold-value').val(r.total * 10);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -127,8 +155,8 @@ export class OseCharacterCreator extends FormApplication {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async _onSubmit(event, {updateData=null, preventClose=false, preventRender=false}={}) {
|
async _onSubmit(event, { updateData = null, preventClose = false, preventRender = false } = {}) {
|
||||||
super._onSubmit(event, {updateData: updateData, preventClose: preventClose, preventRender: preventRender});
|
super._onSubmit(event, { updateData: updateData, preventClose: preventClose, preventRender: preventRender });
|
||||||
// Generate gold
|
// Generate gold
|
||||||
let gold = event.target.elements.namedItem('gold').value;
|
let gold = event.target.elements.namedItem('gold').value;
|
||||||
const itemData = {
|
const itemData = {
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<section class="ose chat-message">
|
||||||
|
<div class="ose chat-block">
|
||||||
|
<div class="flexrow chat-header">
|
||||||
|
<div class="chat-title"><h2>{{title}}</h2></div>
|
||||||
|
<div class="chat-img" style="background-image:url('{{data.img}}')"></div>
|
||||||
|
</div>
|
||||||
|
<div class="flexrow">
|
||||||
|
<ol class="flex2">
|
||||||
|
{{#each scores as |score id|}}
|
||||||
|
<li class="flexrow">
|
||||||
|
<div style="text-align:right;">
|
||||||
|
{{lookup ../config.scores id}}
|
||||||
|
</div>
|
||||||
|
<div style="text-align:center;">
|
||||||
|
{{score}}
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{{/each}}
|
||||||
|
</ol>
|
||||||
|
<div style="margin: 0.5em 0">
|
||||||
|
<div>Sum: {{stats.sum}}</div>
|
||||||
|
<div>Avg: {{stats.avg}}</div>
|
||||||
|
<div>σ: {{stats.std}}</div>
|
||||||
|
<hr>
|
||||||
|
<div>Gold: {{gold}}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
Loading…
Reference in New Issue