mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Combat and CombatTracker (#108)
* Added Combat and CombatTracker * Some cleneaup * Fixing and cleaning up * Added categories for combatants * Style improvements * Layout change
This commit is contained in:
parent
32730b3aac
commit
aa8fe6a7a1
23 changed files with 730 additions and 684 deletions
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
/**
|
||||
|
|
@ -10,101 +9,101 @@ const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
|||
*/
|
||||
|
||||
export default class Resources extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(options={}) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
id: "resources",
|
||||
classes: [],
|
||||
tag: "div",
|
||||
window: {
|
||||
frame: true,
|
||||
title: "Fear",
|
||||
positioned: true,
|
||||
resizable: true,
|
||||
minimizable: false
|
||||
},
|
||||
actions: {
|
||||
setFear: Resources.setFear,
|
||||
increaseFear: Resources.increaseFear
|
||||
},
|
||||
position: {
|
||||
width: 222,
|
||||
height: 222,
|
||||
// top: "200px",
|
||||
// left: "120px"
|
||||
constructor(options = {}) {
|
||||
super(options);
|
||||
}
|
||||
};
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
resources: {
|
||||
root: true,
|
||||
template: "systems/daggerheart/templates/views/resources.hbs"
|
||||
// template: "templates/ui/players.hbs"
|
||||
/** @inheritDoc */
|
||||
static DEFAULT_OPTIONS = {
|
||||
id: 'resources',
|
||||
classes: [],
|
||||
tag: 'div',
|
||||
window: {
|
||||
frame: true,
|
||||
title: 'Fear',
|
||||
positioned: true,
|
||||
resizable: true,
|
||||
minimizable: false
|
||||
},
|
||||
actions: {
|
||||
setFear: Resources.setFear,
|
||||
increaseFear: Resources.increaseFear
|
||||
},
|
||||
position: {
|
||||
width: 222,
|
||||
height: 222
|
||||
// top: "200px",
|
||||
// left: "120px"
|
||||
}
|
||||
};
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
resources: {
|
||||
root: true,
|
||||
template: 'systems/daggerheart/templates/views/resources.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
get currentFear() {
|
||||
return game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
}
|
||||
};
|
||||
|
||||
get currentFear() {
|
||||
return game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear);
|
||||
}
|
||||
get maxFear() {
|
||||
return game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.MaxFear);
|
||||
}
|
||||
|
||||
get maxFear() {
|
||||
return game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.MaxFear);
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
/* Rendering */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Rendering */
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
async _prepareContext(_options) {
|
||||
const display = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.DisplayFear),
|
||||
current = this.currentFear,
|
||||
max = this.maxFear,
|
||||
percent = (current / max) * 100,
|
||||
isGM = game.user.isGM;
|
||||
// Return the data for rendering
|
||||
return { display, current, max, percent, isGM };
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _prepareContext(_options) {
|
||||
const display = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.DisplayFear),
|
||||
current = this.currentFear,
|
||||
max = this.maxFear,
|
||||
percent = (current / max) * 100,
|
||||
isGM = game.user.isGM;
|
||||
// Return the data for rendering
|
||||
return {display, current, max, percent, isGM};
|
||||
}
|
||||
/** @override */
|
||||
async _preFirstRender(context, options) {
|
||||
options.position = game.user.getFlag(SYSTEM.id, 'app.resources.position') ?? Resources.DEFAULT_OPTIONS.position;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _preFirstRender(context, options) {
|
||||
options.position = game.user.getFlag(SYSTEM.id, 'app.resources.position') ?? Resources.DEFAULT_OPTIONS.position;
|
||||
}
|
||||
/** @override */
|
||||
async _preRender(context, options) {
|
||||
if (this.currentFear > this.maxFear)
|
||||
await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear, this.maxFear);
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _preRender(context, options) {
|
||||
if(this.currentFear > this.maxFear) await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear, this.maxFear);
|
||||
}
|
||||
_onPosition(position) {
|
||||
game.user.setFlag(SYSTEM.id, 'app.resources.position', position);
|
||||
}
|
||||
|
||||
_onPosition(position) {
|
||||
game.user.setFlag(SYSTEM.id, 'app.resources.position', position);
|
||||
}
|
||||
async close(options = {}) {
|
||||
if (!options.allowed) return;
|
||||
else super.close(options);
|
||||
}
|
||||
|
||||
async close(options={}) {
|
||||
if(!options.allowed) return;
|
||||
else super.close(options);
|
||||
}
|
||||
static async setFear(event, target) {
|
||||
if (!game.user.isGM) return;
|
||||
const fearCount = Number(target.dataset.index ?? 0);
|
||||
await this.updateFear(this.currentFear === fearCount + 1 ? fearCount : fearCount + 1);
|
||||
}
|
||||
|
||||
static async setFear(event, target) {
|
||||
if(!game.user.isGM) return;
|
||||
const fearCount = Number(target.dataset.index ?? 0);
|
||||
await this.updateFear(this.currentFear === fearCount + 1 ? fearCount : fearCount + 1);
|
||||
}
|
||||
static async increaseFear(event, target) {
|
||||
let value = target.dataset.increment ?? 0,
|
||||
operator = value.split('')[0] ?? null;
|
||||
value = Number(value);
|
||||
await this.updateFear(operator ? this.currentFear + value : value);
|
||||
}
|
||||
|
||||
static async increaseFear(event, target) {
|
||||
let value = target.dataset.increment ?? 0,
|
||||
operator = value.split('')[0] ?? null;
|
||||
value = Number(value);
|
||||
await this.updateFear(operator ? this.currentFear + value : value);
|
||||
}
|
||||
|
||||
async updateFear(value) {
|
||||
if(!game.user.isGM) return;
|
||||
value = Math.max(0, Math.min(this.maxFear, value));
|
||||
await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear, value);
|
||||
}
|
||||
}
|
||||
async updateFear(value) {
|
||||
if (!game.user.isGM) return;
|
||||
value = Math.max(0, Math.min(this.maxFear, value));
|
||||
await game.settings.set(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear, value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue