Skip to content

Commit

Permalink
Remove forms from template and implement them with localization in th…
Browse files Browse the repository at this point in the history
…eir own dataprep file
  • Loading branch information
Veilza committed Aug 30, 2024
1 parent 77b1919 commit b7ad8c6
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 163 deletions.
2 changes: 1 addition & 1 deletion display/wta/actors/parts/forms.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="flexrow grid grid-5col forms">
{{#each actor.system.forms as |form id|}}
<div>
<label class="resource-label were-form-name"><h3>{{localize form.name}}</h3></label>
<label class="resource-label were-form-name"><h3>{{localize form.displayName}}</h3></label>
<div class="were-form-title flexcol flex-center">
<label class="were-form-nickname">{{localize form.nickname}}</label>
</div>
Expand Down
45 changes: 22 additions & 23 deletions system/actor/wta/scripts/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const _onLostTheWolf = async function (actor) {
if (actor.system.lostTheWolf) return

// Update the listTheWolf key
actor.update({ 'system.lostTheWolf': true })
await actor.update({ 'system.lostTheWolf': true })

// Define the template to be used
const template = `
Expand All @@ -29,19 +29,19 @@ export const _onLostTheWolf = async function (actor) {
homid: {
label: 'Homid',
callback: async () => {
actor.update({ 'system.activeForm': 'homid' })
await actor.update({ 'system.activeForm': 'homid' })
}
},
lupus: {
label: 'Lupus',
callback: async () => {
actor.update({ 'system.activeForm': 'lupus' })
await actor.update({ 'system.activeForm': 'lupus' })
}
}
}

new Dialog({
title: 'Lost the Wolf',
title: game.i18n.localize('WOD5E.WTA.LostTheWolf'),
content: template,
buttons,
default: 'homid'
Expand All @@ -62,21 +62,21 @@ export const _onShiftForm = async function (event) {

switch (form) {
case 'glabro':
this.handleFormChange(actor, 'glabro', 1)
await handleFormChange(actor, 'glabro', 1)
break
case 'crinos':
this.handleFormChange(actor, 'crinos', 2)
await handleFormChange(actor, 'crinos', 2)
break
case 'hispo':
this.handleFormChange(actor, 'hispo', 1)
await handleFormChange(actor, 'hispo', 1)
break
case 'lupus':
actor.update({ 'system.activeForm': 'lupus' })
this._onFormToChat(event)
await actor.update({ 'system.activeForm': 'lupus' })
await _onFormToChat(event, actor)
break
default:
actor.update({ 'system.activeForm': 'homid' })
this._onFormToChat(event)
await actor.update({ 'system.activeForm': 'homid' })
await _onFormToChat(event, actor)
}
}

Expand All @@ -86,11 +86,10 @@ export const handleFormChange = async function (actor, form, diceCount) {

// If automatedRage is turned on and the actor's rage is 0, present a warning
if (game.settings.get('vtm5e', 'automatedRage') && actor.system.rage.value === 0) {
this._onInsufficientRage(form)
_onInsufficientRage(actor, form)
} else {
// Variables
const formData = actor.system.forms[form]
const flavor = formData.description

// Handle getting any situational modifiers
const activeBonuses = await getActiveBonuses({
Expand All @@ -99,17 +98,17 @@ export const handleFormChange = async function (actor, form, diceCount) {
})

// Roll the rage dice necessary
WOD5eDice.Roll({
await WOD5eDice.Roll({
advancedDice: diceCount + activeBonuses.totalValue,
title: form,
flavor: formData.description,
actor,
data: actor.system,
flavor,
quickRoll: true,
disableBasicDice: true,
decreaseRage: true,
selectors,
callback: (err, rollData) => {
callback: async (err, rollData) => {
if (err) console.log(err)

// Calculate the number of rage dice the actor has left
Expand All @@ -118,25 +117,25 @@ export const handleFormChange = async function (actor, form, diceCount) {

// If rolling rage dice didn't reduce the actor to 0 rage, then update the current form
if (newRageAmount > 0) {
actor.update({ 'system.activeForm': form })
await actor.update({ 'system.activeForm': form })
}
}
})
}
}

export const _onFormToChat = async function (event) {
export const _onFormToChat = async function (event, originActor) {
event.preventDefault()

// Top-level variables
const actor = this.actor
const actor = originActor || this.actor
const element = event.currentTarget
const dataset = Object.assign({}, element.dataset)
const form = dataset.form

// Secondary variables
const formData = actor.system.forms[form]
const formName = formData.name
const formName = formData.displayName
const formDescription = formData.description ? `<p>${formData.description}</p>` : ''
const formAbilities = formData.attributes

Expand Down Expand Up @@ -171,7 +170,7 @@ export const _onFormEdit = async function (event) {

// Secondary variables
const formData = actor.system.forms[form]
const formName = formData.name
const formName = formData.displayName
const formDescription = formData.description

// Variables yet to be defined
Expand All @@ -193,7 +192,7 @@ export const _onFormEdit = async function (event) {
callback: async (html) => {
const newDescription = html.find('#formDescription')[0].value

actor.update({ [`system.forms.${form}.description`]: newDescription })
await actor.update({ [`system.forms.${form}.description`]: newDescription })
}
},
cancel: {
Expand Down Expand Up @@ -232,7 +231,7 @@ export const _onInsufficientRage = async function (actor, form) {
icon: '<i class="fas fa-check"></i>',
label: 'Shift Anyway',
callback: async () => {
actor.update({ 'system.activeForm': form })
await actor.update({ 'system.activeForm': form })
}
},
cancel: {
Expand Down
31 changes: 31 additions & 0 deletions system/actor/wta/scripts/prepare-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,34 @@ export const prepareRiteData = async function (sheetData) {

return rites
}

// Handle form data
export const prepareFormData = async function (sheetData) {
const wereForms = WOD5E.WereForms.getList({})

// Fields to keep from the existing data
const fieldsToKeep = [
'description'
]

// Merge new form data with existing form data
const mergedForms = {}
for (const formKey in wereForms) {
if (Object.prototype.hasOwnProperty.call(wereForms, formKey)) {
// Start with the new form data
mergedForms[formKey] = { ...wereForms[formKey] }

// Check if the existing form data has additional fields
if (sheetData.actor.system.forms[formKey]) {
// Add fields to keep from the existing form data
for (const field of fieldsToKeep) {
if (sheetData.actor.system.forms[formKey][field] !== undefined) {
mergedForms[formKey][field] = sheetData.actor.system.forms[formKey][field]
}
}
}
}
}

return mergedForms
}
6 changes: 4 additions & 2 deletions system/actor/wta/werewolf-actor-sheet.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* global game, foundry */

import { WoDActor } from '../wod-v5-sheet.js'
import { _prepareWerewolfItems, prepareGiftData, prepareRiteData } from './scripts/prepare-data.js'
import { _prepareWerewolfItems, prepareGiftData, prepareRiteData, prepareFormData } from './scripts/prepare-data.js'
import { _onAddGift, _onRemoveGift, _onGiftToChat } from './scripts/gifts.js'
import { _onBeginFrenzy, _onEndFrenzy } from './scripts/frenzy.js'
import { _onShiftForm, _onFormToChat, _onFormEdit } from './scripts/forms.js'
import { _onHaranoRoll, _onHaugloskRoll } from './scripts/balance.js'
import { _onLostTheWolf } from './scripts/forms.js'

/**
* Extend the basic ActorSheet with some very simple modifications
Expand Down Expand Up @@ -44,6 +45,7 @@ export class WerewolfActorSheet extends WoDActor {
// Prepare gifts and rites data
data.actor.system.gifts = await prepareGiftData(data)
data.actor.system.rites = await prepareRiteData(data)
data.actor.system.forms = await prepareFormData(data)

// If the actor's rage is above 0, make sure they aren't in "lost the wolf" form
if (data.actor.system.rage.value > 0 && data.actor.system.lostTheWolf) {
Expand All @@ -53,7 +55,7 @@ export class WerewolfActorSheet extends WoDActor {
// Check if the actor's rage is 0, they're in a supernatural form, and they haven't already lost the wolf
const supernaturalForms = ['glabro', 'crinos', 'hispo']
if ((data.actor.system.rage.value === 0) && (supernaturalForms.indexOf(data.actor.system.activeForm) > -1)) {
this._onLostTheWolf()
_onLostTheWolf(this.actor)
}

return data
Expand Down
48 changes: 31 additions & 17 deletions system/api/def/were-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export class WereForms extends BaseDefinitionClass {
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
// Initialize the nickname label too
value.nickname = game.i18n.localize(value.nickname)

// Localize the Werewolf attributes
value.attributes = value.attributes.map(attribute => {
return game.i18n.localize(attribute)
})
}
}
}
Expand All @@ -24,26 +29,31 @@ export class WereForms extends BaseDefinitionClass {
label: 'WOD5E.WTA.HomidName',
nickname: 'WOD5E.WTA.HomidTitle',
cost: 0,
attributes: ['Silver Immunity']
attributes: [
'WOD5E.WTA.SilverImmunity'
]
}

static lupus = {
label: 'WOD5E.WTA.LupusName',
nickname: 'WOD5E.WTA.LupusTitle',
cost: 0,
attributes: ['Silver Immunity', 'Social Tests: Limited to wolves and Garou']
attributes: [
'WOD5E.WTA.SilverImmunity',
'WOD5E.WTA.LupusSocialTests'
]
}

static hispo = {
label: 'WOD5E.WTA.HispoName',
nickname: 'WOD5E.WTA.HispoTitle',
cost: 1,
attributes: [
'(Non-Stealth) Physical Tests: +2',
'Stealth Tests: -2',
'Social Tests: Limited to wolves and Garou',
'Regenerate: 1/Rage Check',
'Bite: +1 Aggravated'
'WOD5E.WTA.HispoPhysicalTests',
'WOD5E.WTA.HispoStealthTests',
'WOD5E.WTA.HispoSocialTests',
'WOD5E.WTA.HispoRegenerate',
'WOD5E.WTA.HispoBite'
],
bonuses: [
{
Expand Down Expand Up @@ -74,7 +84,11 @@ export class WereForms extends BaseDefinitionClass {
label: 'WOD5E.WTA.GlabroName',
nickname: 'WOD5E.WTA.GlabroTitle',
cost: 1,
attributes: ['Physical Tests: +2', 'Social Tests: -2', 'Regenerate: 1/Rage Check'],
attributes: [
'WOD5E.WTA.GlabroPhysicalTests',
'WOD5E.WTA.GlabroSocialTests',
'WOD5E.WTA.GlabroRegenerate'
],
bonuses: [
{
source: 'WOD5E.WTA.GlabroName',
Expand Down Expand Up @@ -104,15 +118,15 @@ export class WereForms extends BaseDefinitionClass {
nickname: 'WOD5E.WTA.CrinosTitle',
cost: 2,
attributes: [
'Frenzy Risk, 1 Willpower/turn',
'Physical Tests: +4',
'Health: +4',
'Social Tests: Auto-failure',
'Mental Tests: Auto-failure',
'Regenerate: 2/Rage Check',
'Claws: +3',
'Bite: +1 Aggravated',
'Causes Delirium'
'WOD5E.WTA.CrinosFrenzy',
'WOD5E.WTA.CrinosPhysicalTests',
'WOD5E.WTA.CrinosHealth',
'WOD5E.WTA.CrinosSocialTests',
'WOD5E.WTA.CrinosMentalTests',
'WOD5E.WTA.CrinosRegenerate',
'WOD5E.WTA.CrinosClaws',
'WOD5E.WTA.CrinosBite',
'WOD5E.WTA.CausesDelirium'
],
bonuses: [
{
Expand Down
Loading

0 comments on commit b7ad8c6

Please sign in to comment.