Skip to content

Commit

Permalink
Feat/resume (#127)
Browse files Browse the repository at this point in the history
* feat: add resume application

* feat: switch resume to line template

* feat: allow to open/close resume application
  • Loading branch information
Armaklan authored and mattraykowski committed Jun 9, 2023
1 parent 840279c commit 37b7767
Show file tree
Hide file tree
Showing 14 changed files with 363 additions and 18 deletions.
57 changes: 57 additions & 0 deletions css/svnsea2e.css
Original file line number Diff line number Diff line change
Expand Up @@ -939,4 +939,61 @@ input[type=range]::-webkit-slider-thumb {
.item .sheet-header .item-subtitle {
font-size: 0.8em;
opacity: 0.5;
}

.toolbox {
font-size: 0.8em;
}
.toolbox .window-content {
background: none;
color: white;
}
.toolbox .items {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
gap: 8px;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
padding-bottom: 16px;
padding-right: 8px;
}
.toolbox .actor-resume {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-flex: 1;
-ms-flex: 1 1 100%;
flex: 1 1 100%;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.toolbox .actor-resume h3 {
text-align: center;
padding: 0;
margin: 0;
color: white;
}
.toolbox .score-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-pack: distribute;
justify-content: space-around;
gap: 16px;
}
.toolbox .score-container > div {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
5 changes: 4 additions & 1 deletion lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,8 @@
"SVNSEA2E.UseForMe": "Use for me",
"SVNSEA2E.UseForHelpMe": "Use for help me",
"SVNSEA2E.NotEnoughHero": "Not enough hero points",
"SVNSEA2E.JoieDeVivre": "Joie de Vivre"
"SVNSEA2E.JoieDeVivre": "Joie de Vivre",
"SVNSEA2E.Toolbox": "Toolbox",
"SVNSEA2E.EmptyToolbox": "Drop some actor here",
"SVNSEA2E.OpenToolbox": "Open toolbox"
}
5 changes: 4 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,8 @@
"SVNSEA2E.UseForMe": "Use for me",
"SVNSEA2E.UseForHelpMe": "Use for help me",
"SVNSEA2E.NotEnoughHero": "Not enough hero points",
"SVNSEA2E.JoieDeVivre": "Joie de Vivre"
"SVNSEA2E.JoieDeVivre": "Joie de Vivre",
"SVNSEA2E.Toolbox": "Toolbox",
"SVNSEA2E.EmptyToolbox": "Drop some actor here",
"SVNSEA2E.OpenToolbox": "Open toolbox"
}
5 changes: 4 additions & 1 deletion lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,8 @@
"SVNSEA2E.UseForMe": "Use for me",
"SVNSEA2E.UseForHelpMe": "Use for help me",
"SVNSEA2E.NotEnoughHero": "Not enough hero points",
"SVNSEA2E.JoieDeVivre": "Joie de Vivre"
"SVNSEA2E.JoieDeVivre": "Joie de Vivre",
"SVNSEA2E.Toolbox": "Toolbox",
"SVNSEA2E.EmptyToolbox": "Drop some actor here",
"SVNSEA2E.OpenToolbox": "Open toolbox"
}
5 changes: 4 additions & 1 deletion lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,8 @@
"SVNSEA2E.UseForMe": "Utilisé pour moi",
"SVNSEA2E.UseForHelpMe": "Utilisé pour m'aider",
"SVNSEA2E.NotEnoughHero": "Pas assez de points d'héroïsme",
"SVNSEA2E.JoieDeVivre": "Joie de Vivre"
"SVNSEA2E.JoieDeVivre": "Joie de Vivre",
"SVNSEA2E.EmptyToolbox": "Glisser des acteurs ici",
"SVNSEA2E.Toolbox": "Boite à outils",
"SVNSEA2E.OpenToolbox": "Ouvrir la boite à outils"
}
5 changes: 4 additions & 1 deletion lang/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,8 @@
"SVNSEA2E.AddOneToDice": "Aggiungi 1 al dado",
"SVNSEA2E.AddOneToDiced": "+1 aggiunto a tutti i dadi.",
"SVNSEA2E.AddToInitiativeTracker": "Aggiungi all'iniziativa",
"SVNSEA2E.Initiative": "Incrementi"
"SVNSEA2E.Initiative": "Incrementi",
"SVNSEA2E.Toolbox": "Toolbox",
"SVNSEA2E.EmptyToolbox": "Drop some actor here",
"SVNSEA2E.OpenToolbox": "Open toolbox"
}
5 changes: 4 additions & 1 deletion lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,8 @@
"SVNSEA2E.UseForMe": "Usado por mim",
"SVNSEA2E.UseForHelpMe": "Usado para me ajudar",
"SVNSEA2E.NotEnoughHero": "Pontos heroicos insuficientes",
"SVNSEA2E.JoieDeVivre": "Joie de Vivre"
"SVNSEA2E.JoieDeVivre": "Joie de Vivre",
"SVNSEA2E.Toolbox": "Toolbox",
"SVNSEA2E.EmptyToolbox": "Drop some actor here",
"SVNSEA2E.OpenToolbox": "Open toolbox"
}
2 changes: 1 addition & 1 deletion module/actor/sheets/hero.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ActorSheetSS2e from './base.js';
import { getItems, skillsToSheetData } from '../../helpers.js';
import ActorSheetSS2e from './base.js';
/**
* Extend the basic ActorSheet with some very simple modifications
* @ext'../../dice.js't}
Expand Down
41 changes: 30 additions & 11 deletions module/svnsea2e.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
// Import Modules
import { SVNSEA2E } from './config.js';
import { preloadHandlebarsTemplates } from './templates.js';
import { registerSystemSettings } from './settings.js';
import { preloadHandlebarsTemplates } from './templates.js';

// Import Applications
import { SvnSea2EActor } from './actor/actor.js';
import { ActorSheetSS2ePlayerCharacter } from './actor/sheets/playercharacter.js';
import { ActorSheetSS2eHero } from './actor/sheets/hero.js';
import { ActorSheetSS2eBrute } from './actor/sheets/brute.js';
import { ActorSheetSS2eDangerPts } from './actor/sheets/dangerpts.js';
import { ActorSheetSS2eHero } from './actor/sheets/hero.js';
import { ActorSheetSS2eMonster } from './actor/sheets/monster.js';
import { ActorSheetSS2eVillain } from './actor/sheets/villain.js';
import { ActorSheetSS2ePlayerCharacter } from './actor/sheets/playercharacter.js';
import { ActorSheetSS2eShip } from './actor/sheets/ship.js';
import { ActorSheetSS2eDangerPts } from './actor/sheets/dangerpts.js';
import { ActorSheetSS2eVillain } from './actor/sheets/villain.js';
import { SvnSea2EItem } from './item/item.js';
import { ItemSheetSS2eAdvantage } from './item/sheets/advantage.js';
import { ItemSheetSS2eArtifact } from './item/sheets/artifact.js';
import { ItemSheetSS2eBackground } from './item/sheets/background.js';
import { ItemSheetSS2eDuelStyle } from './item/sheets/duelstyle.js';
import { ItemSheetSS2eMonsterQuality } from './item/sheets/monsterquality.js';
import { ItemSheetSS2eSecretSociety } from './item/sheets/secretsociety.js';
import { ItemSheetSS2eScheme } from './item/sheets/scheme.js';
import { ItemSheetSS2eSecretSociety } from './item/sheets/secretsociety.js';
import { ItemSheetSS2eShipAdventure } from './item/sheets/shipadventure.js';
import { ItemSheetSS2eShipBackground } from './item/sheets/shipbackground.js';
import { ItemSheetSS2eSorcery } from './item/sheets/sorcery.js';
import { ItemSheetSS2eStory } from './item/sheets/story.js';
import LanguageSelector from './apps/language-selector.js';
import SkillSelector from './apps/skill-selector.js';

import * as migrations from './migration.js';
import { ItemSheetSS2eVirtue } from './item/sheets/virtue.js';
import { ItemSheetSS2eHubris } from './item/sheets/hubris.js';
import { chatEventHandler } from './eventhandler.js';
import { ItemSheetSS2eHubris } from './item/sheets/hubris.js';
import { ItemSheetSS2eVirtue } from './item/sheets/virtue.js';
import * as migrations from './migration.js';
import { emitCharacterChange } from './toolbox/socket.js';
import { Toolbox } from './toolbox/toolbox.js';

Hooks.once('init', async function () {
console.log(`7th Sea 2E | Initializing 7th Sea Second Edition System
Expand All @@ -42,6 +42,7 @@ Hooks.once('init', async function () {
},
config: SVNSEA2E,
migrations: migrations,
toolbox: new Toolbox(),
};

/**
Expand Down Expand Up @@ -240,6 +241,8 @@ Hooks.once('ready', async function () {
}

chatEventHandler();

game.svnsea2e.toolbox.render(true);
});

/* -------------------------------------------- */
Expand Down Expand Up @@ -306,6 +309,22 @@ Hooks.on('preCreateActor', function (document, entity, options, userId) {
});
});

Hooks.on('updateActor', function () {
emitCharacterChange();
});

Hooks.on('renderActorDirectory', (app, html, data) => {
if (game.user.isGM) {
const button = document.createElement('button');
button.style.width = '95%';
button.innerHTML = game.i18n.localize('SVNSEA2E.OpenToolbox');
button.addEventListener('click', () => {
game.svnsea2e.toolbox.render(true);
});
html.find('.header-actions').after(button);
}
});

async function getAllPackAdvantages() {
const advantages = [];
const packs = game.packs.entries;
Expand Down
32 changes: 32 additions & 0 deletions module/toolbox/socket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const SOCKET_NAME = 'system.svnsea2e';
export const actions = {
characterChange: 'characterChanged',
};

export function registerSocketListeners() {
game.socket.on(SOCKET_NAME, (payload) => {
switch (payload.type) {
case actions.characterChange:
refreshToolbox(payload);
break;

default:
console.warn(
new Error('L5R5E | This socket event is not supported'),
payload,
);
break;
}
});
}

export function emitCharacterChange() {
game.svnsea2e.toolbox.refresh();
game.socket.emit(SOCKET_NAME, {
type: actions.characterChange,
});
}

function refreshToolbox() {
game.svnsea2e.toolbox.refresh();
}
144 changes: 144 additions & 0 deletions module/toolbox/toolbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
* L5R GM Toolbox dialog
* @extends {FormApplication}
*/
export class Toolbox extends FormApplication {
/**
* Settings
*/
object = {};

/**
* Assign the default options
* @override
*/
static get defaultOptions() {
const x = $(window).width();
const y = $(window).height();
return mergeObject(super.defaultOptions, {
id: 'svnsea-toolbox',
classes: ['toolbox'],
template: 'systems/svnsea2e/templates/toolbox/toolbox.html',
title: game.i18n.localize('SVNSEA2E.Toolbox'),
left: x - 650,
top: 20,
width: 300,
closeOnSubmit: false,
submitOnClose: false,
submitOnChange: true,
minimizable: true,
resizable: true,
dragDrop: [{ dropSelector: '.items' }],
});
}

/**
* Constructor
* @param {ApplicationOptions} options
*/
constructor(options = {}) {
super(options);
this._initialize();
}

/**
* Refresh data (used from socket)
*/
async refresh() {
if (!game.user.isGM) {
return;
}
this.object.showActors = this.object.items.map((it) =>
game.actors.find((a) => `Actor.${a.id}` === it),
);
this.render(false);
}

/**
* Initialize the values
* @private
*/
_initialize() {
this.object = {
items: [],
};
}

/**
* @override
*/
render(force = false, options = {}) {
if (!game.user.isGM) {
return;
}
this.position.height = 'auto';
return super.render(force, options);
}

/**
* Construct and return the data object used to render the HTML template for this form application.
* @param options
* @return {Object}
* @override
*/
async getData(options = null) {
const data = await super.getData(options);
return {
...data,
};
}

/**
* Listen to html elements
* @param {jQuery} html HTML content of the sheet.
* @override
*/
activateListeners(html) {
super.activateListeners(html);
}

/**
* This method is called upon form submission after form data is validated
* @param event The initial triggering submission event
* @param formData The object of validated form data with which to update the object
* @returns A Promise which resolves once the update operation has completed
* @override
*/
async _updateObject(event, formData) {
this.render(false);
}

/** @override */
async _onDrop(event) {
if (!game.user.isGM) {
return;
}
event.preventDefault();

// Get dropped data
let data;
try {
data = JSON.parse(event.dataTransfer.getData('text/plain'));
} catch (err) {
return false;
}
if (!data) return false;

// Case 2 - Dropped Actor
if (data.type === 'Actor') {
return this._onDropActor(event, data);
}
}

/**
* Handle dropping an Actor on the sheet to trigger a Polymorph workflow
* @param {DragEvent} event The drop event
* @param {Object} data The data transfer
* @return {Object} OwnedItem data _getIndexeso create
* @private
*/
async _onDropActor(event, data) {
this.object.items.push(data.uuid);
this.refresh();
}
}
Loading

0 comments on commit 37b7767

Please sign in to comment.