Skip to content

Commit

Permalink
fix: Rebuilds a lot of the internals for skill rolls etc. Preparation…
Browse files Browse the repository at this point in the history
… for issue 86, 120, 168.
  • Loading branch information
xdy committed Nov 7, 2020
1 parent 6d5c452 commit 28e059d
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 242 deletions.
4 changes: 2 additions & 2 deletions src/module/entities/TwodsixActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class TwodsixActor extends Actor {
// things organized.
switch (actorData.type) {
case 'traveller':
this._prepareCharacterData(actorData);
this._prepareTravellerData(actorData);
break;
case 'ship':
break;
Expand All @@ -32,7 +32,7 @@ export default class TwodsixActor extends Actor {
/**
* Prepare Character type specific data
*/
async _prepareCharacterData(actorData:ActorData):Promise<void> {
_prepareTravellerData(actorData:ActorData):void {
// Get the Actor's data object
const {data} = actorData;

Expand Down
2 changes: 1 addition & 1 deletion src/module/hooks/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Hooks.once("ready", async function () {
}
}

const needMigration = worldVersion === null || !isNewerVersion(worldVersion, systemVersion);
const needMigration = worldVersion === null || isNewerVersion(worldVersion, systemVersion);

// Perform the migration
if (needMigration && game.user.isGM) {
Expand Down
19 changes: 11 additions & 8 deletions src/module/sheets/AbstractTwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export class AbstractTwodsixActorSheet extends ActorSheet {

let data:any;
try {
if (!event.dataTransfer) {
return false;
}
data = JSON.parse(event.dataTransfer.getData('text/plain'));
} catch (err) {
console.log(`Twodsix | Drop failed with {err}`);
Expand Down Expand Up @@ -203,14 +206,14 @@ export class AbstractTwodsixActorSheet extends ActorSheet {
const actorData = sheetData.actor;

// Initialize containers.
const storage = [];
const equipment = [];
const weapon = [];
const armor = [];
const augment = [];
const tool = [];
const junk = [];
const skills = [];
const storage:Item[] = [];
const equipment:Item[] = [];
const weapon:Item[] = [];
const armor:Item[] = [];
const augment:Item[] = [];
const tool:Item[] = [];
const junk:Item[] = [];
const skills:Item[] = [];

// Iterate through items, allocating to containers
for (const i of sheetData.items) {
Expand Down
59 changes: 8 additions & 51 deletions src/module/sheets/TwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export class TwodsixActorSheet extends AbstractTwodsixActorSheet {
private async _onRoll(event:Event):Promise<void> {
event.preventDefault();
event.stopPropagation();
const advanced = event["shiftKey"];
const showThrowDialog = event["shiftKey"];
const element = event.currentTarget;
const dataset = element["dataset"];
const itemId = $(event.currentTarget).parents('.item').attr('data-item-id');
await TwodsixRolls.performRoll(this.actor, itemId, dataset, advanced);
await TwodsixRolls.performRoll(this.actor, itemId, dataset, showThrowDialog);
}

/**
Expand All @@ -109,56 +109,13 @@ export class TwodsixActorSheet extends AbstractTwodsixActorSheet {
event.stopPropagation();
const itemId = $(event.currentTarget).parents('.item').attr('data-item-id');
const item = this.actor.getOwnedItem(itemId) as TwodsixItem;
TwodsixRolls.rollDamage(item, true, this.actor);
}

//Unused, but something like it is needed to support cascade/subskills, so letting it stay for now.
// /**
// * Handle skill upgrade
// * @param {Event} event The originating click event
// * @private
// */
// _onUpgrade(event:{ preventDefault:() => void; currentTarget:any; }):void {
// event.preventDefault();
// const element = event.currentTarget;
// const skillName = element.getAttribute('data-label');
// const actorData = this.actor.data;
// const data = actorData.data;
// const matchingSkill = data.skills[skillName];
// const maxSkillLevel = game.settings.get('twodsix', 'maxSkillLevel');
//
// if (matchingSkill) {
// if (TwodsixActorSheet.isChildSkill(matchingSkill)) {
// if (this.parentSkillIsTrained(matchingSkill) && matchingSkill.value < maxSkillLevel) {
// this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value + 1});
// }
// } else if (matchingSkill.value < 0) {
// this.actor.update({[`data.skills.${skillName}.value`]: 0});
// if (matchingSkill.hasChildren) {
// this.processChildren(data, skillName, 0);
// }
// } else if (!matchingSkill.hasChildren && matchingSkill.value < maxSkillLevel) {
// this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value + 1});
// }
// }
// }
//
// private processChildren(data:any, skillName:string, level:number) {
// for (const [key] of Object.entries(data.skills)) {
// if (key.startsWith(skillName + "-")) {
// this.actor.update({[`data.skills.${key}.value`]: level});
// }
// }
// }
//
// private static isChildSkill(matchingSkill:any) {
// return matchingSkill.childOf != null && matchingSkill.childOf != "";
// }
//
// private parentSkillIsTrained(matchingSkill:any) {
// const parent = this.actor.data.data.skills[matchingSkill.childOf];
// return parent && parent.value >= 0;
// }
async function extracted(this):Promise<void> {
return await TwodsixRolls.rollDamage(item, true, this.actor);
}

extracted.call(this);
}
}


Expand Down
Loading

0 comments on commit 28e059d

Please sign in to comment.