Skip to content

Commit

Permalink
Multiple fixes and additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Apr 11, 2023
1 parent debeab5 commit 1f847a2
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 26 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Version 2.6.1

- Updated WFRP system configuration (thank you Txus5012 on github!)
- Updated Portuguese (Brazil) and French localization (thank you eunaumtenhoid and rectulo on Weblate!)
- Added `PILE_DEFAULTS` and `TOKEN_FLAG_DEFAULT` system specific settings
- Tweaked the way default item pile data is applied, in the case of merchant columns
- Fixed `game.itempiles.API.createItemPile` not respecting an overriding `texture.src`, `texture.scaleX`, and `texture.scaleY` property on the token data
- Fixed populate items not having scroll bars when enough items was added to the merchant
Expand Down
34 changes: 27 additions & 7 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [ITEM_SIMILARITIES](#ITEM_SIMILARITIES)
* [UNSTACKABLE_ITEM_TYPES](#UNSTACKABLE_ITEM_TYPES)
* [PILE_DEFAULTS](#PILE_DEFAULTS)
* [TOKEN_FLAG_DEFAULTS](#TOKEN_FLAG_DEFAULTS)
* [setActorClassType](#setActorClassType)
* [setCurrencies](#setCurrencies)
* [setCurrencyDecimalDigits](#setCurrencyDecimalDigits)
Expand All @@ -19,6 +20,7 @@
* [setItemSimilarities](#setItemSimilarities)
* [setUnstackableItemTypes](#setUnstackableItemTypes)
* [setPileDefaults](#setPileDefaults)
* [setTokenFlagDefaults](#setTokenFlagDefaults)
* [addSystemIntegration](#addSystemIntegration)


Expand Down Expand Up @@ -133,7 +135,6 @@ The attributes for detecting item similarities

The types of items that will always be considered unique when transferring between actors


---

### PILE_DEFAULTS
Expand All @@ -144,6 +145,14 @@ The system specific default values for item pile actors created in this system

---

### TOKEN_FLAG_DEFAULTS

`game.itempiles.API.TOKEN_FLAG_DEFAULTS``Object`

The system specific default values for item pile tokens created in this system

---

### setActorClassType

`game.itempiles.API.setActorClassType(inClassType)``Promise`
Expand Down Expand Up @@ -242,13 +251,23 @@ Sets the types of items that will always be considered unique when transferring

### setPileDefaults

`game.itempiles.API.setPileDefaults(inTypes)``Promise`
`game.itempiles.API.setPileDefaults(inDefaults)``Promise`

Sets the types of items that will always be considered unique when transferring between actors

| Param | Type |
|------------|------------------|
| inDefaults | `Object` |

### setTokenFlagDefaults

`game.itempiles.API.setTokenFlagDefaults(inDefaults)``Promise`

Sets the types of items that will always be considered unique when transferring between actors

| Param | Type |
|--------|------------------|
| inTypes | `Object` |
| Param | Type |
|------------|------------------|
| inDefaults | `Object` |

---

Expand All @@ -265,10 +284,11 @@ A combination of all the methods above, but this integrates a system's specific
| data.ACTOR_CLASS_TYPE | `string` | The system's actor class type to represent item piles |
| data.ITEM_PRICE_ATTRIBUTE | `string` | The property path to the system's item price attribute |
| data.ITEM_QUANTITY_ATTRIBUTE | `string` | The property path to the system's item quantity attribute |
| data.ITEM_FILTERS | `Array<{path: string, filters: string}>` | The filters to determine which items to not include as droppable or tradable |
| data.ITEM_FILTERS | `Array<{path: string, filters: string}>` | The filters to determine which items to not include as droppable or tradeable |
| data.ITEM_SIMILARITIES | `Array<string>` | The array of property path strings used to determine item similarities |
| data.UNSTACKABLE_ITEM_TYPES | `Array<string>` | The array of property path strings used to determine item types that cannot stack, no matter what |
| data.PILE_DEFAULTS | `Object` | The system specific default values for item pile actors created in this system |
| data.PILE_DEFAULTS | `Object` | The system specific default values for item pile actors created in this system |
| data.TOKEN_FLAG_DEFAULTS | `Object` | The system specific default values for item pile tokens created in this system |
| data.ITEM_TRANSFORMER | `undefined/Function` | An optional function that gets run over items before picked up, traded, or bought |
| data.CURRENCIES | `Array<{ primary: boolean, type: string ["attribute"/"item"], img: string, abbreviation: string, data: Object<{ path: string } / { uuid: string } / { item: object }>, exchangeRate: number }>` | The array of currencies for this system |
| data.CURRENCY_DECIMAL_DIGITS | `undefined/number` | How many decimals should be shown for fractional amounts of currency (only works when only 1 currency is configured) |
Expand Down
28 changes: 28 additions & 0 deletions src/API/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ class API {
return Helpers.getSetting(SETTINGS.PILE_DEFAULTS);
}

/**
* The system specific default values for item pile tokens created in this system
*
* @returns {Object}
*/
static get TOKEN_FLAG_DEFAULTS() {
return Helpers.getSetting(SETTINGS.TOKEN_FLAG_DEFAULTS);
}

/**
* Sets the actor class type used for the original item pile actor in this system
*
Expand Down Expand Up @@ -284,6 +293,19 @@ class API {
return Helpers.setSetting(SETTINGS.PILE_DEFAULTS, inDefaults);
}

/**
* Set the flags that will be applied to any tokens created through item piles
*
* @param {Object} inDefaults
* @returns {Promise}
*/
static async setTokenFlagDefaults(inDefaults) {
if (typeof inDefaults !== "object") {
throw Helpers.custom_error("setTokenFlagDefaults | inDefaults must be of type object");
}
return Helpers.setSetting(SETTINGS.TOKEN_FLAG_DEFAULTS, inDefaults);
}

/**
* A combination of all the methods above, but this integrates a system's specific
* settings more readily into item piles, allowing users to also change the settings
Expand All @@ -299,6 +321,7 @@ class API {
* ITEM_SIMILARITIES: Array<string>,
* UNSTACKABLE_ITEM_TYPES: Array<string>,
* PILE_DEFAULTS: Object,
* TOKEN_FLAG_DEFAULTS: Object,
* ITEM_TRANSFORMER: undefined/Function,
* CURRENCIES: Array<{
* primary: boolean,
Expand All @@ -323,6 +346,7 @@ class API {
ITEM_SIMILARITIES: [],
UNSTACKABLE_ITEM_TYPES: [],
PILE_DEFAULTS: {},
TOKEN_FLAG_DEFAULTS: {},
ITEM_TRANSFORMER: null,
CURRENCIES: [],
CURRENCY_DECIMAL_DIGITS: null
Expand Down Expand Up @@ -380,6 +404,10 @@ class API {
}
}

if (typeof data['TOKEN_FLAG_DEFAULTS'] !== "object") {
throw Helpers.custom_error("addSystemIntegration | data.TOKEN_FLAG_DEFAULTS must be of type object");
}

if (!Array.isArray(data['ITEM_SIMILARITIES'])) {
throw Helpers.custom_error("addSystemIntegration | data.ITEM_SIMILARITIES must be of type array");
}
Expand Down
16 changes: 11 additions & 5 deletions src/API/private-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,8 @@ export default class PrivateAPI {
vision: false,
displayName: 50,
[CONSTANTS.FLAGS.PILE]: pileDataDefaults,
[CONSTANTS.FLAGS.VERSION]: Helpers.getModuleVersion()
[CONSTANTS.FLAGS.VERSION]: Helpers.getModuleVersion(),
...Helpers.getSetting(SETTINGS.TOKEN_FLAG_DEFAULTS)
}, tokenOverrides)

const actorUpdate = foundry.utils.mergeObject({
Expand Down Expand Up @@ -1089,7 +1090,8 @@ export default class PrivateAPI {
vision: false,
displayName: 50,
[CONSTANTS.FLAGS.PILE]: pileDataDefaults,
[CONSTANTS.FLAGS.VERSION]: Helpers.getModuleVersion()
[CONSTANTS.FLAGS.VERSION]: Helpers.getModuleVersion(),
...Helpers.getSetting(SETTINGS.TOKEN_FLAG_DEFAULTS)
}
})

Expand Down Expand Up @@ -1126,7 +1128,11 @@ export default class PrivateAPI {

if (position && sceneId) {

let overrideData = { ...position, ...tokenOverrides };
let overrideData = foundry.utils.mergeObject({
...position,
...tokenOverrides,
...Helpers.getSetting(SETTINGS.TOKEN_FLAG_DEFAULTS)
}, {});

let pileData = PileUtilities.getActorFlagData(pileActor);
pileData.enabled = true;
Expand All @@ -1141,7 +1147,7 @@ export default class PrivateAPI {
const overrideImage = getProperty(overrideData, "texture.src") ?? getProperty(overrideData, "img");
const overrideScale = getProperty(overrideData, "texture.scaleX")
?? getProperty(overrideData, "texture.scaleY")
?? getProperty(overrideData, "img");
?? getProperty(overrideData, "scale");

const scale = PileUtilities.getItemPileTokenScale(pileActor, data, overrideScale);

Expand Down Expand Up @@ -1224,7 +1230,7 @@ export default class PrivateAPI {
const overrideImage = getProperty(specificTokenSettings, "texture.src") ?? getProperty(specificTokenSettings, "img");
const overrideScale = getProperty(specificTokenSettings, "texture.scaleX")
?? getProperty(specificTokenSettings, "texture.scaleY")
?? getProperty(specificTokenSettings, "img");
?? getProperty(specificTokenSettings, "scale");

const scale = PileUtilities.getItemPileTokenScale(target, data, overrideScale);

Expand Down
9 changes: 9 additions & 0 deletions src/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const SETTINGS = {
ITEM_SIMILARITIES: "itemSimilarities",
UNSTACKABLE_ITEM_TYPES: "unstackableItemTypes",
PILE_DEFAULTS: "pileDefaults",
TOKEN_FLAG_DEFAULTS: "tokenFlagDefaults",

// Hidden settings
DEFAULT_ITEM_PILE_JOURNAL_ID: "defaultItemPileJournalID",
Expand Down Expand Up @@ -240,6 +241,14 @@ const SETTINGS = {
type: Object
},

[SETTINGS.TOKEN_FLAG_DEFAULTS]: {
scope: "world",
config: false,
system: true,
default: SYSTEMS.DATA.TOKEN_FLAG_DEFAULTS,
type: Object
},

[SETTINGS.CUSTOM_ITEM_CATEGORIES]: {
name: "ITEM-PILES.Settings.CustomItemCategories.Title",
label: "ITEM-PILES.Settings.CustomItemCategories.Label",
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/pile-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ export async function updateItemPileData(target, flagData, tokenData) {

if (!flagData) flagData = getActorFlagData(target);
if (!tokenData) tokenData = {};
tokenData = foundry.utils.mergeObject(tokenData, {});

let [documentActor, documentTokens] = getRelevantTokensAndActor(target);

Expand All @@ -461,7 +462,7 @@ export async function updateItemPileData(target, flagData, tokenData) {
const overrideImage = getProperty(tokenData, "texture.src") ?? getProperty(tokenData, "img");
const overrideScale = getProperty(tokenData, "texture.scaleX")
?? getProperty(tokenData, "texture.scaleY")
?? getProperty(tokenData, "img");
?? getProperty(tokenData, "scale");
const scale = getItemPileTokenScale(tokenDocument, pileData, overrideScale);
const newTokenData = foundry.utils.mergeObject(tokenData, {
"texture.src": getItemPileTokenImage(tokenDocument, pileData, overrideImage),
Expand Down
13 changes: 1 addition & 12 deletions src/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ import CONSTANTS from "./constants/constants.js";
import { custom_warning, getSetting } from "./helpers/helpers.js";
import * as PileUtilities from "./helpers/pile-utilities.js";
import SETTINGS from "./constants/settings.js";
import { SYSTEMS } from "./systems.js";

let oldSettings;

function findOldSettingValue(oldSettingKey) {
if (!oldSettings) {
oldSettings = game.settings.storage.get("world").filter(setting => setting.key.startsWith(CONSTANTS.MODULE_NAME));
}
return oldSettings.find(setting => setting.key.endsWith(oldSettingKey))?.value;
}

export default async function runMigrations() {

Expand All @@ -28,7 +18,6 @@ export default async function runMigrations() {
custom_warning(`Something went wrong when migrating to version ${version}. Please check the console for the error!`, true)
}
}

}

function getItemPileActorsOfLowerVersion(version) {
Expand Down Expand Up @@ -201,7 +190,7 @@ const migrations = {
const flags = getProperty(item, CONSTANTS.FLAGS.ITEM);
flags.infiniteQuantity = "default";
return PileUtilities.updateItemData(item, { flags }, { version, returnUpdate: true });
})
});

if (itemUpdates.length) {
console.log(`Item Piles | Migrating ${itemUpdates.length} items to version ${version}...`)
Expand Down
1 change: 1 addition & 0 deletions src/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const SYSTEMS = {
UNSTACKABLE_ITEM_TYPES: [],
CURRENCIES: [],
PILE_DEFAULTS: {},
TOKEN_FLAG_DEFAULTS: {},
CURRENCY_DECIMAL_DIGITS: 0.00001
},

Expand Down
9 changes: 9 additions & 0 deletions src/systems/pf2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export default {
}]
},

"TOKEN_FLAG_DEFAULTS": {
flags: {
pf2e: {
linkToActorSize: false,
autoscale: false
}
}
},

// Currencies in item piles is a versatile system that can accept actor attributes (a number field on the actor's sheet) or items (actual items in their inventory)
// In the case of attributes, the path is relative to the "actor.system"
// In the case of items, it is recommended you export the item with `.toObject()`, put it into `data.item`, and strip out any module data
Expand Down
2 changes: 1 addition & 1 deletion src/systems/wfrp4e.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import CONSTANTS from "../constants/constants.js";

export default {

"VERSION": "1.0.4",
"VERSION": "1.0.5",

// The actor class type is the type of actor that will be used for the default item pile actor that is created on first item drop.
"ACTOR_CLASS_TYPE": "character",
Expand Down

0 comments on commit 1f847a2

Please sign in to comment.