Skip to content

Commit

Permalink
Fixes to const
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Jul 1, 2024
1 parent a45b421 commit 696707b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Fixed opening item pile interfaces would spawn duplicate windows instead of focusing existing interfaces
- Fixed item piles chat messages not working in v11
- Fixed errors when trying to get document templates in v12 (fixes merchant columns & item pile system settings)
- Fixed deprecation warnings surrounding `CONST.DOCUMENT_PERMISSION_LEVELS`

## Version 3.0.1

Expand Down
2 changes: 1 addition & 1 deletion src/API/private-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ export default class PrivateAPI {

const actorOwners = Object.entries(targetActor.ownership)
.filter(entry => {
return entry[0] !== "default" && entry[1] === CONST.DOCUMENT_PERMISSION_LEVELS.OWNER;
return entry[0] !== "default" && entry[1] === CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER;
})
.map(entry => game.users.get(entry[0]))
.sort(user => user.isGM ? 1 : -1);
Expand Down
16 changes: 5 additions & 11 deletions src/applications/components/PropertyPathInput.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
<script>
import { getDocumentTemplates } from "../../helpers/utilities.js";
export let value = "";
export let templateType;
export let required = false;
const id = "property-list-" + foundry.utils.randomID();
const templates = Object.values(CONFIG?.[templateType]?.dataModels ?? []).length
? {
...Object.fromEntries(Object.entries(CONFIG?.[templateType]?.dataModels).map(model => {
return [model[0], model[1].schema.initial()]
})),
types: Object.keys(CONFIG?.[templateType]?.dataModels),
}
: foundry.utils.deepClone(game.system.documentTypes[templateType]);
const templates = getDocumentTemplates(templateType);
const templateObject = {
name: "",
type: "",
system: templates.types
.map(type => {
let obj = templates[type];
system: Object.values(templates)
.map(obj => {
if (obj['templates']) {
for (const template of obj['templates']) {
obj = foundry.utils.mergeObject(obj, templates["templates"][template]);
Expand Down
9 changes: 5 additions & 4 deletions src/applications/settings-app/settings-shell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import Tabs from "../components/Tabs.svelte";
import { TJSDialog } from "#runtime/svelte/application";
import CustomDialog from "../components/CustomDialog.svelte";
import { getDocumentTemplates } from "../../helpers/utilities.js";
const { application } = getContext('#external');
Expand Down Expand Up @@ -192,13 +193,13 @@
getSettings();
}}/>
<Setting key={SETTINGS.ACTOR_CLASS_TYPE} bind:data="{settings[SETTINGS.ACTOR_CLASS_TYPE]}"
options={["None", ...Object.keys(game.system.documentTypes.Actor)]}/>
options={["None", ...Object.keys(getDocumentTemplates("Actor"))]}/>
<Setting key={SETTINGS.ITEM_CLASS_LOOT_TYPE} bind:data="{settings[SETTINGS.ITEM_CLASS_LOOT_TYPE]}"
options={["None", ...Object.keys(game.system.documentTypes.Item)]}/>
options={["None", ...Object.keys(getDocumentTemplates("Item"))]}/>
<Setting key={SETTINGS.ITEM_CLASS_WEAPON_TYPE} bind:data="{settings[SETTINGS.ITEM_CLASS_WEAPON_TYPE]}"
options={["None", ...Object.keys(game.system.documentTypes.Item)]}/>
options={["None", ...Object.keys(getDocumentTemplates("Item"))]}/>
<Setting key={SETTINGS.ITEM_CLASS_EQUIPMENT_TYPE} bind:data="{settings[SETTINGS.ITEM_CLASS_EQUIPMENT_TYPE]}"
options={["None", ...Object.keys(game.system.documentTypes.Item)]}/>
options={["None", ...Object.keys(getDocumentTemplates("Item"))]}/>
<Setting key={SETTINGS.ITEM_QUANTITY_ATTRIBUTE} bind:data="{settings[SETTINGS.ITEM_QUANTITY_ATTRIBUTE]}"/>
<Setting key={SETTINGS.ITEM_PRICE_ATTRIBUTE} bind:data="{settings[SETTINGS.ITEM_PRICE_ATTRIBUTE]}"/>
<SettingButton key={SETTINGS.CURRENCIES} bind:data="{settings[SETTINGS.CURRENCIES]}"/>
Expand Down
2 changes: 1 addition & 1 deletion src/applications/trading-app/TradeEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
if (!canPreview || !data.id) return;
const item = store.leftTraderActor.items.get(data.id) ?? store.rightTraderActor.items.get(data.id);
if (!item) return;
if (game.user.isGM || item.ownership[game.user.id] === CONST.DOCUMENT_PERMISSION_LEVELS.OWNER) {
if (game.user.isGM || item.ownership[game.user.id] === CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER) {
return item.sheet.render(true);
}
const cls = item._getSheetClass()
Expand Down
38 changes: 21 additions & 17 deletions src/helpers/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ export function refreshItemTypesThatCanStack() {
getItemTypesThatCanStack();
}


export function getDocumentTemplates(templateType) {
return foundry.utils.mergeObject(
game.model[templateType],
Object.fromEntries(Object.entries(CONFIG[templateType]?.dataModels ?? {}).map(([k, v]) => [k, v.schema.getInitialValue()])),
{ inplace: false },
);
}


/**
* Retrieve all system item types that can be stacked
* @returns {Set<string>} The items type that can be stacked on this system
Expand All @@ -153,22 +163,16 @@ export function getItemTypesThatCanStack() {
}

const unstackableItemTypes = Helpers.getSetting(SETTINGS.UNSTACKABLE_ITEM_TYPES);
const types = new Set(Object.keys(CONFIG?.Item?.dataModels ?? {}).concat(game.system.documentTypes.Item.types));
const templates = getDocumentTemplates("Item");
const types = new Set(Object.keys(templates));
itemTypesWithQuantities = new Set([...itemTypesWithQuantities, ...types.filter(type => {
let itemTemplate = {};
if (CONFIG?.Item?.dataModels?.[type]?.defineSchema !== undefined) {
itemTemplate.system = Object.entries(CONFIG.Item.dataModels[type].defineSchema())
.map(([key, schema]) => {
return [key, schema.fields ?? true]
})
itemTemplate.system = Object.fromEntries(itemTemplate.system);
} else if (game.system?.templates?.Item?.[type]) {
itemTemplate.system = foundry.utils.deepClone(game.system.templates.Item[type]);
if (itemTemplate.system?.templates?.length) {
const templates = foundry.utils.duplicate(itemTemplate.system.templates);
for (let template of templates) {
itemTemplate.system = foundry.utils.mergeObject(itemTemplate.system, foundry.utils.duplicate(game.system.documentTypes.Item.templates[template]));
}
let itemTemplate = {
system: foundry.utils.deepClone(templates[type])
};
if (itemTemplate.system?.templates?.length) {
const templates = foundry.utils.duplicate(itemTemplate.system.templates);
for (let template of templates) {
itemTemplate.system = foundry.utils.mergeObject(itemTemplate.system, foundry.utils.duplicate(game.system.documentTypes.Item.templates[template]));
}
}
return hasItemQuantity(itemTemplate);
Expand Down Expand Up @@ -354,7 +358,7 @@ export async function runMacro(macroId, macroData) {
throw Helpers.custom_error(`The "${packArray[3]}" macro was not found in Compendium ${packArray[1]}.${packArray[2]}`);
}
macro = new Macro(findMacro?.toObject());
macro.ownership.default = CONST.DOCUMENT_PERMISSION_LEVELS.OWNER;
macro.ownership.default = CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER;
} else {
macro = game.macros.getName(macroId);
if (!macro) {
Expand All @@ -376,7 +380,7 @@ export async function runMacro(macroId, macroData) {
export function getOwnedCharacters(user = false) {
user = user || game.user;
return game.actors.filter(actor => {
return actor.ownership?.[user.id] === CONST.DOCUMENT_PERMISSION_LEVELS.OWNER && actor.prototypeToken.actorLink;
return actor.ownership?.[user.id] === CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER && actor.prototypeToken.actorLink;
})
.sort((a, b) => {
return b._stats.modifiedTime - a._stats.modifiedTime;
Expand Down

0 comments on commit 696707b

Please sign in to comment.