Skip to content

Commit

Permalink
v1.13.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
drewg13 committed Oct 16, 2021
1 parent b3ccffd commit 6ecd430
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 195 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ v1.9.4 Fix Trauma tooltip z-indexing
1.13.0 Add faction clocks/goals to Universe sheet, add NPC actors

1.13.1 Clean up Universe sheet

1.13.2 Updates for V9d1, simplified NPC sheet, remove item logic fields and functions
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@ Clock Tiles

Clock Tiles are useful for quick, disposable clocks you'd like to drop onto the scene but don't plan to keep around for long. Click the new Clock button in the Tiles toolbar and a new clock will be dropped into the actual middle of your scene (you may need to scroll to see it). When you select and right-click the clock you'll see a new set of controls on the left that let you switch the clock's theme, cycle through clock sizes, and increment/decrement progress on the clock.

## Logic field

Logic field is a json with params which allows to implement some logic when the Item of corresponding type is added or removed.
### Example (from the Vault 1 crew upgrade)
`{"attribute":"data.vault.max","operator":"addition","value":4,"requirement":""}`
- `attribute` - the attribute to affect
- `operator` - what is done to attribute
- `value` - the value for operator
- `requirement` - is not used

### Operators list
- `addition` - is added when item is attached and substracted when removed
- `attribute_change` - changes the "attribute" to value and when removed - uses the "attribute_default" to restore

## Troubleshooting
- If you can't find an item added to your sheet, refer to "All Items" tab on each sheet.

Expand Down
125 changes: 0 additions & 125 deletions module/sav-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,131 +78,6 @@ export class SaVHelpers {
}


/**
* Add item modification if logic exists.
* @param {Object} item_data
* @param {Document} entity
*/
static async callItemLogic(item_data, entity) {

let items = item_data.data || {};

if ('logic' in items && items.logic !== '') {
let logic = JSON.parse(items.logic);
// Should be an array to support multiple expressions
if (!Array.isArray(logic)) {
logic = [logic];
}

if (logic) {
let logic_update = { "_id": entity.data._id };
logic.forEach( expression => {

// Different logic behav. dep on operator.
switch (expression.operator) {

// Add when creating.
case "addition":
let prefix = "";
if( game.majorVersion > 7 ) {
prefix = "data.data.";
} else {
prefix = "data.";
}
//update to foundry.utils.mergeObject
mergeObject(
logic_update,
{[expression.attribute]: Number(SaVHelpers.getNestedProperty(entity, prefix + expression.attribute)) + expression.value},
{insertKeys: true}
);
break;

// Change name property.
case "attribute_change":
//update to foundry.utils.mergeObject
mergeObject(
logic_update,
{[expression.attribute]: expression.value},
{insertKeys: true}
);
break;

}
});
if( game.majorVersion > 7 ) {
await Actor.updateDocuments( [logic_update] );
} else {
await Actor.update( logic_update );
}
}
}
}

/**
* Undo Item modifications when item is removed.
* @param {Object} item_data
* @param {Document} entity
*/
static async undoItemLogic(item_data, entity) {

let items = item_data.data || {};

if ( ('logic' in items) && (items.logic !== '') ) {
let logic = JSON.parse(items.logic)

// Should be an array to support multiple expressions
if (!Array.isArray(logic)) {
logic = [logic];
}

if (logic) {
let logic_update = { "_id": entity.data._id };
let entity_data = entity.data;

logic.forEach(expression => {
// Different logic behav. dep on operator.
switch (expression.operator) {

// Subtract when removing.
case "addition":
let prefix = "";
if( game.majorVersion > 7 ) {
prefix = "data.data.";
} else {
prefix = "data.";
}
//update to foundry.utils.mergeObject
mergeObject(
logic_update,
{[expression.attribute]: Number(SaVHelpers.getNestedProperty(entity, prefix + expression.attribute)) - expression.value},
{insertKeys: true}
);
break;

// Change name back to default.
case "attribute_change":
// Get the array path to take data.
let default_expression_attribute_path = expression.attribute + '_default';
let default_name = default_expression_attribute_path.split(".").reduce((o, i) => o[i], entity_data);

//update to foundry.utils.mergeObject
mergeObject(
logic_update,
{[expression.attribute]: default_name},
{insertKeys: true}
);
break;
}
});
if( game.majorVersion > 7 ) {
await Actor.updateDocuments( [logic_update] );
} else {
await Actor.update( logic_update );
}
}
}
}

/**
* Get a nested dynamic attribute.
* @param {Object} obj
Expand Down
11 changes: 0 additions & 11 deletions module/sav-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class SaVItem extends Item {
let actor = this.parent ? this.parent : null;

if( ( game.majorVersion > 7 ) && ( actor?.documentName === "Actor" ) && ( actor?.permission >= CONST.ENTITY_PERMISSIONS.OWNER ) ) {
await SaVHelpers.callItemLogic( data, actor );

if( ( ( data.type === "class" ) || ( data.type === "crew_type" ) ) && ( data.data.def_abilities !== "" ) ) {
await SaVHelpers.addDefaultAbilities( data, actor );
Expand All @@ -61,16 +60,6 @@ export class SaVItem extends Item {

/* -------------------------------------------- */

/** @override */
async _onDelete( options, userId ) {
super._onDelete( options, userId );

let actor = this.parent ? this.parent : null;
let data = this.data;
if( ( game.majorVersion > 7 ) && ( actor?.documentName === "Actor" ) && ( actor?.permission >= CONST.ENTITY_PERMISSIONS.OWNER ) ) {
await SaVHelpers.undoItemLogic( data, actor );
}
}

/** override */
prepareData() {
Expand Down
14 changes: 0 additions & 14 deletions module/sav.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,6 @@ Hooks.on("preCreateOwnedItem", async (parent_entity, child_data, options, userId
return true;
});

Hooks.on("createOwnedItem", async (parent_entity, child_data, options, userId) => {
if ( ( game.majorVersion === 7 ) && (parent_entity.entity === "Actor") && (parent_entity.permission >= CONST.ENTITY_PERMISSIONS.OWNER) ) {
await SaVHelpers.callItemLogic(child_data, parent_entity);
}
return true;
});

Hooks.on("deleteOwnedItem", async (parent_entity, child_data, options, userId) => {
if ( ( game.majorVersion === 7 ) && (parent_entity.entity === "Actor") && (parent_entity.permission >= CONST.ENTITY_PERMISSIONS.OWNER) ) {
await SaVHelpers.undoItemLogic(child_data, parent_entity);
}
return true;
});

// getSceneControlButtons
Hooks.on("renderSceneControls", async (app, html) => {
let dice_roller = $( '<li class="scene-control" title="Dice Roll"><i class="fas fa-dice"></i></li>' );
Expand Down
4 changes: 2 additions & 2 deletions styles/sav.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions system.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"authors": ["megastruktur", "Andrew Garinger [agaringer#6498]"],
"url": "https://github.com/drewg13/foundryvtt-scum-and-villainy/",
"flags": {},
"version": "1.13.1",
"version": "1.13.2",
"minimumCoreVersion": "0.7.9",
"compatibleCoreVersion": "9.224",
"compatibleCoreVersion": "9.226",
"system": [],
"dependencies": [],
"socket": false,
"manifest": "https://raw.githubusercontent.com/drewg13/foundryvtt-scum-and-villainy/master/system.json",
"download": "https://github.com/drewg13/foundryvtt-scum-and-villainy/archive/v1.13.1.zip",
"download": "https://github.com/drewg13/foundryvtt-scum-and-villainy/archive/v1.13.2.zip",
"protected": false,
"scripts": [],
"esmodules": [
Expand Down Expand Up @@ -41,6 +41,7 @@
"system": "scum-and-villainy",
"path": "./packs/classes.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -49,6 +50,7 @@
"system": "scum-and-villainy",
"path": "./packs/heritages.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -57,6 +59,7 @@
"system": "scum-and-villainy",
"path": "./packs/vices.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -65,6 +68,7 @@
"system": "scum-and-villainy",
"path": "./packs/backgrounds.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -73,6 +77,7 @@
"system": "scum-and-villainy",
"path": "./packs/items.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -81,6 +86,7 @@
"system": "scum-and-villainy",
"path": "./packs/abilities.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -89,6 +95,7 @@
"system": "scum-and-villainy",
"path": "./packs/crew_reputation.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -97,6 +104,7 @@
"system": "scum-and-villainy",
"path": "./packs/crew_types.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -105,6 +113,7 @@
"system": "scum-and-villainy",
"path": "./packs/crew_upgrades.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -113,6 +122,7 @@
"system": "scum-and-villainy",
"path": "./packs/crew_abilities.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -121,6 +131,7 @@
"system": "scum-and-villainy",
"path": "./packs/tables.db",
"entity": "RollTable",
"type": "RollTable",
"private": false
},
{
Expand All @@ -129,6 +140,7 @@
"system": "scum-and-villainy",
"path": "./packs/star_systems.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -137,6 +149,7 @@
"system": "scum-and-villainy",
"path": "./packs/planets.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -145,6 +158,7 @@
"system": "scum-and-villainy",
"path": "./packs/factions.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -153,6 +167,7 @@
"system": "scum-and-villainy",
"path": "./packs/size.db",
"entity": "Item",
"type": "Item",
"private": false
},
{
Expand All @@ -161,6 +176,7 @@
"system": "scum-and-villainy",
"path": "./packs/wanted-consequences.db",
"entity": "JournalEntry",
"type": "JournalEntry",
"private": false
},
{
Expand All @@ -169,6 +185,7 @@
"system": "scum-and-villainy",
"path": "./packs/wanted-tables.db",
"entity": "RollTable",
"type": "RollTable",
"private": false
},
{
Expand All @@ -177,6 +194,7 @@
"system": "scum-and-villainy",
"path": "./packs/macros.db",
"entity": "Macro",
"type": "Macro",
"private": false
},
{
Expand All @@ -185,6 +203,7 @@
"system": "scum-and-villainy",
"path": "./packs/friends.db",
"entity": "Item",
"type": "Item",
"private": false
}
]
Expand Down
2 changes: 0 additions & 2 deletions templates/items/ability.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ <h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeh
<label class="label-stripe">{{localize "BITD.AbilityClass"}}</label>
<input id="ability-class" type="text" name="data.class" value="{{data.class}}" placeholder="{{localize 'BITD.AbilityClass'}}">
{{#if isGM}}
<div class="label-stripe">{{localize "BITD.Logic"}}</div>
<textarea name="data.logic">{{{data.logic}}}</textarea>
<div class="label-stripe">{{localize "BITD.Effects"}}</div>
<div id="effects">{{> "systems/scum-and-villainy/templates/parts/active-effects.html"}}</div>
{{/if}}
Expand Down
Loading

0 comments on commit 6ecd430

Please sign in to comment.