Add effects and tabs
This commit is contained in:
@@ -12,3 +12,4 @@ export { default as PrismRPGMiracleSheet } from "./sheets/miracle-sheet.mjs"
|
||||
export { default as PrismRPGRaceSheet } from "./sheets/race-sheet.mjs"
|
||||
export { default as PrismRPGClassSheet } from "./sheets/class-sheet.mjs"
|
||||
export { default as PrismRPGCharacterPathSheet } from "./sheets/character-path-sheet.mjs"
|
||||
export { WeaponTypesConfig } from "./weapon-types-config.mjs"
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* Application to configure weapon types and groups
|
||||
*/
|
||||
import { getWeaponTypes, getWeaponGroups } from "../config/weapon.mjs"
|
||||
|
||||
export class WeaponTypesConfig extends FormApplication {
|
||||
|
||||
constructor(object, options) {
|
||||
super(object, options)
|
||||
|
||||
// Store working copies that won't trigger settings changes
|
||||
this.workingTypes = null
|
||||
this.workingGroups = null
|
||||
}
|
||||
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
title: game.i18n.localize("PRISMRPG.Settings.weaponTypesConfig.title"),
|
||||
id: "weapon-types-config",
|
||||
classes: ["prismrpg", "weapon-types-config"],
|
||||
template: "systems/fvtt-prism-rpg/templates/weapon-types-config.hbs",
|
||||
width: 1000,
|
||||
height: "auto",
|
||||
closeOnSubmit: true,
|
||||
submitOnChange: false,
|
||||
tabs: [{ navSelector: ".tabs", contentSelector: ".content", initial: "types" }]
|
||||
})
|
||||
}
|
||||
|
||||
getData() {
|
||||
const data = super.getData()
|
||||
|
||||
// Get default weapon types from config with proper translation keys
|
||||
const defaultTypes = getWeaponTypes()
|
||||
|
||||
// Get default weapon groups from config with proper translation keys
|
||||
const defaultGroups = getWeaponGroups()
|
||||
|
||||
// Initialize working copies on first render
|
||||
if (!this.workingTypes) {
|
||||
const customTypes = game.settings.get("fvtt-prism-rpg", "customWeaponTypes") || {}
|
||||
this.workingTypes = foundry.utils.deepClone(customTypes)
|
||||
}
|
||||
|
||||
if (!this.workingGroups) {
|
||||
const customGroups = game.settings.get("fvtt-prism-rpg", "customWeaponGroups") || {}
|
||||
this.workingGroups = foundry.utils.deepClone(customGroups)
|
||||
}
|
||||
|
||||
// Merge default and working copies
|
||||
data.weaponTypes = {}
|
||||
const mergedTypes = foundry.utils.mergeObject(defaultTypes, this.workingTypes, { inplace: false })
|
||||
console.log("Merged types in getData:", mergedTypes)
|
||||
for (const [key, type] of Object.entries(mergedTypes)) {
|
||||
data.weaponTypes[key] = {
|
||||
...type,
|
||||
// Translate label if it's a translation key
|
||||
label: type.label.startsWith("PRISMRPG.") ? game.i18n.localize(type.label) : type.label,
|
||||
// Mark if it's a custom type (can be deleted)
|
||||
isCustom: key.startsWith("custom_")
|
||||
}
|
||||
}
|
||||
|
||||
data.weaponGroups = {}
|
||||
const mergedGroups = foundry.utils.mergeObject(defaultGroups, this.workingGroups, { inplace: false })
|
||||
for (const [key, group] of Object.entries(mergedGroups)) {
|
||||
data.weaponGroups[key] = {
|
||||
...group,
|
||||
// Translate labels if they're translation keys
|
||||
label: group.label.startsWith("PRISMRPG.") ? game.i18n.localize(group.label) : group.label,
|
||||
passiveLabel: group.passiveLabel.startsWith("PRISMRPG.") ? game.i18n.localize(group.passiveLabel) : group.passiveLabel,
|
||||
passiveDescription: group.passiveDescription.startsWith("PRISMRPG.") ? game.i18n.localize(group.passiveDescription) : group.passiveDescription,
|
||||
// Mark if it's a custom group (can be deleted)
|
||||
isCustom: key.startsWith("custom_")
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html)
|
||||
|
||||
// Add new weapon type
|
||||
html.find('[data-action="add-weapon-type"]').click(this._onAddWeaponType.bind(this))
|
||||
|
||||
// Delete weapon type
|
||||
html.find('[data-action="delete-weapon-type"]').click(this._onDeleteWeaponType.bind(this))
|
||||
|
||||
// Add new weapon group
|
||||
html.find('[data-action="add-weapon-group"]').click(this._onAddWeaponGroup.bind(this))
|
||||
|
||||
// Delete weapon group
|
||||
html.find('[data-action="delete-weapon-group"]').click(this._onDeleteWeaponGroup.bind(this))
|
||||
|
||||
// Reset to defaults
|
||||
html.find('[data-action="reset-defaults"]').click(this._onResetDefaults.bind(this))
|
||||
|
||||
console.log("Listeners activated, weapon types count:", html.find('.weapon-type-entry').length)
|
||||
}
|
||||
|
||||
async _onAddWeaponType(event) {
|
||||
event.preventDefault()
|
||||
|
||||
const newId = `custom_${foundry.utils.randomID()}`
|
||||
|
||||
// Add new empty type to working copy (no settings save)
|
||||
this.workingTypes[newId] = {
|
||||
id: newId,
|
||||
label: "New Weapon Type",
|
||||
apc: 1,
|
||||
hands: 1
|
||||
}
|
||||
|
||||
// Force re-render without saving
|
||||
this.render(true)
|
||||
}
|
||||
|
||||
async _onDeleteWeaponType(event) {
|
||||
event.preventDefault()
|
||||
const typeId = $(event.currentTarget).data('id')
|
||||
|
||||
console.log("Delete weapon type clicked:", typeId)
|
||||
console.log("Working types before:", this.workingTypes)
|
||||
|
||||
// Delete from working copy (no settings save)
|
||||
delete this.workingTypes[typeId]
|
||||
|
||||
console.log("Working types after:", this.workingTypes)
|
||||
|
||||
// Save to settings immediately so it persists
|
||||
await game.settings.set("fvtt-prism-rpg", "customWeaponTypes", this.workingTypes)
|
||||
|
||||
// Find and remove the entry from DOM immediately
|
||||
this.element.find(`.weapon-type-entry[data-id="${typeId}"]`).remove()
|
||||
}
|
||||
|
||||
async _onAddWeaponGroup(event) {
|
||||
event.preventDefault()
|
||||
|
||||
const newId = `custom_${foundry.utils.randomID()}`
|
||||
|
||||
// Add new empty group to working copy (no settings save)
|
||||
this.workingGroups[newId] = {
|
||||
id: newId,
|
||||
label: "New Weapon Group",
|
||||
passive: "newPassive",
|
||||
passiveLabel: "New Passive",
|
||||
passiveDescription: "Description of the new passive ability."
|
||||
}
|
||||
|
||||
// Force re-render without saving
|
||||
this.render(true)
|
||||
}
|
||||
|
||||
async _onDeleteWeaponGroup(event) {
|
||||
event.preventDefault()
|
||||
const groupId = $(event.currentTarget).data('id')
|
||||
|
||||
// Delete from working copy (no settings save)
|
||||
delete this.workingGroups[groupId]
|
||||
|
||||
// Save to settings immediately so it persists
|
||||
await game.settings.set("fvtt-prism-rpg", "customWeaponGroups", this.workingGroups)
|
||||
|
||||
// Find and remove the entry from DOM immediately
|
||||
this.element.find(`.weapon-group-entry[data-id="${groupId}"]`).remove()
|
||||
}
|
||||
|
||||
async _onResetDefaults(event) {
|
||||
event.preventDefault()
|
||||
|
||||
const confirm = await Dialog.confirm({
|
||||
title: game.i18n.localize("PRISMRPG.Settings.resetConfirm.title"),
|
||||
content: game.i18n.localize("PRISMRPG.Settings.resetConfirm.content"),
|
||||
yes: () => true,
|
||||
no: () => false
|
||||
})
|
||||
|
||||
if (confirm) {
|
||||
// Reset working copies
|
||||
this.workingTypes = {}
|
||||
this.workingGroups = {}
|
||||
this.render(true)
|
||||
}
|
||||
}
|
||||
|
||||
async _updateObject(event, formData) {
|
||||
const expanded = foundry.utils.expandObject(formData)
|
||||
|
||||
// Extract only custom types (those with custom_ prefix)
|
||||
const customTypes = {}
|
||||
if (expanded.weaponTypes) {
|
||||
for (const [key, type] of Object.entries(expanded.weaponTypes)) {
|
||||
if (key.startsWith("custom_")) {
|
||||
customTypes[key] = type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract only custom groups (those with custom_ prefix)
|
||||
const customGroups = {}
|
||||
if (expanded.weaponGroups) {
|
||||
for (const [key, group] of Object.entries(expanded.weaponGroups)) {
|
||||
if (key.startsWith("custom_")) {
|
||||
customGroups[key] = group
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save custom weapon types (this will trigger page reload)
|
||||
await game.settings.set("fvtt-prism-rpg", "customWeaponTypes", customTypes)
|
||||
|
||||
// Save custom weapon groups (this will trigger page reload)
|
||||
await game.settings.set("fvtt-prism-rpg", "customWeaponGroups", customGroups)
|
||||
|
||||
ui.notifications.info(game.i18n.localize("PRISMRPG.Settings.weaponTypesSaved"))
|
||||
}
|
||||
}
|
||||
+182
-20
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* Weapon types based on Prism RPG rules
|
||||
* Default weapon types based on Prism RPG rules
|
||||
* APC determines weapon class: Light (1 APC), One-Handed (2 APC), Heavy (3 APC)
|
||||
*/
|
||||
export const TYPE = Object.freeze({
|
||||
const DEFAULT_TYPES = {
|
||||
light: {
|
||||
id: "light",
|
||||
label: "PRISMRPG.Weapon.Type.light",
|
||||
@@ -27,22 +27,75 @@ export const TYPE = Object.freeze({
|
||||
apc: 0, // Variable based on specific weapon
|
||||
hands: 2
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get weapon types (default + custom from settings)
|
||||
*/
|
||||
export function getWeaponTypes() {
|
||||
if (!game?.settings) return DEFAULT_TYPES;
|
||||
|
||||
const customTypes = game.settings.get("fvtt-prism-rpg", "customWeaponTypes") || {};
|
||||
return foundry.utils.mergeObject(DEFAULT_TYPES, customTypes, { inplace: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Weapon types (dynamically loaded)
|
||||
*/
|
||||
export const TYPE = new Proxy({}, {
|
||||
get(target, prop) {
|
||||
const types = getWeaponTypes();
|
||||
return types[prop];
|
||||
},
|
||||
ownKeys(target) {
|
||||
return Object.keys(getWeaponTypes());
|
||||
},
|
||||
getOwnPropertyDescriptor(target, prop) {
|
||||
return {
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Simplified Weapon Types object for form choices (label-only format)
|
||||
*/
|
||||
export const TYPE_CHOICES = Object.freeze(
|
||||
Object.fromEntries(
|
||||
Object.entries(TYPE).map(([key, value]) => [key, value.label])
|
||||
)
|
||||
);
|
||||
export function getWeaponTypeChoices() {
|
||||
const types = getWeaponTypes();
|
||||
return Object.fromEntries(
|
||||
Object.entries(types).map(([key, value]) => [key, value.label])
|
||||
);
|
||||
}
|
||||
|
||||
export const TYPE_CHOICES = new Proxy({}, {
|
||||
get(target, prop) {
|
||||
const choices = getWeaponTypeChoices();
|
||||
return choices[prop];
|
||||
},
|
||||
ownKeys(target) {
|
||||
return Object.keys(getWeaponTypeChoices());
|
||||
},
|
||||
getOwnPropertyDescriptor(target, prop) {
|
||||
return {
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Weapon groups and their associated passives
|
||||
* Default weapon groups and their associated passives
|
||||
* Each weapon belongs to a group and possesses its passive while wielded
|
||||
*/
|
||||
export const WEAPON_GROUP = Object.freeze({
|
||||
const DEFAULT_WEAPON_GROUPS = {
|
||||
shortsword: {
|
||||
id: "shortsword",
|
||||
label: "PRISMRPG.WeaponGroup.shortsword",
|
||||
passive: "quickBlade",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.quickBlade",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.quickBlade"
|
||||
},
|
||||
longsword: {
|
||||
id: "longsword",
|
||||
label: "PRISMRPG.WeaponGroup.longsword",
|
||||
@@ -50,12 +103,19 @@ export const WEAPON_GROUP = Object.freeze({
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.turningEdge",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.turningEdge"
|
||||
},
|
||||
warhammer: {
|
||||
id: "warhammer",
|
||||
label: "PRISMRPG.WeaponGroup.warhammer",
|
||||
passive: "puncturingBlows",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.puncturingBlows",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.puncturingBlows"
|
||||
greatsword: {
|
||||
id: "greatsword",
|
||||
label: "PRISMRPG.WeaponGroup.greatsword",
|
||||
passive: "cleave",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.cleave",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.cleave"
|
||||
},
|
||||
handaxe: {
|
||||
id: "handaxe",
|
||||
label: "PRISMRPG.WeaponGroup.handaxe",
|
||||
passive: "throwingAxe",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.throwingAxe",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.throwingAxe"
|
||||
},
|
||||
battleaxe: {
|
||||
id: "battleaxe",
|
||||
@@ -64,6 +124,62 @@ export const WEAPON_GROUP = Object.freeze({
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.shieldEater",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.shieldEater"
|
||||
},
|
||||
greataxe: {
|
||||
id: "greataxe",
|
||||
label: "PRISMRPG.WeaponGroup.greataxe",
|
||||
passive: "devastatingBlow",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.devastatingBlow",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.devastatingBlow"
|
||||
},
|
||||
club: {
|
||||
id: "club",
|
||||
label: "PRISMRPG.WeaponGroup.club",
|
||||
passive: "stun",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.stun",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.stun"
|
||||
},
|
||||
mace: {
|
||||
id: "mace",
|
||||
label: "PRISMRPG.WeaponGroup.mace",
|
||||
passive: "armorBreaker",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.armorBreaker",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.armorBreaker"
|
||||
},
|
||||
greatMaul: {
|
||||
id: "greatMaul",
|
||||
label: "PRISMRPG.WeaponGroup.greatMaul",
|
||||
passive: "earthshatter",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.earthshatter",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.earthshatter"
|
||||
},
|
||||
javelin: {
|
||||
id: "javelin",
|
||||
label: "PRISMRPG.WeaponGroup.javelin",
|
||||
passive: "piercingThrow",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.piercingThrow",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.piercingThrow"
|
||||
},
|
||||
spear: {
|
||||
id: "spear",
|
||||
label: "PRISMRPG.WeaponGroup.spear",
|
||||
passive: "reach",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.reach",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.reach"
|
||||
},
|
||||
longSpear: {
|
||||
id: "longSpear",
|
||||
label: "PRISMRPG.WeaponGroup.longSpear",
|
||||
passive: "extendedReach",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.extendedReach",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.extendedReach"
|
||||
},
|
||||
warhammer: {
|
||||
id: "warhammer",
|
||||
label: "PRISMRPG.WeaponGroup.warhammer",
|
||||
passive: "puncturingBlows",
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.puncturingBlows",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.puncturingBlows"
|
||||
},
|
||||
dagger: {
|
||||
id: "dagger",
|
||||
label: "PRISMRPG.WeaponGroup.dagger",
|
||||
@@ -85,16 +201,62 @@ export const WEAPON_GROUP = Object.freeze({
|
||||
passiveLabel: "PRISMRPG.Weapon.Passive.volleyFire",
|
||||
passiveDescription: "PRISMRPG.Weapon.PassiveDescription.volleyFire"
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get weapon groups (default + custom from settings)
|
||||
*/
|
||||
export function getWeaponGroups() {
|
||||
if (!game?.settings) return DEFAULT_WEAPON_GROUPS;
|
||||
|
||||
const customGroups = game.settings.get("fvtt-prism-rpg", "customWeaponGroups") || {};
|
||||
return foundry.utils.mergeObject(DEFAULT_WEAPON_GROUPS, customGroups, { inplace: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Weapon groups (dynamically loaded)
|
||||
*/
|
||||
export const WEAPON_GROUP = new Proxy({}, {
|
||||
get(target, prop) {
|
||||
const groups = getWeaponGroups();
|
||||
return groups[prop];
|
||||
},
|
||||
ownKeys(target) {
|
||||
return Object.keys(getWeaponGroups());
|
||||
},
|
||||
getOwnPropertyDescriptor(target, prop) {
|
||||
return {
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Simplified Weapon Groups object for form choices (label-only format)
|
||||
*/
|
||||
export const WEAPON_GROUP_CHOICES = Object.freeze(
|
||||
Object.fromEntries(
|
||||
Object.entries(WEAPON_GROUP).map(([key, value]) => [key, value.label])
|
||||
)
|
||||
);
|
||||
export function getWeaponGroupChoices() {
|
||||
const groups = getWeaponGroups();
|
||||
return Object.fromEntries(
|
||||
Object.entries(groups).map(([key, value]) => [key, value.label])
|
||||
);
|
||||
}
|
||||
|
||||
export const WEAPON_GROUP_CHOICES = new Proxy({}, {
|
||||
get(target, prop) {
|
||||
const choices = getWeaponGroupChoices();
|
||||
return choices[prop];
|
||||
},
|
||||
ownKeys(target) {
|
||||
return Object.keys(getWeaponGroupChoices());
|
||||
},
|
||||
getOwnPropertyDescriptor(target, prop) {
|
||||
return {
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Damage types for weapons
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { SYSTEM } from "../config/system.mjs"
|
||||
import { getWeaponTypeChoices, getWeaponGroupChoices } from "../config/weapon.mjs"
|
||||
|
||||
export default class PrismRPGWeapon extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
@@ -12,13 +13,13 @@ export default class PrismRPGWeapon extends foundry.abstract.TypeDataModel {
|
||||
schema.weaponType = new fields.StringField({
|
||||
required: true,
|
||||
initial: "light",
|
||||
choices: SYSTEM.WEAPON_TYPE_CHOICES
|
||||
choices: () => getWeaponTypeChoices()
|
||||
})
|
||||
|
||||
schema.weaponGroup = new fields.StringField({
|
||||
required: true,
|
||||
initial: "longsword",
|
||||
choices: SYSTEM.WEAPON_GROUP_CHOICES
|
||||
choices: () => getWeaponGroupChoices()
|
||||
})
|
||||
|
||||
// APC (Action Point Cost) - determined by weapon type
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { WeaponTypesConfig } from "./applications/weapon-types-config.mjs"
|
||||
|
||||
/**
|
||||
* Register all system settings
|
||||
*/
|
||||
export function registerSettings() {
|
||||
|
||||
// Custom Weapon Types
|
||||
game.settings.register("fvtt-prism-rpg", "customWeaponTypes", {
|
||||
name: "PRISMRPG.Settings.customWeaponTypes.name",
|
||||
hint: "PRISMRPG.Settings.customWeaponTypes.hint",
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: Object,
|
||||
default: {},
|
||||
onChange: value => {
|
||||
// Reload weapon types when changed
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
|
||||
// Custom Weapon Groups
|
||||
game.settings.register("fvtt-prism-rpg", "customWeaponGroups", {
|
||||
name: "PRISMRPG.Settings.customWeaponGroups.name",
|
||||
hint: "PRISMRPG.Settings.customWeaponGroups.hint",
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: Object,
|
||||
default: {},
|
||||
onChange: value => {
|
||||
// Reload weapon groups when changed
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
|
||||
// Register menu for weapon types configuration
|
||||
game.settings.registerMenu("fvtt-prism-rpg", "weaponTypesConfig", {
|
||||
name: "PRISMRPG.Settings.weaponTypesConfig.name",
|
||||
hint: "PRISMRPG.Settings.weaponTypesConfig.hint",
|
||||
label: "PRISMRPG.Settings.weaponTypesConfig.label",
|
||||
icon: "fas fa-sword",
|
||||
type: WeaponTypesConfig,
|
||||
restricted: true
|
||||
})
|
||||
}
|
||||
@@ -258,6 +258,7 @@ export default class PrismRPGUtils {
|
||||
static async preloadHandlebarsTemplates() {
|
||||
const templatePaths = [
|
||||
'systems/fvtt-prism-rpg/templates/partial-item-effects.hbs',
|
||||
'systems/fvtt-prism-rpg/templates/weapon-types-config.hbs',
|
||||
]
|
||||
return foundry.applications.handlebars.loadTemplates(templatePaths)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user