Skip to content

Commit

Permalink
fix: Fixed skill characteristic modifiers not updating when character…
Browse files Browse the repository at this point in the history
…s take damage. Includes migration that adds a localization string:

"MigrationError0_6_29": "0.6.30 migration failed to replace the characteristic '${characteristic}' of skill '${name}' so set it to '${fallback}'"

Also changes the recoil field of weapons to a checkbox.
  • Loading branch information
xdy committed Oct 3, 2020
1 parent 84a824c commit 36061b4
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 179 deletions.
215 changes: 83 additions & 132 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/module/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

export const TWODSIX:any = {};

TWODSIX.CHARACTERISTICS = {
"strength": "STR",
"dexterity": "DEX",
"endurance": "END",
"intelligence": "INT",
"education": "EDU",
"socialStanding": "SOC",
"psionicStrength": "PSI"
};

/**
* The sets of rules variants one can use
* Not currently used for anything. TODO Remove?
Expand Down
4 changes: 3 additions & 1 deletion src/module/entities/TwodsixItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export default class TwodsixItem extends Item {
const itemCharacteristic = itemData.data.characteristic;
if (this.actor.data.data.characteristics) { //Temporary fix until issue #102
const actorCharacteristics = Object.values(this.actor.data.data.characteristics);
const activeCharacteristic:any = actorCharacteristics.filter((c:any) => c.shortLabel === itemCharacteristic);
const activeCharacteristic:any = actorCharacteristics.filter((c:any) => {
return c.key === itemCharacteristic;
});

let mod = 0;
if (activeCharacteristic.length) {
Expand Down
27 changes: 27 additions & 0 deletions src/module/migration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {TwodsixItemData} from "./entities/TwodsixItem";
import {before} from "./hooks/ready";
import {TWODSIX} from "./config";
import {getKeyByValue} from "./utils/sheetUtils";

//TODO Move all types to a better place
export type UpdateData = {
Expand Down Expand Up @@ -77,6 +79,7 @@ export class Migration {
}

if (before(systemMigrationVersion, "0.6.25")) {
// This migration failed horribly, so removed in 0.6.26
// let cost;
// try {
// const price = item.data.price as string;
Expand All @@ -102,6 +105,30 @@ export class Migration {
}
}

if (before(systemMigrationVersion, "0.6.30")) {
if (item.type === 'skills') {
let characteristic;
//If it can be found, it's already correct
const alreadyCorrect = !!(TWODSIX.CHARACTERISTICS)[item.data.characteristic];
if (!alreadyCorrect) {
//If it's in the reverse map, use that.
characteristic = getKeyByValue(TWODSIX.CHARACTERISTICS, item.data.characteristic);
if (!characteristic) {
//Failed somehow, so set it to strength as a fallback (unlikely to be right, but at least it's obviously wrong...)
characteristic = 'strength';
console.log(game.i18n.format("TWODSIX.Migration.MigrationError0_6_29", {
characteristic: item.data.characteristic,
name: item.data.name,
fallback: TWODSIX.CHARACTERISTICS[0]
}));
}
}
if (!alreadyCorrect) {
updateData['data.characteristic'] = characteristic;
}
}
}

// Remove deprecated fields
this._migrateRemoveDeprecated(item, updateData);

Expand Down
7 changes: 4 additions & 3 deletions src/module/sheets/AbstractTwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ export class AbstractTwodsixActorSheet extends ActorSheet {
const {type} = header.dataset;
// Grab any data associated with this control.
const data = duplicate(header.dataset);
// Initialize a default name.
const name = game.i18n.localize("TWODSIX.Items.Items.New") + ` ${type.capitalize()}`;
// Initialize a default name, handle bad naming of 'skills' item type, which should be singular.
const itemType = (type === "skills" ? "skill" : type).capitalize();
const name = game.i18n.localize("TWODSIX.Items.Items.New") + " " + `${itemType}`;
data.name = name;
// Prepare the item object.
const itemData = {
Expand All @@ -100,7 +101,7 @@ export class AbstractTwodsixActorSheet extends ActorSheet {
}


protected static _prepareItemContainers(sheetData: { actor: any; items: any; }):void {
protected static _prepareItemContainers(sheetData:{ actor:any; items:any; }):void {
const actorData = sheetData.actor;

// Initialize containers.
Expand Down
14 changes: 9 additions & 5 deletions src/module/sheets/TwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {AbstractTwodsixActorSheet} from "./AbstractTwodsixActorSheet";
import TwodsixItem from "../entities/TwodsixItem";
import {UpdateData} from "../migration";
import {calcModFor} from "../utils/sheetUtils";
import {TWODSIX} from "../config";

export class TwodsixActorSheet extends AbstractTwodsixActorSheet {

Expand All @@ -29,6 +30,7 @@ export class TwodsixActorSheet extends AbstractTwodsixActorSheet {
data.data.settings = {
ShowRangeBandAndHideRange: game.settings.get('twodsix', 'ShowRangeBandAndHideRange'),
};
data.config = TWODSIX;

return data;
}
Expand Down Expand Up @@ -74,14 +76,16 @@ export class TwodsixActorSheet extends AbstractTwodsixActorSheet {

const updateData = <UpdateData>{};
const characteristics = this.actor.data.data.characteristics;
updateData[`data.characteristics.${characteristicKey}.damage`] = characteristic.damage;
updateData['data.hits.value'] = characteristics["endurance"].current + characteristics["strength"].current + characteristics["dexterity"].current;
updateData['data.hits.max'] = characteristics["endurance"].value + characteristics["strength"].value + characteristics["dexterity"].value;
try {
await this.actor.update(updateData);
} catch (e) {
console.log(e);

for (const skill of this.actor.items.filter(x => x.type === 'skills').filter(x => x.data.data.characteristic === characteristicKey)) {
const itemData = <UpdateData>{};
itemData['data.mod'] = characteristic.mod;
await (this.actor.getOwnedItem(skill._id) as TwodsixItem).update(itemData, null);
}

await this.actor.update(updateData);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/module/utils/sheetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export function calcModFor(characteristic:number):number {
// return calcModFor(characteristic);
// }

export function getKeyByValue(object, value) {
return Object.keys(object).find(key => object[key] === value);
}




15 changes: 8 additions & 7 deletions static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
"Migration": {
"Completed": "Twodsix System Migration to version {version} completed!",
"DoNotClose": "Migrating Twodsix to {version}. Do not close your game or shut down your server.",
"MigrationError0.6.25": "Migration error: Couldn't parse price for ${name}, it was ${price} but is now 0."
"MigrationError0.6.25": "Migration error: Couldn't parse price for ${name}, it was ${price} but is now 0.",
"MigrationError0_6_29": "0.6.30 migration failed to replace the characteristic '${characteristic}' of skill '${name}' so set it to '${fallback}'"
},
"No": "No",
"Rolls": {
Expand Down Expand Up @@ -192,7 +193,7 @@
"name": "Default Prototype Token Settings"
},
"effectOrTotal": {
"hint": "true=Show effect (i.e. roll+modifiers-target number, usually 8), false=show total (i.e. roll+modifiers)",
"hint": "true=Show effect (i.e. roll+modifiers-target number, usually 8), false=Show total (i.e. roll+modifiers)",
"name": "Show effect or total roll value for skill and characteristic rolls."
},
"initiativeFormula": {
Expand Down Expand Up @@ -222,23 +223,23 @@
"name": "What you want to call rolls with disadvantage (3d6kl2)."
},
"ShowLawLevel": {
"hint": "true=Show the 'Law Level' field, false=hide it",
"hint": "true=Show the 'Law Level' field, false=Hide it",
"name": "Show the 'Law Level' field on weapon sheets"
},
"ShowRecoil": {
"hint": "true=Show the 'Recoil' field, false=hide it",
"hint": "true=Show the 'Recoil' field, false=Hide it",
"name": "Show the 'Recoil' field on weapon sheets"
},
"ShowRateOfFire": {
"name": "true=Show the 'Rate of Fire' field, false=hide it",
"name": "true=Show the 'Rate of Fire' field, false=Hide it",
"hint": "Show the 'Rate of Fire' field on weapon sheets"
},
"ShowDamageType": {
"hint": "true=Show the 'Damage Type' field, false=hide it",
"hint": "true=Show the 'Damage Type' field, false=Hide it",
"name": "Show the 'Damage Type' field on weapon sheets"
},
"ShowWeaponType": {
"hint": "true=Show the 'Weapon Type' field, false=hide it",
"hint": "true=Show the 'Weapon Type' field, false=Hide it",
"name": "Show the 'Weapon Type' field on weapon sheets"
},
"ShowRangeBandAndHideRange": {
Expand Down
17 changes: 9 additions & 8 deletions static/lang/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
"Rolling": "Rullar",
"Skills": {
"AddSkill": ">>Ny färdighet<<",
"AddSkill": "Ny färdighet",
"DeleteItem": "Ta bort Sak",
"EditItem": "Ändra Sak",
"EditOrRemove": "Ändra el Sudda",
Expand Down Expand Up @@ -165,7 +165,8 @@
"Migration": {
"Completed": "Twodsix Systemmigrering till version {version} klar!",
"DoNotClose": "Migrerar Twodsix till {version}. Avsluta inte ditt spel och stäng inte ner servern.",
"MigrationError0.6.25": "Migrationsfel: Kunde inte tolka priset för ${name}, det var ${price} men är nu 0."
"MigrationError0.6.25": "Migrationsfel: Kunde inte tolka priset för ${name}, det var ${price} men är nu 0.",
"MigrationError0_6_29": "0.6.30 migrering misslyckades ersätta attributet '${characteristic}' på skillen '${name}' så satte den till '${fallback}'"
},
"No": "Nej",
"Rolls": {
Expand Down Expand Up @@ -193,7 +194,7 @@
"name": "Defaultprototypspelfigursinställningar"
},
"effectOrTotal": {
"hint": "sant=Visa effekten (dvs. resultat+modifierare-målnummer, normalt 8), falskt=visa total (dvs. resultat+modifierare)",
"hint": "sant=Visa effekten (dvs. resultat+modifierare-målnummer, normalt 8), falskt=Visa total (dvs. resultat+modifierare)",
"name": "Visa effekten eller totalvärdet när färgdighet och grundförmågor rullas."
},
"initiativeFormula": {
Expand All @@ -211,7 +212,7 @@
"name": "Modifierare for egenskapsvärde noll."
},
"systemMigrationVersion": {
"hint": "Innehåller schema versionen för Twodsix systemet. (Modifiera inte denna om du inte vet vad du håller på med.)",
"hint": "Innehåller schemaversionen för Twodsix systemet. (Modifiera inte denna om du inte vet vad du håller på med.)",
"name": "System Schema Version"
},
"termForAdvantage": {
Expand All @@ -228,19 +229,19 @@
},
"ShowRecoil": {
"name": "Visa 'Rekyl' fältet på vapenblad",
"hint": "true=Visa 'Rekyl' fältet, falskt=Göm det"
"hint": "sant=Visa 'Rekyl' fältet, falskt=Göm det"
},
"ShowRateOfFire": {
"name": "Visa 'Eldhastighet' fältet på vapenblad",
"hint": "true=Visa 'Eldhastighet' fältet, falskt=Göm det"
"hint": "sant=Visa 'Eldhastighet' fältet, falskt=Göm det"
},
"ShowDamageType": {
"name": "Visa 'Skadetyp' fältet på vapenblad",
"hint": "true=Visa 'Skadetyp' fältet, falskt=Göm det"
"hint": "sant=Visa 'Skadetyp' fältet, falskt=Göm det"
},
"ShowWeaponType": {
"name": "Visa 'Vapentyp' fältet på vapenblad",
"hint": "true=Visa 'Vapentyp' fältet, falskt=Göm det"
"hint": "sant=Visa 'Vapentyp' fältet, falskt=Göm det"
},
"ShowRangeBandAndHideRange": {
"name": "Visa 'Räckviddsband' och *göm* 'Räckvidd' på vapenblad och karaktärsblad",
Expand Down
2 changes: 1 addition & 1 deletion static/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
],
"name": "Skill Name",
"value": -3,
"characteristic": "STR",
"characteristic": "strength",
"type": "skills",
"description": "",
"shortdescr": "",
Expand Down
14 changes: 7 additions & 7 deletions static/templates/actors/actor-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<div class="character-characteristics">
<div class="stat strength" data-characteristic="strength">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.strength.mod}}" data-label="{{data.characteristics.strength.shortLabel}}"
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.strength.mod}}" data-label="{{data.characteristics.strength.key}}"
>{{localize "TWODSIX.Actor.Characteristics.STR"}} <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll strength"/></span>

<span class="stat-ability"><input type="number" min="0" name="data.characteristics.strength.value"
Expand All @@ -35,7 +35,7 @@
</div>

<div class="stat dexterity" data-characteristic="dexterity">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.dexterity.mod}}" data-label="{{data.characteristics.dexterity.shortLabel}}"
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.dexterity.mod}}" data-label="{{data.characteristics.dexterity.key}}"
>{{localize "TWODSIX.Actor.Characteristics.DEX"}} <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll dexterity"/>
</span>

Expand All @@ -50,7 +50,7 @@
</div>

<div class="stat endurance" data-characteristic="endurance">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.endurance.mod}}" data-label="{{data.characteristics.endurance.shortLabel}}"
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.endurance.mod}}" data-label="{{data.characteristics.endurance.key}}"
>{{localize "TWODSIX.Actor.Characteristics.END"}} <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll endurance"/>
</span>

Expand All @@ -65,7 +65,7 @@
</div>

<div class="stat intelligence" data-characteristic="intelligence">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.intelligence.mod}}" data-label="{{data.characteristics.intelligence.shortLabel}}"
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.intelligence.mod}}" data-label="{{data.characteristics.intelligence.key}}"
>{{localize "TWODSIX.Actor.Characteristics.INT"}} <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll intelligence"/>
</span>

Expand All @@ -80,7 +80,7 @@
</div>

<div class="stat education" data-characteristic="education">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.education.mod}}" data-label="{{data.characteristics.education.shortLabel}}"
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.education.mod}}" data-label="{{data.characteristics.education.key}}"
>{{localize "TWODSIX.Actor.Characteristics.EDU"}} <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll education"/>
</span>

Expand All @@ -95,7 +95,7 @@
</div>

<div class="stat socialStanding" data-characteristic="socialStanding">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.socialStanding.mod}}" data-label="{{data.characteristics.socialStanding.shortLabel}}"
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.socialStanding.mod}}" data-label="{{data.characteristics.socialStanding.key}}"
>{{localize "TWODSIX.Actor.Characteristics.SOC"}} <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll socialStanding"/>
</span>

Expand All @@ -110,7 +110,7 @@
</div>

<div class="special psionicStrength" data-characteristic="psionicStrength">
<span class="special-name rollable" data-roll="2d6+{{data.characteristics.psionicStrength.mod}}" data-label="{{data.characteristics.psionicStrength.shortLabel}}"
<span class="special-name rollable" data-roll="2d6+{{data.characteristics.psionicStrength.mod}}" data-label="{{data.characteristics.psionicStrength.key}}"
>{{localize "TWODSIX.Actor.Characteristics.PSI"}} <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll psionicStrength"/>
</span>

Expand Down
3 changes: 2 additions & 1 deletion static/templates/actors/parts/actor/actor-skills.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<span class="mini-dice centre"><img class="rollable" data-label="{{item.name}}" src="./systems/twodsix/assets/d6-icon.svg" alt="d6"/></span>
<span class="item-name rollable" data-label="{{item.name}}" data-roll="2d6+{{data.mod}}+{{data.value}}">{{item.name}}</span>
<span class="item-name centre rollable" data-label="{{item.name}}" data-roll="2d6+{{data.mod}}+{{data.value}}">{{data.value}}</span>
<span class="item-name centre rollable" data-label="{{item.name}}" data-roll="2d6+{{data.mod}}+{{data.value}}" for="skill-modifier">{{data.characteristic}} ({{numberFormat data.mod decimals=0 sign=true}})</span>
<span class="item-name centre rollable" data-label="{{item.name}}" data-roll="2d6+{{data.mod}}+{{data.value}}" for="skill-modifier">
{{localize (concat "TWODSIX.Actor.Characteristics." (lookup ../config.CHARACTERISTICS data.characteristic))}}({{numberFormat data.mod decimals=0 sign=true}})</span>
<span class="total-output flex1 skill-mod rollable" data-label="{{item.name}}" data-roll="2d6+{{data.mod}}+{{data.value}}">{{data.total}}</span>
<span class="item-controls centre">
<a class="skl item-control item-edit" title='{{localize "TWODSIX.Actor.Skills.EditItem"}}'><i class="fas fa-edit"></i></a>
Expand Down
14 changes: 7 additions & 7 deletions static/templates/items/skills-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<label for="data.characteristic" class="resource-label">{{localize "TWODSIX.Items.Skills.Modifier"}}</label>
<select class="select-mod" name="data.characteristic" value={{characteristic}}>
{{#select data.characteristic}}
<option value="STR" for="skill-modifier">{{localize "TWODSIX.Items.Skills.STR"}}</option>
<option value="DEX" for="skill-modifier">{{localize "TWODSIX.Items.Skills.DEX"}}</option>
<option value="END" for="skill-modifier">{{localize "TWODSIX.Items.Skills.END"}}</option>
<option value="INT" for="skill-modifier">{{localize "TWODSIX.Items.Skills.INT"}}</option>
<option value="EDU" for="skill-modifier">{{localize "TWODSIX.Items.Skills.EDU"}}</option>
<option value="SOC" for="skill-modifier">{{localize "TWODSIX.Items.Skills.SOC"}}</option>
<option value="PSI" for="skill-modifier">{{localize "TWODSIX.Items.Skills.PSI"}}</option>
<option value="strength" for="skill-modifier">{{localize "TWODSIX.Items.Skills.STR"}}</option>
<option value="dexterity" for="skill-modifier">{{localize "TWODSIX.Items.Skills.DEX"}}</option>
<option value="endurance" for="skill-modifier">{{localize "TWODSIX.Items.Skills.END"}}</option>
<option value="intelligence" for="skill-modifier">{{localize "TWODSIX.Items.Skills.INT"}}</option>
<option value="education" for="skill-modifier">{{localize "TWODSIX.Items.Skills.EDU"}}</option>
<option value="socialStanding" for="skill-modifier">{{localize "TWODSIX.Items.Skills.SOC"}}</option>
<option value="psionicStrength" for="skill-modifier">{{localize "TWODSIX.Items.Skills.PSI"}}</option>
{{/select}}
</select>
</div>
Expand Down
8 changes: 1 addition & 7 deletions static/templates/items/weapon-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,9 @@
{{/if}}

{{#if data.settings.ShowRecoil}}
<!-- Should be a checkbox, but it behaved strangely, so I switched to a dropdown instead. -->
<div class="item-recoil">
<span class="resource-label">{{localize "TWODSIX.Items.Weapon.recoil"}}</span>
<select name="data.recoil" value={{data.recoil}}>
{{#select data.recoil}}
<option value="true">{{localize "TWODSIX.Yes"}}</option>
<option value="false">{{localize "TWODSIX.No"}}</option>
{{/select}}
</select>
<input type="checkbox" class="checkbox" name="data.recoil" {{checked data.recoil}} data-dtype="Boolean" />
</div>
{{/if}}

Expand Down

0 comments on commit 36061b4

Please sign in to comment.