Enhance sheets

This commit is contained in:
2021-02-03 15:33:07 +01:00
parent c65f1b8246
commit d248411e90
10 changed files with 276 additions and 13 deletions

View File

@ -168,8 +168,6 @@ export class SoSActor extends Actor {
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/dialog-flip.html', flipData);
new SoSFlipDialog(flipData, html).render(true);
//console.log("STAT", this);
//let result = this.cardDeck.doFlipStat( duplicate(this.data.data.stat[statKey]) );
}
/* -------------------------------------------- */

30
module/sos-combat.js Normal file
View File

@ -0,0 +1,30 @@
import { SoSCardDeck } from "./sos-card-deck.js";
import { SoSUtility } from "./sos-utility.js";
import { SoSFlipDialog } from "./sos-flip-dialog.js";
import { SoSDialogCombatActions } from "./sos-dialog-combat-actions.js";
/* -------------------------------------------- */
export class SoSCombat extends Combat {
/* -------------------------------------------- */
async nextRound() {
console.log("NEXT ROUND !!!!");
if ( game.user.isGM ) {
ChatMessage.create( { content: `New round !! Click on the button below to declare your actions for round ${this.round} !<br>
<a class='chat-card-button' id='button-declare-actions' data-combat-id='${this._id} data-round='${this.round}'>Declare actions</a>`,
whisper: game.users.map(user => user.data._id) } );
}
super.nextRound();
}
/* -------------------------------------------- */
setupActorActions(actionConf) {
if ( !this.phaseSetup) this.phaseSetup = []; // Opportunistic init
if ( !this.phaseSetup[this.round] ) this.phaseSetup[this.round] = {}; // Bis
// Keep track
this.phaseSetup[this.round][actionConf.userId] = actionConf;
}
}

View File

@ -0,0 +1,130 @@
import { SoSUtility } from "./sos-utility.js";
/* -------------------------------------------- */
export class SoSDialogCombatActions extends Dialog {
/* -------------------------------------------- */
static async create( combatId, round ) {
let combatActions = {
actionsList: await SoSUtility.loadCompendium( 'foundryvtt-shadows-over-sol.combat-actions' ),
actionPoints: SoSUtility.fillRange(0, 6),
combatId: combatId,
round: round
}
for ( let i=0; i<combatActions.actionsList.length; i++) {
if ( combatActions.actionsList[i].name == 'No Action') {
combatActions.noActionId = i;
}
}
//console.log("ACTIONS", combatActions.actionsList );
let html = await renderTemplate('systems/foundryvtt-shadows-over-sol/templates/dialog-combat-actions.html', combatActions);
return new SoSDialogCombatActions(combatActions, html );
}
/* -------------------------------------------- */
constructor(combatActions, html, options = {} ) {
let dialogConf = {
title: "Combat Actions",
content: html,
buttons: {
validate: {
icon: '<i class="fas fa-check"></i>',
label: "Validate",
callback: (html) => { this.validateActions(html) }
}
},
default: "validate"
};
super(dialogConf, options);
this.combatActions = combatActions;
}
/* -------------------------------------------- */
async close() {
let ap = Number($('#remain-ap').text());
if ( ap >= 0 ) {
super.close();
let action3Index = $('#action3').val();
let action3 = duplicate(this.combatActions.actionsList[action3Index]);
let action2Index = $('#action2').val();
let action2 = duplicate(this.combatActions.actionsList[action2Index]._id);
let action1Index = $('#action1').val();
let action1 = duplicate(this.combatActions.actionsList[action1Index]._id);
game.socket.emit("system.foundryvtt-reve-de-dragon", {
name: "msg_declare_actions", data: {
userId: game.userId,
phaseArray: [ action1, action2, action3],
remainingAP: ap
} } );
} else {
ui.notifications.warn("Action Points are below 0 ! Please check your phases !");
}
}
/* -------------------------------------------- */
validateActions( html ) {
}
/* -------------------------------------------- */
resetAP() {
let maxAP = $('#actionMax').val();
$('#remain-ap').text( maxAP);
$('#action3').val( this.combatActions.noActionId );
$('#action2').val( this.combatActions.noActionId );
$('#action1').val( this.combatActions.noActionId );
$('#action3').prop('disabled', false);
$('#action2').prop('disabled', false);
$('#action1').prop('disabled', false);
}
/* -------------------------------------------- */
updateAP( ) {
let remainAP = $('#actionMax').val();
let action3Index = $('#action3').val();
if ( this.combatActions.actionsList[action3Index].name != 'No Action') {
remainAP -= 3;
}
let action2Index = $('#action2').val();
if ( this.combatActions.actionsList[action2Index].name != 'No Action') {
remainAP -= 2;
}
let action1Index = $('#action1').val();
if ( this.combatActions.actionsList[action1Index].name != 'No Action') {
remainAP -= 1;
}
$('#remain-ap').text( remainAP);
if ( remainAP < 0 ) {
$("#remain-ap").addClass("text-red");
ui.notifications.warn("No more Action Points ! Please check your phases !");
} else {
$("#remain-ap").removeClass("text-red");
}
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
html.find('#actionMax').change((event) => {
this.resetAP( );
});
html.find('.action-select').change((event) => {
this.updateAP( );
});
}
}

View File

@ -12,6 +12,7 @@ import { SoSActor } from "./actor.js";
import { SoSItemSheet } from "./item-sheet.js";
import { SoSActorSheet } from "./actor-sheet.js";
import { SoSUtility } from "./sos-utility.js";
import { SoSCombat } from "./sos-combat.js";
/* -------------------------------------------- */
/* Foundry VTT Initialization */
@ -51,6 +52,7 @@ Hooks.once("init", async function () {
/* -------------------------------------------- */
// Define custom Entity classes
CONFIG.Actor.entityClass = SoSActor;
CONFIG.Combat.entityClass = SoSCombat;
CONFIG.SoS = {
}
@ -61,6 +63,11 @@ Hooks.once("init", async function () {
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("foundryvtt-shadows-over-sol", SoSItemSheet, { makeDefault: true });
// Init/registers
Hooks.on('renderChatLog', (log, html, data) => {
SoSUtility.registerChatCallbacks(html);
});
// Patch the initiative formula
_patch_initiative();

View File

@ -1,5 +1,8 @@
/* -------------------------------------------- */
import { SoSDialogCombatActions } from "./sos-dialog-combat-actions.js";
export class SoSUtility {
/* -------------------------------------------- */
export class SoSUtility {
/* -------------------------------------------- */
static async preloadHandlebarsTemplates() {
@ -24,6 +27,14 @@ export class SoSUtility {
return Array(end - start + 1).fill().map((item, index) => start + index);
}
/* -------------------------------------------- */
onSocketMesssage( msg ) {
if (msg.name == 'msg_declare_actions' ) {
let combat = game.combats.get( msg.data.combatId); // Get the associated combat
combat.setupActorActions( msg.data );
}
}
/* -------------------------------------------- */
static async loadCompendiumNames(compendium) {
const pack = game.packs.get(compendium);
@ -49,4 +60,21 @@ export class SoSUtility {
return list;
}
/* -------------------------------------------- */
static async openDeclareActions( event) {
event.preventDefault();
let round = event.currentTarget.attributes['data-round'].value;
let combatId = event.currentTarget.attributes['data-combat-id'].value;
let d = await SoSDialogCombatActions.create( combatId, round );
d.render(true);
}
/* -------------------------------------------- */
static async registerChatCallbacks(html) {
html.on("click", '#button-declare-actions', event => {
SoSUtility.openDeclareActions( event );
});
}
}