-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathModularFate.js
More file actions
910 lines (815 loc) · 34.9 KB
/
ModularFate.js
File metadata and controls
910 lines (815 loc) · 34.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
/**
* The Fate Core game system for Foundry Virtual Tabletop
* Author: Richard Bellingham, partially based on work by Nick van Oosten (NickEast)
* Software License: GNU GPLv3
* Content License:
* This work is based on Fate Core System and Fate Accelerated Edition (found at http://www.faterpg.com/),
* products of Evil Hat Productions, LLC, developed, authored, and edited by Leonard Balsera, Brian Engard,
* Jeremy Keller, Ryan Macklin, Mike Olson, Clark Valentine, Amanda Valentine, Fred Hicks, and Rob Donoghue,
* and licensed for our use under the Creative Commons Attribution 3.0 Unported license
* (http://creativecommons.org/licenses/by/3.0/).
*
* This work is based on Fate Condensed (found at http://www.faterpg.com/), a product of Evil Hat Productions, LLC,
* developed, authored, and edited by PK Sullivan, Ed Turner, Leonard Balsera, Fred Hicks, Richard Bellingham, Robert Hanz, Ryan Macklin,
* and Sophie Lagacé, and licensed for our use under the Creative Commons Attribution 3.0 Unported license (http://creativecommons.org/licenses/by/3.0/).
*
*
* Note to self: New standardised hook signatures:
* preCreate[documentName](document:Document, data:object, options:object, userId:string) {}
* create[documentName](document:Document, options:object, userId: string) {}
* preUpdate[documentName](document:Document, change:object, options:object, userId: string) {}
* update[documentName](document:Document, change:object, options:object, userId: string) {}
* preDelete[documentName](document:Document, options:object, userId: string) {}
* delete[documentName](document:Document, options:object, userId: string) {}
*/
/* -------------------------------- */
/* System initialization */
/* -------------------------------- */
import { ModularFateCharacter } from "./scripts/ModularFateCharacter.js"
import { ExtraSheet } from "./scripts/ExtraSheet.js"
import { Thing } from "./scripts/Thing.js"
import { ModularFateActor } from "./scripts/ModularFateActor.js"
import { ModularFateExtra } from "./scripts/ModularFateExtra.js"
Hooks.on("preCreateActor", async (actor, data, options, userId) => {
if (actor.type == "Thing"){
if (!options.thing){
ui.notifications.error(game.i18n.localize("ModularFate.CantCreateThing"));
return false;
}
}
if (actor.type == "ModularFate"){
if (game.user == game.users.find(e => e.isGM && e.active) || game.user.id === userId){
if (actor?.data?.data?.details?.fatePoints?.refresh === ""){
let modified_data = await initialiseModularFateCharacter(actor);
data.data = modified_data.data;
}
}
}
});
async function initialiseModularFateCharacter (actor) {
//Modifies the data of the supplied actor to add tracks, aspects, etc. from system settings, then returns the data.
let working_data = actor.data.toJSON();
// Logic to set up Refresh and Current
let refresh = game.settings.get("ModularFate", "refreshTotal");
working_data.data.details.fatePoints.refresh = refresh;
working_data.data.details.fatePoints.current = refresh;
let p_skills=working_data.data.skills;
//Check to see what skills the character has compared to the global skill list
var skill_list = game.settings.get("ModularFate","skills");
// This is the number of skills the character has currently.
//We only need to add any skills if this is currently 0,
let skills_to_add = [];
for (let w in skill_list){
let w_skill = skill_list[w];
if (p_skills[w]!=undefined){
} else {
if(w_skill.pc){
skills_to_add.push(w_skill);
}
}
}
if (skills_to_add.length >0){
//Add any skills from the global list that they don't have at rank 0.
skills_to_add.forEach(skill => {
skill.rank=0;
p_skills[skill.name]=skill;
})
}
let aspects = game.settings.get("ModularFate", "aspects");
let player_aspects = duplicate(aspects);
for (let a in player_aspects) {
player_aspects[a].value = "";
}
//Now to store the aspect list to the character
working_data.data.aspects = player_aspects;
//Step one, get the list of universal tracks.
let world_tracks = duplicate(game.settings.get("ModularFate", "tracks"));
let tracks_to_write = working_data.data.tracks;
for (let t in world_tracks) {
let track = world_tracks[t];
if (track.universal == true) {
tracks_to_write[t] = world_tracks[t];
}
}
for (let t in tracks_to_write) {
let track = tracks_to_write[t];
//Add a notes field. This is a bit redundant for stress tracks,
//but useful for aspects, indebted, etc. Maybe it's configurable whether we show the
//notes or not for any given track. LATER NOTE: It is not.
track.notes = "";
//If this box is an aspect when marked, it needs an aspect.name data field.
if (track.aspect == game.i18n.localize("ModularFate.DefinedWhenMarked")) {
track.aspect = {};
track.aspect.name = "";
track.aspect.when_marked = true;
track.aspect.as_name = false;
}
if (track.aspect == game.i18n.localize("ModularFate.AspectAsName")) {
track.aspect = {};
track.aspect.name = "";
track.aspect.when_marked = true;
track.aspect.as_name = false;
}
//Initialise the box array for this track
if (track.boxes > 0) {
let box_values = [];
for (let i = 0; i < track.boxes; i++) {
box_values.push(false);
}
track.box_values = box_values;
}
}
working_data.data.tracks = tracks_to_write;
let tracks = working_data.data.tracks;
let categories = game.settings.get("ModularFate", "track_categories");
//GO through all the tracks, find the ones with boxes, check the number of boxes and linked skills and initialise as necessary.
for (let t in tracks) {
let track = tracks[t];
if (track.universal) {
track.enabled = true;
}
// Check for linked skills and enable/add boxes as necessary.
if (track.linked_skills != undefined && track.linked_skills.length > 0 && Object.keys(working_data.data.skills).length > 0) {
let skills = working_data.data.skills;
let linked_skills = tracks[t].linked_skills;
let box_mod = 0;
for (let i = 0; i < linked_skills.length; i++) {
let l_skill = linked_skills[i].linked_skill;
let l_skill_rank = linked_skills[i].rank;
let l_boxes = linked_skills[i].boxes;
let l_enables = linked_skills[i].enables;
//Get the value of the player's skill
if (working_data.data.skills[l_skill] == undefined){
}else {
let skill_rank = working_data.data.skills[l_skill].rank;
//If this is 'enables' and the skill is too low, disable.
if (l_enables && skill_rank < l_skill_rank) {
track.enabled = false;
}
//If this adds boxes and the skill is high enough, add boxes if not already present.
//Telling if the boxes are already present is the hard part.
//If boxes.length > boxes it means we have added boxes, but how many? I think we need to store a count and add
//or subract them at the end of our run through the linked skills.
if (l_boxes > 0 && skill_rank >= l_skill_rank) {
box_mod += l_boxes;
}
}
} //End of linked_skill iteration
//Now to add or subtract the boxes
//Only if this track works with boxes, though
if (track.boxes > 0 || track.box_values != undefined) {
//If boxes + box_mod is greater than box_values.length add boxes
let toModify = track.boxes + box_mod - track.box_values.length;
if (toModify > 0) {
for (let i = 0; i < toModify; i++) {
track.box_values.push(false);
}
}
//If boxes + box_mod is less than box_values.length subtract boxes.
if (toModify < 0) {
for (let i = toModify; i < 0; i++) {
track.box_values.pop();
}
}
}
}
}
return working_data;
}
Hooks.once('ready', async function () {
if (game.settings.get("ModularFate","run_once") == false){
if (game.user.isGM){
ModularFateConstants.awaitOKDialog(game.i18n.localize("ModularFate.WelcomeTitle"),game.i18n.localize("ModularFate.WelcomeText"),500,250);
game.settings.set("ModularFate","run_once", true);
console.log(game.i18n.localize("ModularFate.baseDefaults"));
game.settings.set("ModularFate","defaults",game.i18n.localize("ModularFate.baseDefaults"))
}
}
})
// Needed to update with token name changes in FU.
Hooks.on('updateToken', (token, data, userId) => {
if (data.hidden != undefined || data.actorData != undefined || data.flags != undefined || data.name!=undefined){
game.system.apps["actor"].forEach(a=> {
a.renderMe(token.id, data, token);
})
}
})
Hooks.on('controlToken', (token, control) => {
game.system.apps["actor"].forEach (a=> {
a.renderMe("controlToken",token.id, control);
})
})
Hooks.on('updateUser',(...args) =>{
game.system.apps["user"].forEach (a=> {
a.renderMe("updateUser");
})
})
Hooks.on('renderPlayerList',(...args) =>{
game.system.apps["user"].forEach (a=> {
a.renderMe("updateUser");
})
})
Hooks.on('updateActor', (actor, data) => {
game.system.apps["actor"].forEach(a=> {
a.renderMe(actor.id, data, actor);
})
})
Hooks.on('updateItem', (item, data) => {
game.system.apps["item"].forEach(a=> {
a.renderMe(item.id, data, item);
})
})
Hooks.on('renderCombatTracker', () => {
game.system.apps["combat"].forEach(a=> {
a.renderMe("renderCombatTracker");
})
})
Hooks.on('updateCombat', (...args) => {
let ags = args;
game.system.apps["combat"].forEach(a=> {
a.renderMe(ags);
})
})
Hooks.on('deleteCombat', (...args) => {
game.system.apps["combat"].forEach(a=> {
a.renderMe("deleteCombat");
})
})
Hooks.on('deleteToken', (...args) => {
game.system.apps["actor"].forEach(a=> {
a.renderMe("deleteToken")
})
})
Hooks.on('createToken', (...args) => {
game.system.apps["actor"].forEach(a=> {
a.renderMe("createToken");
})
})
Hooks.on('updateScene', (...args) => {
game.system.apps["combat"].forEach(a=> {
a.renderMe(args);
})
})
Hooks.once('init', async function () {
CONFIG.Actor.documentClass = ModularFateActor;
CONFIG.Item.documentClass = ModularFateExtra;
CONFIG.fontFamilies.push("Montserrat");
// Register a setting for replacing the existing skill list with one of the pre-defined default sets.
game.settings.register("ModularFate", "defaultSkills", {
name: game.i18n.localize("ModularFate.ReplaceSkills"),
hint: game.i18n.localize("ModularFate.ReplaceSkillsHint"),
scope: "world", // This specifies a client-stored setting
config: true, // This specifies that the setting appears in the configuration view
type: String,
restricted:true,
choices: { // If choices are defined, the resulting setting will be a select menu
"nothing":game.i18n.localize("ModularFate.No"),
"fateCore":game.i18n.localize("ModularFate.YesFateCore"),
"fateCondensed":game.i18n.localize("ModularFate.YesFateCondensed"),
"accelerated":game.i18n.localize("ModularFate.YesFateAccelerated"),
"dfa":game.i18n.localize("ModularFate.YesDFA"),
"clearAll":game.i18n.localize("ModularFate.YesClearAll")
},
default: "nothing", // The default value for the setting
onChange: value => { // A callback function which triggers when the setting is changed
if (value == "fateCore"){
if (game.user.isGM){
game.settings.set("ModularFate","skills",game.i18n.localize("ModularFate.FateCoreDefaultSkills"));
game.settings.set("ModularFate","defaultSkills","nothing");
game.settings.set("ModularFate","skillsLabel",game.i18n.localize("ModularFate.defaultSkillsLabel"));
}
}
if (value=="clearAll"){
if (game.user.isGM) {
game.settings.set("ModularFate","skills",{});
game.settings.set("ModularFate","skillsLabel",game.i18n.localize("ModularFate.defaultSkillsLabel"));
}
}
if (value=="fateCondensed"){
if (game.user.isGM){
game.settings.set("ModularFate","skills",game.i18n.localize("ModularFate.FateCondensedDefaultSkills"));
game.settings.set("ModularFate","defaultSkills","nothing");
game.settings.set("ModularFate","skillsLabel",game.i18n.localize("ModularFate.defaultSkillsLabel"));
}
}
if (value=="accelerated"){
if (game.user.isGM){
game.settings.set("ModularFate","skills",game.i18n.localize("ModularFate.FateAcceleratedDefaultSkills"));
game.settings.set("ModularFate","defaultSkills","nothing");
game.settings.set("ModularFate","skillsLabel",game.i18n.localize("ModularFate.FateAcceleratedSkillsLabel"));
}
}
if (value=="dfa"){
if (game.user.isGM){
game.settings.set("ModularFate","skills",game.i18n.localize("ModularFate.DresdenFilesAcceleratedDefaultSkills"));
game.settings.set("ModularFate","defaultSkills","nothing");
game.settings.set("ModularFate","skillsLabel",game.i18n.localize("ModularFate.FateAcceleratedSkillsLabel"));
}
}
}
});
// Register a setting for replacing the existing aspect list with one of the pre-defined default sets.
game.settings.register("ModularFate", "defaultAspects", {
name: game.i18n.localize("ModularFate.ReplaceAspectsName"),
hint: game.i18n.localize("ModularFate.ReplaceAspectsHint"),
scope: "world", // This specifies a client-stored setting
config: true, // This specifies that the setting appears in the configuration view
type: String,
restricted:true,
choices: { // If choices are defined, the resulting setting will be a select menu
"nothing":game.i18n.localize("No"),
"fateCore":game.i18n.localize("ModularFate.YesFateCore"),
"fateCondensed":game.i18n.localize("ModularFate.YesFateCondensed"),
"accelerated":game.i18n.localize("ModularFate.YesFateAccelerated"),
"dfa":game.i18n.localize("ModularFate.YesDFA"),
"clearAll":game.i18n.localize("ModularFate.YesClearAll")
},
default: "nothing", // The default value for the setting
onChange: value => { // A callback function which triggers when the setting is changed
if (value == "fateCore"){
if (game.user.isGM){
game.settings.set("ModularFate","aspects",game.i18n.localize("ModularFate.FateCoreDefaultAspects"));
game.settings.set("ModularFate","defaultAspects","nothing");
}
}
if (value == "fateCondensed"){
if (game.user.isGM){
game.settings.set("ModularFate","aspects",game.i18n.localize("ModularFate.FateCondensedDefaultAspects"));
game.settings.set("ModularFate","defaultAspects","nothing");
}
}
if (value=="clearAll"){
if (game.user.isGM){
game.settings.set("ModularFate","aspects",{});
game.settings.set("ModularFate","defaultAspects","nothing");
}
}
if (value=="accelerated"){
if (game.user.isGM){
game.settings.set("ModularFate","aspects",game.i18n.localize("ModularFate.FateAcceleratedDefaultAspects"));
game.settings.set("ModularFate","defaultAspects","nothing");
}
}
if (value=="dfa"){
if (game.user.isGM){
game.settings.set("ModularFate","aspects",game.i18n.localize("ModularFate.DresdenFilesAcceleratedDefaultAspects"));
game.settings.set("ModularFate","defaultAspects","nothing");
}
}
}
});
// Register a setting for replacing the existing track list with one of the pre-defined default sets.
game.settings.register("ModularFate", "defaultTracks", {
name: game.i18n.localize("ModularFate.ReplaceTracksName"),
hint: game.i18n.localize("ModularFate.ReplaceTracksHint"),
scope: "world", // This specifies a client-stored setting
config: true, // This specifies that the setting appears in the configuration view
type: String,
restricted:true,
choices: { // If choices are defined, the resulting setting will be a select menu
"nothing":game.i18n.localize("ModularFate.No"),
"fateCore":game.i18n.localize("ModularFate.YesFateCore"),
"fateCondensed":game.i18n.localize("ModularFate.YesFateCondensed"),
"accelerated":game.i18n.localize("ModularFate.YesFateAccelerated"),
"dfa":game.i18n.localize("ModularFate.YesDFA"),
"clearAll":game.i18n.localize("ModularFate.YesClearAll")
},
default: "nothing", // The default value for the setting
onChange: value => { // A callback function which triggers when the setting is changed
if (value == "fateCore"){
if (game.user.isGM){
game.settings.set("ModularFate","tracks",game.i18n.localize("ModularFate.FateCoreDefaultTracks"));
game.settings.set("ModularFate","defaultTracks","nothing");
}
}
if (value=="clearAll"){
if (game.user.isGM){
game.settings.set("ModularFate","tracks",{});
game.settings.set("ModularFate","defaultTracks","nothing");
}
}
if (value=="fateCondensed"){
if (game.user.isGM){
game.settings.set("ModularFate","tracks",game.i18n.localize("ModularFate.FateCondensedDefaultTracks"));
game.settings.set("ModularFate","defaultTracks","nothing");
}
}
if (value=="accelerated"){
if (game.user.isGM){
game.settings.set("ModularFate","tracks",game.i18n.localize("ModularFate.FateAcceleratedDefaultTracks"));
game.settings.set("ModularFate","defaultTracks","nothing");
}
}
if (value == "dfa"){
if (game.user.isGM){
game.settings.set("ModularFate","tracks",game.i18n.localize("ModularFate.DresdenFilesAcceleratedDefaultTracks"));
game.settings.set("ModularFate","track_categories",game.i18n.localize("ModularFate.DresdenFilesAcceleratedDefaultTrackCategories"));
game.settings.set("ModularFate","defaultTracks","nothing");
}
}
}
});
game.settings.register("ModularFate","exportSettings", {
name: game.i18n.localize("ModularFate.ExportSettingsName"),
scope:"world",
config:true,
type:Boolean,
restricted:true,
default:false,
onChange: value => {
if (value == true && game.user.isGM){
let text = ModularFateConstants.exportSettings();
new Dialog({
title: game.i18n.localize("ModularFate.ExportSettingsDialogTitle"),
content: `<div style="background-color:white; color:black;"><textarea rows="20" style="font-family:Montserrat; width:382px; background-color:white; border:1px solid lightsteelblue; color:black;" id="export_settings">${text}</textarea></div>`,
buttons: {
},
}).render(true);
game.settings.set("ModularFate","exportSettings",false);
}
}
})
game.settings.register("ModularFate","importSettings", {
name: game.i18n.localize("ModularFate.ImportSettingsName"),
scope:"world",
hint:game.i18n.localize("ModularFate.ImportSettingsHint"),
config:true,
type:Boolean,
restricted:true,
default:false,
onChange: async value => {
if (value == true && game.user.isGM){
let text = await ModularFateConstants.getSettings();
ModularFateConstants.importSettings(text);
game.settings.set("ModularFate","importSettings",false);
}
}
})
//Register a setting for the game's current Refresh total
game.settings.register("ModularFate", "refreshTotal", {
name: game.i18n.localize("ModularFate.RefreshTotalName"),
hint: game.i18n.localize("ModularFate.RefreshTotalHint"),
scope: "world",
config: true,
type: Number,
default:3,
onChange: () =>{
for (let app in ui.windows){
if (ui.windows[app]?.object?.type == "Thing" || ui.windows[app]?.object?.type == "ModularFate"){
ui.windows[app]?.render(false);
}
}
}
});
game.settings.register("ModularFate","freeStunts", {
name:game.i18n.localize("ModularFate.FreeStunts"),
hint:game.i18n.localize("ModularFate.FreeStuntsHint"),
scope:"world",
config:true,
type:Number,
restricted:true,
default:3,
onChange: () =>{
for (let app in ui.windows){
if (ui.windows[app]?.object?.type == "Thing" || ui.windows[app]?.object?.type == "ModularFate"){
ui.windows[app]?.render(false);
}
}
}
})
//Register a setting for the game's current skill total
game.settings.register("ModularFate", "skillTotal", {
name: game.i18n.localize("ModularFate.SkillPointTotal"),
hint: game.i18n.localize("ModularFate.SkillPointTotalHint"),
scope: "world",
config: true,
type: Number,
restricted:true,
default:20,
onChange: () =>{
for (let app in ui.windows){
if (ui.windows[app]?.object?.type == "Thing" || ui.windows[app]?.object?.type == "ModularFate"){
ui.windows[app]?.render(false);
}
}
}
});
game.settings.register("ModularFate","enforceSkillTotal", {
name: game.i18n.localize("ModularFate.EnforceSkillTotal"),
hint: game.i18n.localize("ModularFate.EnforceSkillTotalHint"),
scope:"world",
config:true,
type: Boolean,
restricted:true,
default:true,
onChange: () =>{
for (let app in ui.windows){
if (ui.windows[app]?.object?.type == "Thing" || ui.windows[app]?.object?.type == "ModularFate"){
ui.windows[app]?.render(false);
}
}
}
})
game.settings.register("ModularFate","enforceColumn", {
name: game.i18n.localize("ModularFate.EnforceColumn"),
hint: game.i18n.localize("ModularFate.EnforceColumnHint"),
scope:"world",
config:true,
type: Boolean,
restricted:true,
default:true,
onChange: () =>{
for (let app in ui.windows){
if (ui.windows[app]?.object?.type == "Thing" || ui.windows[app]?.object?.type == "ModularFate"){
ui.windows[app]?.render(false);
}
}
}
})
let skill_choices = {};
let skills = game.settings.get("ModularFate", "skills")
skill_choices["None"]="None";
skill_choices["Disable"]="Disable";
for (let skill in skills){skill_choices[skill]=skill};
game.settings.register("ModularFate","init_skill", {
name:game.i18n.localize("ModularFate.initiativeSkill"),
hint:game.i18n.localize("ModularFate.initiativeSetting"),
"scope":"world",
"config":true,
"restricted":true,
type:String,
default:"None",
choices:skill_choices
})
game.settings.register("ModularFate","modifiedRollDefault", {
name:game.i18n.localize("ModularFate.modifiedRollDefault"),
hint:game.i18n.localize("ModularFate.modifiedRollDefaultExplainer"),
scope:"world",
config:"true",
type:Boolean,
default:false
})
game.settings.register("ModularFate","sheet_template", {
name:game.i18n.localize("ModularFate.DefaultSheetTemplateName"),
hint:game.i18n.localize("ModularFate.DefaultSheetTemplateHint"),
scope:"world",
config:"true",
type:String,
default:'systems/ModularFate/templates/ModularFateSheet.html'
})
game.settings.register("ModularFate","limited_sheet_template", {
name:game.i18n.localize("ModularFate.DefaultLimitedSheetTemplateName"),
hint:game.i18n.localize("ModularFate.DefaultLimitedSheetTemplateHint"),
scope:"world",
config:"true",
type:String,
default:'systems/ModularFate/templates/ModularFateSheet.html'
})
game.settings.register ("ModularFate","PlayerThings", {
name:game.i18n.localize("ModularFate.AllowPlayerThingCreation"),
label:game.i18n.localize("ModularFate.ThingCreationLabel"),
hint:game.i18n.localize("ModularFate.ThingCreationHint"),
type:Boolean,
scope:"world",
config:true,
restricted:true,
default:true
});
game.settings.register ("ModularFate","DeleteOnTransfer", {
name:game.i18n.localize("ModularFate.DeleteOnTransfer"),
label:game.i18n.localize("ModularFate.DeleteOnTransferLabel"),
hint:game.i18n.localize("ModularFate.DeleteOnTransferHint"),
type:Boolean,
scope:"world",
config:true,
restricted:true,
default:true
});
game.settings.register("ModularFate","confirmDeletion", {
name: game.i18n.localize("ModularFate.ConfirmDeletionName"),
hint:game.i18n.localize("ModularFate.ConfirmDeletionHint"),
scope:"user",
config:true,
type:Boolean,
restricted:false,
default:false
});
game.settings.register("ModularFate","drawingsOnTop", {
name:game.i18n.localize("ModularFate.DrawingsOnTop"),
hint:game.i18n.localize("ModularFate.DrawingsOnTopHint"),
scope:"world",
config:"true",
type:Boolean,
default:false
})
game.settings.register("ModularFate","fu_actor_avatars", {
name:"Use actor avatars instead of token avatars in Fate Utilities?",
hint:"Whether to use actor avatars instead of token avatars in Fate Utilities' aspect viewer",
scope:"world",
config:false,
default:false,
type:Boolean
})
game.settings.register("ModularFate","fu_combatants_only", {
name:"Display information only for combatants in the current 'encounter' rather than all tokens?",
hint:"Toggle between display of all tokens or just active combatants in Fate Utilities",
scope:"user",
config:false,
default:false,
type:Boolean
})
game.settings.register("ModularFate", "run_once", {
name: "Run Once?",
hint:"Pops up a brief tutorial message on first load of a world with this system",
scope:"world",
config:false,
type: Boolean,
default:false
})
game.system.entityTypes.Item = ["Extra"];
game.system.entityTypes.Actor = ["ModularFate","Thing"]
game.system.apps= {
actor:[],
combat:[],
scene:[],
user:[],
item:[]
}
//On init, we initialise any settings and settings menus and HUD overrides as required.
Actors.unregisterSheet('core', ActorSheet);
Actors.registerSheet("ModularFate", ModularFateCharacter, { types: ["ModularFate"], makeDefault: true, label:game.i18n.localize("ModularFate.ModularFateCharacter") });
Actors.registerSheet("Thing" , Thing, {types: ["Thing"], label:game.i18n.localize("ModularFate.Thing")});
// Register Item sheets
Items.registerSheet('fate', ExtraSheet, { types: ['Extra'] });
game.settings.register("ModularFate", "gameTime", {
name: game.i18n.localize("ModularFate.GameTime"),
scope:"world",
config:false,
type:String,
restricted:true,
default:""
})
game.settings.register("ModularFate", "gameNotes", {
name: game.i18n.localize("ModularFate.GameNotes"),
scope:"world",
config:false,
type:String,
restricted:true,
default:""
})
game.settings.register("ModularFate", "gameAspects", {
name: game.i18n.localize("ModularFate.GameTime"),
scope:"world",
config:false,
type:Object,
restricted:true,
default:[]
})
game.settings.register("ModularFate", "fuFontSize", {
name: "Fate Utilities Font Size",
scope:"user",
config:false,
type:Number,
restricted:false,
default:10 //Size in points (pt)
})
game.settings.register("ModularFate", "aspectwidth", {
name: game.i18n.localize("ModularFate.aspectWidth"),
hint: game.i18n.localize("ModularFate.AspectLabelWidth"),
scope: "world",
config: true,
type: Number,
range: {
min: 5,
max: 50,
step: 1,
},
default:12
});
game.settings.register("ModularFate", "fuAspectLabelSize", {
name: game.i18n.localize("ModularFate.fuAspectLabelSizeName"),
hint:game.i18n.localize("ModularFate.fuAspectLabelSizeHint"),
scope:"world",
config:false,
type:Number,
restricted:true,
default:0
})
game.settings.register("ModularFate","fuAspectLabelFont", {
name: game.i18n.localize("ModularFate.fuAspectLabelFont"),
hint:game.i18n.localize("ModularFate.fuAspectLabelFontHint"),
scope:"world",
config:false,
type:String,
restricted:true,
choices:CONFIG.fontFamilies,
default:"Montserrat",
})
// Text colour
game.settings.register("ModularFate","fuAspectLabelTextColour", {
name: game.i18n.localize("ModularFate.fuAspectLabelTextColour"),
hint:game.i18n.localize("ModularFate.fuAspectLabelTextColourHint"),
scope:"world",
config:false,
type:String,
restricted:true,
default:"#000000",
})
//BG Colour
game.settings.register("ModularFate","fuAspectLabelFillColour", {
name: game.i18n.localize("ModularFate.fuAspectLabelFillColour"),
hint:game.i18n.localize("ModularFate.fuAspectLabelFillColourHint"),
scope:"world",
config:false,
restricted:true,
type:String,
restricted:true,
default:"#FFFFFF"
})
// Border colour
game.settings.register("ModularFate","fuAspectLabelBorderColour", {
name: game.i18n.localize("ModularFate.fuAspectLabelBorderColour"),
hint:game.i18n.localize("ModularFate.fuAspectLabelBorderColourHint"),
scope:"world",
config:false,
restricted:true,
type:String,
restricted:true,
default:"#000000"
})
});
Combatant.prototype._getInitiativeFormula = function () {
let init_skill = game.settings.get("ModularFate","init_skill");
if (init_skill === "None" || init_skill === "Disable") {
return "1d0";
}else {
return `1d0+${this.actor.data.data.skills[init_skill].rank}`;
}
}
// Custom drawings layer with different z index
class CustomDrawingsLayer extends DrawingsLayer {
static get layerOptions() {
const options = super.layerOptions;
options.zIndex = 350;
return options;
}
}
Hooks.on("init", () => {
if (game.settings.get ("ModularFate", "drawingsOnTop")){
// Force Canvas to use the new DrawingsLayer
const existingLayers = Canvas.layers;
existingLayers.drawings = CustomDrawingsLayer;
Object.defineProperty(Canvas, "layers", { get: () => existingLayers });
}
});
Hooks.on("getSceneControlButtons", (controls) => {
if (game.settings.get ("ModularFate", "drawingsOnTop")){
controls.find(c => c.name === "drawings").layer = "CustomDrawingsLayer";
}
})
Handlebars.registerHelper("add1", function(value) {
return value+1;
});
Handlebars.registerHelper("add5", function(value) {
return value+5;
})
Handlebars.registerHelper("str", function(value) {
return JSON.stringify(value);
});
Handlebars.registerHelper("concat", function(value1, value2){
return value1.concat(value2);
});
Handlebars.registerHelper("category", function(category1, category2) {
if (category1 == "All" || category1 == category2){
return true;
} else {
return false;
}
})
Handlebars.registerHelper("undefined", function(value) {
if (value == undefined){
return true;
} else {
return false;
}
});
Handlebars.registerHelper("expanded", function (actor, item){
let key;
if (actor == "game"){
key = "game"+item;
} else {
key = actor.id + item;
}
if (game.user.expanded != undefined){
return game.user.expanded[key]==true;
} else {
return false;
}
});
Handlebars.registerHelper("hasBoxes", function(track) {
if(track.box_values==undefined || track.box_values.length==0){
return false;
} else {
return true;
}
});