Skip to content

Commit

Permalink
More work on clock keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunomiac committed Dec 9, 2023
1 parent 237207b commit 17b493d
Show file tree
Hide file tree
Showing 59 changed files with 16,363 additions and 12,803 deletions.
25,793 changes: 14,107 additions & 11,686 deletions css/style.min.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion module/BladesPushAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default class BladesPushAlert {
}
static isInitialized = false;
static Initialize() {
game.eunoblades ??= {};
Hooks.once("ready", async () => {
let pushController = game.eunoblades.PushController;
if (!(pushController instanceof BladesPushAlert)) {
Expand Down
51 changes: 50 additions & 1 deletion module/blades.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// #region ▮▮▮▮▮▮▮ IMPORTS ▮▮▮▮▮▮▮ ~
import C, { ActionTrait, AttributeTrait, RollType, ConsequenceType } from "./core/constants.js";
import C, { ActionTrait, ClockColor, AttributeTrait, RollType, ConsequenceType } from "./core/constants.js";
import registerSettings, { initTinyMCEStyles, initCanvasStyles, initDOMStyles } from "./core/settings.js";
import { registerHandlebarHelpers, preloadHandlebarsTemplates } from "./core/helpers.js";
import BladesPushAlert from "./BladesPushAlert.js";
import BladesChat from "./BladesChat.js";
import U from "./core/utilities.js";
import logger from "./core/logger.js";
import G, { Initialize as GsapInitialize } from "./core/gsap.js";
import BladesClock, { BladesClockKey } from "./documents/items/BladesClock.js";
import BladesActorProxy, { BladesActor, BladesPC, BladesCrew, BladesNPC, BladesFaction } from "./documents/BladesActorProxy.js";
import BladesItemProxy, { BladesItem, BladesClockKeeper, BladesGMTracker, BladesLocation, BladesScore, BladesProject } from "./documents/BladesItemProxy.js";
import BladesItemSheet from "./sheets/item/BladesItemSheet.js";
Expand Down Expand Up @@ -476,6 +477,46 @@ class GlobalGetter {
};
BladesRoll.NewRoll(conf);
}
async addClockKey(keyName, clockNames) {
const { ClockKeeper: CK } = game.eunoblades ?? {};
if (!CK) {
return undefined;
}
const clocksData = [];
const [curClock] = U.sample(clockNames);
const clocks = [];
while (clockNames.length) {
const name = clockNames.shift();
const color = U.sample([ClockColor.white, ClockColor.red, ClockColor.yellow, ClockColor.cyan]);
const [max] = U.sample([2, 3, 4, 5, 6, 8, 10, 12]);
let value;
if (curClock === name) {
value = U.randInt(1, max - 1);
}
else if (clockNames.includes(curClock)) {
value = max;
}
else {
value = 0;
}
clocksData.push({ name, color, value, max });
}
const clockKey = await CK.addClockKey({
sceneID: game.scenes.current?.id,
name: keyName
}, clocksData.shift());
if (!clockKey) {
return undefined;
}
while (clocksData.length) {
await clockKey.addClock(clocksData.shift());
}
return {
key: clockKey,
clocks
};
}
get clockKeys() { return game.eunoblades.ClockKeeper?.clockKeys; }
}
// #region Globals: Exposing Functionality to Global Scope ~
/* DEVCODE*/ Object.assign(globalThis, {
Expand All @@ -494,6 +535,8 @@ class GlobalGetter {
BladesPCSheet,
BladesCrewSheet,
BladesFactionSheet,
BladesClock,
BladesClockKey,
BladesNPCSheet,
BladesActiveEffect,
BladesPushAlert,
Expand All @@ -520,6 +563,12 @@ class GlobalGetter {
// #endregion Globals
// #region ████████ SYSTEM INITIALIZATION: Initializing Blades In The Dark System on 'Init' Hook ████████
Hooks.once("init", async () => {
// Initialize Game object
game.eunoblades = {
Clocks: new Collection(),
ClockKeys: new Collection(),
Consequences: new Collection()
};
// Register System Settings
registerSettings();
eLog.display("Initializing Blades In the Dark System");
Expand Down
84 changes: 84 additions & 0 deletions module/core/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ export var Tag;
GangType["Vehicle"] = "Vehicle";
})(GangType = Tag.GangType || (Tag.GangType = {}));
})(Tag || (Tag = {}));
export var ClockKeyDisplayMode;
(function (ClockKeyDisplayMode) {
ClockKeyDisplayMode["full"] = "full";
ClockKeyDisplayMode["clocks"] = "clocks";
ClockKeyDisplayMode["currentClock"] = "currentClock";
})(ClockKeyDisplayMode || (ClockKeyDisplayMode = {}));
const C = {
SYSTEM_ID: "eunos-blades",
SYSTEM_NAME: "Euno's Blades",
Expand Down Expand Up @@ -590,6 +596,84 @@ const C = {
dBLUE: "rgba(0,118,118, 1)",
ddBLUE: "rgba(0, 77, 77, 1)"
},
ClockKeyPositions: {
0: {
keyDimensions: { width: 0, height: 0 },
keyCenter: { x: 0, y: 0 },
clocksCenter: { x: 0, y: 0 },
clocksCenterDimensions: { width: 0, height: 0 },
clocks: {}
},
1: {
keyDimensions: { width: 202, height: 455 },
keyCenter: { x: 101, y: 227 },
clocksCenter: { x: 101, y: 99 },
clocksCenterDimensions: { width: 110, height: 110 },
clocks: {
0: { x: 101, y: 99 }
}
},
2: {
keyDimensions: { width: 202, height: 625 },
keyCenter: { x: 101, y: 312 },
clocksCenter: { x: 101, y: 189 },
clocksCenterDimensions: { width: 110, height: 290 },
clocks: {
0: { x: 101, y: 99 },
1: { x: 101, y: 279 }
}
},
3: {
keyDimensions: { width: 280, height: 915 },
keyCenter: { x: 140, y: 457 },
clocksCenter: { x: 140, y: 169 },
clocksCenterDimensions: { width: 242, height: 222 },
clocks: {
0: { x: 140, y: 99 },
1: { x: 74, y: 211 },
2: { x: 206, y: 211 }
}
},
4: {
keyDimensions: { width: 376, height: 1140 },
keyCenter: { x: 188, y: 570 },
clocksCenter: { x: 188, y: 185 },
clocksCenterDimensions: { width: 284, height: 284 },
clocks: {
0: { x: 188, y: 99 },
1: { x: 101, y: 185 },
2: { x: 275, y: 185 },
3: { x: 188, y: 273 }
}
},
5: {
keyDimensions: { width: 376, height: 1140 },
keyCenter: { x: 188, y: 570 },
clocksCenter: { x: 188, y: 185 },
clocksCenterDimensions: { width: 284, height: 284 },
clocks: {
0: { x: 188, y: 99 },
1: { x: 101, y: 185 },
2: { x: 275, y: 185 },
3: { x: 188, y: 273 },
4: { x: 188, y: 452 }
}
},
6: {
keyDimensions: { width: 376, height: 1140 },
keyCenter: { x: 188, y: 570 },
clocksCenter: { x: 188, y: 185 },
clocksCenterDimensions: { width: 284, height: 284 },
clocks: {
0: { x: 188, y: 99 },
1: { x: 101, y: 185 },
2: { x: 275, y: 185 },
3: { x: 188, y: 273 },
4: { x: 188, y: 452 },
5: { x: 188, y: 683 }
}
}
},
Loadout: {
selections: [
{ value: "Light", display: "Light" },
Expand Down
6 changes: 6 additions & 0 deletions module/core/gsap.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@ const gsapEffects = {
export function Initialize() {
if (gsapPlugins.length) {
U.gsap.registerPlugin(...gsapPlugins);
Object.assign(globalThis, {
TextPlugin,
Flip,
MotionPathPlugin
});
}
Object.entries(gsapEffects).forEach(([name, effect]) => {
U.gsap.registerEffect(Object.assign(effect, { name }));
Expand Down Expand Up @@ -790,4 +795,5 @@ export function ApplyConsequenceAnimations(html) {
}
});
}
export { TextPlugin, Flip, MotionPathPlugin };
export default U.gsap;
5 changes: 5 additions & 0 deletions module/core/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ const handlebarHelpers = {
}
return outStr;
},
// Merge helper - To merge additional properties into a template's context
merge(context, ...args) {
args.pop();
return args.reduce((acc, val) => Object.assign(acc, val), context);
},
// For loop: {{#for [from = 0, to, stepSize = 1]}}<html content, this = index>{{/for}}
for: (...args) => {
const options = args.pop();
Expand Down
3 changes: 2 additions & 1 deletion module/core/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// #region ▮▮▮▮▮▮▮ IMPORTS ▮▮▮▮▮▮▮ ~
import C, { SVGDATA } from "./constants.js";
// eslint-disable-next-line import/no-unresolved
import { gsap, MotionPathPlugin } from "/scripts/greensock/esm/all.js";
import { gsap, TextPlugin, Flip, MotionPathPlugin } from "/scripts/greensock/esm/all.js";
gsap.registerPlugin(MotionPathPlugin);
// #endregion ▮▮▮▮ IMPORTS ▮▮▮▮
// #region ▮▮▮▮▮▮▮ [HELPERS] Internal Functions, Data & References Used by Utility Functions ▮▮▮▮▮▮▮ ~
Expand Down Expand Up @@ -1663,6 +1663,7 @@ export default {
changeContainer,
// ░░░░░░░ GreenSock ░░░░░░░
gsap, get, set, getGSAngleDelta,
TextPlugin, Flip, MotionPathPlugin,
getRawCirclePath, drawCirclePath,
getColorVals, getRGBString, getHEXString, getContrastingColor, getRandomColor,
getSiblings,
Expand Down
33 changes: 13 additions & 20 deletions module/documents/actors/BladesFaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,27 @@ class BladesFaction extends BladesActor {
get rollOppModsData() { return []; }
// #endregion
// #endregion
_clocks = {};
getClocks(isRefreshing = false) {
const clockIDs = Object.keys(this.system.clocks);
if (clockIDs.length === 0) {
return {};
}
for (const clockID of clockIDs) {
if (isRefreshing || !(clockID in this._clocks)) {
this._clocks[clockID] = new BladesClock(this.system.clocks[clockID]);
}
}
return this._clocks;
}
getClock(clockID) {
return this.getClocks()[clockID];
// _clocks: Collection<BladesClock> = new Collection();
// get clocks(): Collection<BladesClock> = {
// return new Collection()
// }
get clocks() {
return new Collection(Object.entries(this.system.clocks ?? {})
.sort((a, b) => a[1].index - b[1].index)
.map(([id, data]) => [
id,
game.eunoblades.Clocks.get(id) ?? new BladesClock(data)
]));
}
async addClock() {
const numClocks = Object.values(this.getClocks()).length;
return await BladesClock.Create({
id: randomID(),
target: this,
targetKey: "system.clocks",
index: numClocks
index: this.clocks.size
});
}
async deleteClock(clockID) {
await this.getClock(clockID)?.delete();
delete this._clocks[clockID];
await game.eunoblades.Clocks.get(clockID)?.delete();
}
}
export default BladesFaction;
3 changes: 1 addition & 2 deletions module/documents/actors/BladesPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class BladesPC extends BladesActor {
};
const pc = (await super.create(data, options));
await BladesClock.Create({
id: randomID(),
name: "",
target: pc,
targetKey: "system.healing",
Expand All @@ -57,7 +56,7 @@ class BladesPC extends BladesActor {
max: 4,
isVisible: true,
isNameVisible: false,
isActive: true
isShowingControls: false
});
return pc;
}
Expand Down
Loading

0 comments on commit 17b493d

Please sign in to comment.