Skip to content

Commit

Permalink
More v12 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcglincy committed Jun 20, 2024
1 parent 9340d81 commit 54aa469
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 3.0.3

- Fix more v12 breakage due to data=>system changes: slotting apps, linked infestations, vehicle owners, attack crit multiplier, scvmfactory npcs, etc.
- Fix cyberdeck+ slots roll, which can be evaluated synchronously.

# 3.0.2

- Fix more v12 breakage, for chargen abilities and items.
Expand Down
3 changes: 0 additions & 3 deletions module/actor/character-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class CYCharacterSheet extends CYActorSheet {
/** @override */
async getData() {
const superData = await super.getData();
console.log("character superdata", superData);
// TODO: move this to prepareItems?
superData.data.items.forEach(item => {
item.system.equippable = (
Expand Down Expand Up @@ -114,15 +113,13 @@ export class CYCharacterSheet extends CYActorSheet {
return;
}
const deck = this._findDropCyberdeck(event);
console.log(deck);
if (deck && deck.type === CY.itemTypes.cyberdeck) {
// ...onto cyberdecks
await deck.slotApp(item);
}
}

_findDropCyberdeck(event) {
console.log(event);
const dropIntoItem = $(event.srcElement).closest(".cyberdeck-row-wrapper");
return dropIntoItem.length > 0
? this.actor.items.get(dropIntoItem.attr("data-item-id"))
Expand Down
2 changes: 1 addition & 1 deletion module/combat/attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function rollAttack(
damageFormula = `${damageFormula} * 2`;
}
if (isCrit) {
const critMultiplier = item.data.data.critMultiplier ?? 2;
const critMultiplier = item.data.system.critMultiplier ?? 2;
damageFormula = `${damageFormula} * ${critMultiplier}`;
}
damageRoll = new Roll(damageFormula);
Expand Down
4 changes: 2 additions & 2 deletions module/generator/scvmfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ async function createActorWithScvm(s) {
const lastWord = npcData.name.split(" ").pop();
npcData.name = `${actor.name}'s ${lastWord}`;
if (npcData.type === "vehicle") {
npcData.data.ownerId = actor.id;
npcData.system.ownerId = actor.id;
}
const npcActor = await CYActor.create(npcData);
npcActor.sheet.render(true);
Expand Down Expand Up @@ -494,7 +494,7 @@ async function updateActorWithScvm(actor, s) {
const lastWord = npcData.name.split(" ").pop();
npcData.name = `${actor.name}'s ${lastWord}`;
if (npcData.type === "vehicle") {
npcData.data.ownerId = actor.id;
npcData.system.ownerId = actor.id;
}
const npcActor = await CYActor.create(npcData);
npcActor.sheet.render(true);
Expand Down
19 changes: 9 additions & 10 deletions module/item/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CY } from "../config.js";
import { TABLES_PACK, drawDocument, dupeData } from "../packutils.js";
import { soundEffects } from "../settings.js";
import { uiEject, uiError, uiSlot } from "../sound.js";
import { byName, rollTotal } from "../utils.js";
import { byName, rollTotalSync } from "../utils.js";

/**
* @extends {Item}
Expand Down Expand Up @@ -69,7 +69,7 @@ import { byName, rollTotal } from "../utils.js";
return;
}
const data = dupeData(infestation);
data.data.nanoId = this.id;
data.system.nanoId = this.id;
await this.parent.createEmbeddedDocuments("Item", [data]);
}

Expand All @@ -80,10 +80,9 @@ import { byName, rollTotal } from "../utils.js";
} else if (this.type === CY.itemTypes.cyberdeck && this.parent) {
const rollData = this.parent.getRollData();
if (this.system.slotFormula) {
// TODO: fix, since prepareDerivedData doesn't appear to be async.
// Maybe setting the slots randomly should be an item post-create hook?
//this.system.slots = Math.max(await rollTotal(this.system.slotFormula, rollData), 1);
this.system.slots = 3;
// e.g., Cyberdeck+ has slots equal to the owner's knowledge + 4.
// We assume this is a non-random, can-be-synchronous roll.
this.system.slots = Math.max(rollTotalSync(this.system.slotFormula, rollData), 1);
} else {
this.system.slots = 1;
}
Expand All @@ -110,9 +109,9 @@ import { byName, rollTotal } from "../utils.js";
// slots available, so slot it
if (soundEffects()) {
uiSlot();
setTimeout(() => app.update({ "data.cyberdeckId": this._id }), 1000);
setTimeout(() => app.update({ "system.cyberdeckId": this._id }), 1000);
} else {
await app.update({ "data.cyberdeckId": this._id });
await app.update({ "system.cyberdeckId": this._id });
}
} else {
// no empty slots
Expand All @@ -125,9 +124,9 @@ import { byName, rollTotal } from "../utils.js";
if (this.system.cyberdeckId) {
if (soundEffects()) {
uiEject();
setTimeout(() => this.update({ "data.cyberdeckId": null }), 1000);
setTimeout(() => this.update({ "system.cyberdeckId": null }), 1000);
} else {
await this.update({ "data.cyberdeckId": null });
await this.update({ "system.cyberdeckId": null });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion module/packutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function documentFromResult(result) {

export function dupeData(doc) {
return {
data: doc.system,
system: doc.system,
img: doc.img,
name: doc.name,
type: doc.type,
Expand Down
5 changes: 5 additions & 0 deletions module/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export async function rollTotal(formula, rollData={}) {
return roll.total;
};

export function rollTotalSync(formula, rollData={}) {
return new Roll(formula, rollData).evaluateSync().total;
};


// https://stackoverflow.com/questions/4959975/generate-random-number-between-two-numbers-in-javascript
export const randomIntFromInterval = (min, max) => {
// min and max included
Expand Down

0 comments on commit 54aa469

Please sign in to comment.