-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfco.js
1930 lines (1727 loc) · 76.2 KB
/
fco.js
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
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* 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 { fcoCharacter } from "./scripts/fcoCharacter.js"
import { ExtraSheet } from "./scripts/ExtraSheet.js"
import { Thing } from "./scripts/Thing.js"
import { fcoActor } from "./scripts/fcoActor.js"
import { fcoExtra } from "./scripts/fcoExtra.js"
// The following hooks append the Fate Core Official settings to an Adventure document's flags so that they can be loaded/set on import of the adventure module.
Hooks.on("preCreateAdventure", (adventure, ...args) =>{
let flags = foundry.utils.duplicate(adventure.flags);
let fco_settings = JSON.parse(fcoConstants.exportSettings());
if (!flags["fate-core-official"]) flags["fate-core-official"] = {};
flags["fate-core-official"].settings = fco_settings;
adventure.updateSource({"flags":flags});
})
Hooks.on("preUpdateAdventure", (adventure, changes, options, userId) =>{
let flags = foundry.utils.duplicate(adventure.flags);
let fco_settings = JSON.parse(fcoConstants.exportSettings());
if (!flags["fate-core-official"]) flags["fate-core-official"] = {};
flags["fate-core-official"].settings = fco_settings;
changes.flags = flags;
})
// We can mess around with the data in the preImportAdventure hook to do what we need to it, if it's not quite in the right condition.
// This next piece of code is unnecessary if the user is running Foundry 10.286 or higher. In previous versions of Foundry, this was needed
// to change the order of import from scenes then journals to journals then scenes, required to prevent bookmarks on the canvas from being 'unknown'.
if (!foundry.utils.isNewerVersion(game.version, "10.285")){
Hooks.on("preImportAdventure", (adventure, formData, toCreate, toUpdate) => {
// const allowed = Hooks.call("preImportAdventure", this.adventure, formData, toCreate, toUpdate);
let cScene = toCreate?.Scene;
let uScene = toUpdate?.Scene;
if (uScene){
delete toUpdate.Scene;
toUpdate.Scene = uScene;
}
if (cScene){
delete toCreate.Scene;
toCreate.Scene = cScene;
}
adventure.updateSource({toCreate:toCreate, toUpdate:toUpdate});
})
}
Hooks.on("importAdventure", async (adventure, formData, created, updated) =>{
let replace = false;
let flags = foundry.utils.duplicate(adventure.flags);
let settings = flags["fate-core-official"]?.settings;
if (settings && !formData.overrideSettings){
const confirm = await Dialog.confirm({
title: game.i18n.localize("fate-core-official.overrideSettingsTitle"),
content: `<p>${game.i18n.localize("fate-core-official.overrideSettings")} <strong>${adventure.name}</strong></p>`
});
if ( confirm ) replace = true;
} else {
if (settings && formData.overrideSettings) replace = true;
}
if (replace){
if (settings) fcoConstants.importSettings(settings);
}
})
Hooks.on("preCreateActor", (actor, data, options, userId) => {
if (actor.type == "Thing"){
if (!options.thing){
ui.notifications.error(game.i18n.localize("fate-core-official.CantCreateThing"));
return false
}
}
});
Hooks.on("renderSettingsConfig", (app, html) => {
const input = html[0].querySelector("[name='fate-core-official.fco-font-family']");
input.remove(0);
FontConfig.getAvailableFonts().forEach(font => {
const option = document.createElement("option");
option.value = font;
option.text = font;
input.add(option);
});
let options = input.getElementsByTagName('option');
let current = game.settings.get("fate-core-official","fco-font-family");
for (let option of options) if (option.value == current) option.selected = 'selected'
});
async function setupSheet(){
let scheme = await game.user.getFlag("fate-core-official","current-sheet-scheme");
if (!scheme) scheme = game.settings.get("fate-core-official","fco-world-sheet-scheme");
// Setup the character sheet according to the user's settings
let val = scheme.fco_aspects_panel_height;
document.documentElement.style.setProperty('--fco-aspects-pane-mheight', `${val}%`);
document.documentElement.style.setProperty('--fco-stunts-pane-mheight', `${100-val}%`);
val = scheme.fco_skills_panel_height;
document.documentElement.style.setProperty('--fco-skills-pane-mheight', `${val}%`);
document.documentElement.style.setProperty('--fco-tracks-pane-mheight', `${100-val}%`);
if (scheme.use_notched) {
document.documentElement.style.setProperty('--fco-header-notch', "polygon(0% 10px, 10px 0%, 100% 0%, 100% 0px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0px 100%, 0 calc(100% - 20px))");
document.documentElement.style.setProperty('--fco-border-radius', "0px");
} else {
document.documentElement.style.setProperty('--fco-header-notch', "polygon(0% 0px, 0px 0%, 100% 0%, 100% 0px, 100% 100%, 100% 100%, 0px 100%, 0 100%)");
document.documentElement.style.setProperty('--fco-border-radius', "15px");
}
val = scheme.sheet_header_colour;
document.documentElement.style.setProperty('--fco-header-colour', `${val}`);
val = scheme.sheet_accent_colour;
document.documentElement.style.setProperty('--fco-accent-colour', `${val}`);
val = scheme.sheet_label_colour;
document.documentElement.style.setProperty('--fco-label-colour', `${val}`);
val = scheme.backgroundColour;
document.documentElement.style.setProperty('--fco-sheet-background-colour', `${val}`);
val = scheme.inputColour;
document.documentElement.style.setProperty('--fco-sheet-input-colour', `${val}`);
val = scheme.textColour;
document.documentElement.style.setProperty('--fco-sheet-text-colour', `${val}`);
val = scheme.interactableColour;
document.documentElement.style.setProperty('--fco-foundry-interactable-color', `${val}`);
// Re-render to make sure the logo is updated correctly.
for (let window in ui.windows){
if (ui.windows[window].constructor.name == "fcoCharacter"){
ui.windows[window].render(false);
}
}
}
function setupFont(){
// Setup the system font according to the user's settings
let val = game.settings.get("fate-core-official","fco-font-family");
if (FontConfig.getAvailableFonts().indexOf(val) == -1){
// What we have here is a numerical value (or font not found in config list; nothing we can do about that).
val = FontConfig.getAvailableFonts()[game.settings.get("fate-core-official","fco-font-family")]
}
let override = game.settings.get("fate-core-official", "override-foundry-font");
if (override) {
document.documentElement.style.setProperty('--fco-foundry-font-family', "")
document.documentElement.style.setProperty('--fco-font-family', `${val}`);
} else {
document.documentElement.style.setProperty('--fco-font-family', `${val}`);
document.documentElement.style.setProperty('--fco-foundry-font-family', `${val}`);
}
}
function rationaliseKeys(){
let types = ["stunts","aspects","tracks","skills"];
for (let type of types){
let data = game.settings.get("fate-core-official", type);
let export_data = {};
for (let sub_item in data){
let key = fcoConstants.tob64(data[sub_item].name);
export_data[key] = data[sub_item];
}
let oldKeys = JSON.stringify(Object.keys(data));
let newKeys = JSON.stringify(Object.keys(export_data));
if (newKeys != oldKeys) {
game.settings.set("fate-core-official", type, export_data);
}
}
}
Hooks.once('ready', () => {
game.system["fco-shifted"]=false;
// Set up a reference to the Fate Core Official translations file or fallback file.
if (game.i18n?.translations["fate-core-official"]) {
game.system["lang"] = game.i18n.translations["fate-core-official"];
} else {
game.system["lang"] = game.i18n._fallback["fate-core-official"];
}
setupSheet();
setupFont();
if (game.user == game.users.activeGM){
rationaliseKeys();
game.actors.contents.forEach(async actor => await actor.rationaliseKeys());
game.items.contents.forEach(async extra => await extra.rationaliseKeys());
}
});
if (!foundry.utils.isNewerVersion(game.version, "12.316")){
Hooks.on('createDrawing', (drawing) => {
if (game.settings.get("fate-core-official","drawingsOnTop")){
if (drawing.isOwner){
if (foundry.utils.isNewerVersion(game.version, 12)){
} else {
const siblings = canvas.drawings.placeables;
// Determine target sort index
let z = 0;
let up = true;
let controlled = [drawing];
if ( up ) {
controlled.sort((a, b) => a.document.z - b.document.z);
z = siblings.length ? Math.max(...siblings.map(o => o.document.z)) + 1 : 1;
} else {
controlled.sort((a, b) => b.document.z - a.document.z);
z = siblings.length ? Math.min(...siblings.map(o => o.document.z)) - 1 : -1;
}
// Update all controlled objects
const updates = controlled.map((o, i) => {
let d = up ? i : i * -1;
return {_id: o.id, z: z + d};
});
return canvas.scene.updateEmbeddedDocuments("Drawing", updates);
}
}
}
})
}
Hooks.on('diceSoNiceReady', function() {
game.dice3d.addSFXTrigger("fate4df", "Fate Roll", ["-4","-3","-2","-1","0","1","2","3","4"]);
})
Hooks.once('ready', async function () {
//Convert any straggling ModularFate actors to fate-core-official actors.
let updates = [];
game.actors.contents.forEach(actor => {
if (actor.type == "ModularFate" || actor.type == "FateCoreOfficial") updates.push({_id:actor.id, type:"fate-core-official"})
});
if (game.user == game.users.activeGM) await Actor.updateDocuments(updates)
// We need to port any and all settings over from ModularFate/Fate Core Official and any or all flags.
//First, settings.
const systemSettings = [];
try {
for ( let s of game.data.settings ) {
if ( s.key.startsWith("ModularFate.") ) {
systemSettings.push({_id: s._id, key: s.key.replace("ModularFate.", "fate-core-official.")});
}
if ( s.key.startsWith("FateCoreOfficial.") ) {
systemSettings.push({_id: s._id, key: s.key.replace("FateCoreOfficial.", "fate-core-official.")});
}
}
if (game.user == game.users.activeGM) await Setting.updateDocuments(systemSettings);
}
catch (error){
//Do nothing, just don't stop what you're doing!
}
// Now flags, let us write a convenience function
async function changeFlags(doc){
let flags1 = doc.flags["ModularFate"];
let flags2 = doc.flags["FateCoreOfficial"];
if ( flags1 ) {
await doc.update({"flags.fate-core-official": flags1}, {recursive: false});
await doc.update({"flags.-=ModularFate": null});
}
if ( flags2 ) {
await doc.update({"flags.fate-core-official": flags2}, {recursive: false});
await doc.update({"flags.-=FateCoreOfficial": null});
}
}
// Users
for (let doc of game.users){
if (game.user == game.users.activeGM) await changeFlags(doc);
}
// Actors
for (let doc of game.actors){
if (game.user == game.users.activeGM) await changeFlags(doc);
}
// Scenes & Token actors
for (let doc of game.scenes){
if (game.user == game.users.activeGM) await changeFlags(doc);
for (let tok of doc.tokens){
if (game.user == game.users.activeGM) await changeFlags(tok);
}
}
// Combats & combatants
for (let doc of game.combats) {
if (game.user == game.users.activeGM) await changeFlags (doc);
for (let com of doc.combatants){
if (game.user == game.users.activeGM) await changeFlags (com);
}
}
// The code for initialising a new world with the content of a module pack goes here.
// The fallback position is to display a similar message to the existing one.
if (game.settings.get("fate-core-official","run_once") == false && game.user.isGM){
const ehmodules = [];
game.modules.forEach(m => {
if (m?.flags?.ehproduct == "Fate Core Adventure"){
ehmodules.push(m);
}
})
class fate_splash extends FormApplication {
constructor(...args){
super(...args);
}
static get defaultOptions (){
let h = window.innerHeight;
let w = window.innerWidth;
let options = super.defaultOptions;
options.template = "systems/fate-core-official/templates/fate-splash.html"
options.width = w/2+15;
options.height = h-50;
options.title = "New World Setup"
return options;
}
activateListeners(html){
super.activateListeners(html);
const cont = html.find('button[id="fco_continue_button"]');
cont.on('click', async event => {
await game.settings.set("fate-core-official","run_once",true);
await game.settings.set("fate-core-official","defaults",game.system["lang"]["baseDefaults"])
await ui.sidebar.render(false);
this.close();
})
const install = html.find('button[name="eh_install"]');
install.on('click', async event => {
let module = event.target.id.split("_")[1];
game.settings.set("fate-core-official", "installing", module);
// Now to activate the module, which should kick off a refresh, allowing the installation to begin.
// As of v10 it does not trigger a refresh, so we need to do it manually; let's use the debounceReload() function.
let mc = game.settings.get("core","moduleConfiguration");
if (mc[module] == true) {
this.installModule(module);
this.close();
}
else {
mc[module]=true;
await game.settings.set("core", "moduleConfiguration", mc);
foundry.utils.debouncedReload();
}
})
}
async getData(){
let data = super.getData();
data.ehmodules = foundry.utils.duplicate(ehmodules);
for (let ehm of data.ehmodules){
ehm.richDesc = await fcoConstants.fcoEnrich(ehm.description);
}
data.num_modules = ehmodules.length;
data.h = window.innerHeight /2;
data.w = window.innerWidth /2;
data.mh = data.h/1.1;
return data;
}
async installModule(module_name){
/*
The core system now has code to export settings on creating an adventure as flags on the adventure, and to re-import them
from flags on import of the module.
*/
// Grab the adventure pack and import it.
// The compendium must be called 'content'
// All 'adventures' in this compendium will be imported. This would allow us to segregate content on occasion, for example
// allowing scenes and characters to be imported separately from the journal entries forming the text of the book.
// When imported using the fate_splash installer, the settings from each adventure will be imported automatically, each overwriting the last.
let pack = await game.packs.get(`${module_name}.content`);
await pack.getDocuments();
//Todo: Consider whether we want to restrict to installing just the first adventure in the pack, allowing others to be for characters, etc.
for (let p of pack.contents){
await p.sheet._updateObject({}, {"overrideSettings":true})
}
// Set installing and run_once to the appropriate post-install values
await game.settings.set("fate-core-official", "run_once", true);
await game.settings.set("fate-core-official", "installing", "none");
//Set this game's image to the world's default
await fetch(foundry.utils.getRoute("setup"), {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: "editWorld",
background: `modules/${module_name}/art/world.webp`, title:game.world.title, id:game.world.id, nextSession:null
})
});
game.folders.forEach (folder => game.folders._expanded[folder.id] = true);
ui.sidebar.render(true);
}
}
if (game.user.isGM){
if (game.settings.get("fate-core-official","installing") === "none") {
let f = new fate_splash().render(true);
} else {
new fate_splash().installModule(game.settings.get("fate-core-official","installing"));
}
}
}
})
// Needed to update with token name changes in FU.
Hooks.on('updateToken', (token, data, userId) => {
let check = false;
if (foundry.utils.isNewerVersion(game.version, "11.293")){
if (data.hidden != undefined || data.delta != undefined || data.flags != undefined || data.name!=undefined) check = true;
}
else {
if (data.hidden != undefined || data.actorData != undefined || data.flags != undefined || data.name!=undefined) check = true;
}
if (check){
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.on('getSceneControlButtons', function(hudButtons)
{
let hud = hudButtons.find(val => {return val.name == "token";})
if (hud && game.user.isGM){
hud.tools.push({
name:"StuntDB",
title:game.i18n.localize("fate-core-official.ViewTheStuntDatabase"),
icon:"fas fa-book",
onClick: ()=> {let sd = new StuntDB("none"); sd.render(true)},
button:true
});
}
})
// This next hook is required to prevent Things from showing up in the player configuration menu.
Hooks.on('renderUserConfig', (user, html, data) => {
let actors = html.find("li");
for (let actor of actors){
let id = actor.getAttribute("data-actor-id");
if (game.actors.get(id).type == "Thing"){
actor.remove();
}
}
})
Hooks.once('init', async function () {
CONFIG.Actor.documentClass = fcoActor;
CONFIG.Item.documentClass = fcoExtra;
CONFIG.fontDefinitions["Fate"] = {
"editor": true,
"fonts": [{urls: [`systems/fate-core-official/fonts/Fate Core Font.ttf`]}]
}
CONFIG.fontDefinitions["Fate Core"] = {
"editor": true,
"fonts": [{urls: [`systems/fate-core-official/fonts/Fate Core Font.ttf`]}]
}
CONFIG.fontDefinitions["Jost"] = {
editor: true,
fonts: [
{urls: ["systems/fate-core-official/fonts/Jost-variable.ttf"]},
{urls: ["systems/fate-core-official/fonts/Jost-italic.ttf"], style: "italic"}
]
}
CONFIG.fontDefinitions["Montserrat"] = {
editor: true,
fonts: [
{urls:["systems/fate-core-official/fonts/Montserrat-Regular.otf"]},
{urls:["systems/fate-core-official/fonts/Montserrat-Italic.otf"], style:"italic"},
{urls:["systems/fate-core-official/fonts/Montserrat-Light.otf"], weight:300},
{urls:["systems/fate-core-official/fonts/Montserrat-LightItalic.otf"], style:"italic", weight:300},
{urls:["systems/fate-core-official/fonts/Montserrat-Bold.otf"], weight:"bold"},
{urls:["systems/fate-core-official/fonts/Montserrat-BoldItalic.otf"], style:"italic", weight:"bold"},
{urls:["systems/fate-core-official/fonts/Montserrat-Black.otf"], weight:900},
{urls:["systems/fate-core-official/fonts/Montserrat-BlackItalic.otf"], style:"italic", weight:900},
]
}
const includeRgx = new RegExp("/systems/fate-core-official/");
CONFIG.compatibility.includePatterns.push(includeRgx);
//Let's initialise the settings at the system level.
// ALL settings that might be relied upon later are now included here in order to prevent them from being unavailable later in the init hook.
if (foundry.utils.isNewerVersion(game.version, "9.230")){
let bindings = [
{
key: "SHIFT"
}
];
if (foundry.utils.isNewerVersion(game.version, "9.235")){
bindings = [
{
key: "ShiftLeft"
},
{
key: "ShiftRight"
}
];
}
game.keybindings.register("fate-core-official", "fcoInteractionModifier", {
name: "Fate Core Official modifier key for dragging and clicking",
editable: bindings,
onDown: (...args) => { game.system["fco-shifted"] = true;},
onUp: (...args) => { if (args[0].event.isTrusted == true) {game.system["fco-shifted"] = false;}}
})
}
game.settings.register("fate-core-official","tracks",{
name:"tracks",
hint:game.i18n.localize("fate-core-official.TrackManagerHint"),
scope:"world",
config:false,
type: Object,
default: {}
});
game.settings.register("fate-core-official","track_categories",{
name:"track categories",
hint:game.i18n.localize("fate-core-official.TrackCategoriesHint"),
scope:"world",
config:false,
type: Object,
default:{"Combat":"Combat","Other":"Other"}
});
// Register the menu to setup the world's conditions etc.
game.settings.registerMenu("fate-core-official", "TrackSetup", {
name: game.i18n.localize("fate-core-official.SetupTracks"),
label: game.i18n.localize("fate-core-official.Setup"), // The text label used in the button
hint: game.i18n.localize("fate-core-official.TrackSetupHint"),
type: TrackSetup, // A FormApplication subclass which should be created
restricted: true // Restrict this submenu to gamemaster only?
});
game.settings.register("fate-core-official", "aspects", {
name: "Aspects",
hint: "This is the list of aspects for this particular world.",
scope: "world",
config: false,
type: Object,
default:{}
});
// Register the menu to setup the world's aspect list.
game.settings.registerMenu("fate-core-official","AspectSetup", {
name:game.i18n.localize("fate-core-official.SetupAspects"),
label:game.i18n.localize("fate-core-official.Setup"),
hint:game.i18n.localize("fate-core-official.SetupAspectsHint"),
type:AspectSetup,
restricted:true
});
// Register a setting for replacing the existing skill list with one of the pre-defined default sets.
//On init, we initialise all settings and settings menus for dealing with skills
//We will be using this setting to store the world's list of skills.
game.settings.register("fate-core-official", "skills", {
name: "Skill list",
hint: "This is the list of skills for this particular world.",
scope: "world",
config: false,
type: Object,
default:{}
});
// Register a setting for storing character default templates
game.settings.register("fate-core-official", "defaults", {
name: "Character defaults",
hint: "Character defaults - sets of tracks, skills, stunts, etc. for ease of character creation for GMs.",
scope: "world",
config: false,
type: Object,
default:{}
});
game.settings.register("fate-core-official","stunts", {
name: "Stunts Database",
hint:"A list of approved stunts that can be added to characters",
scope:"world",
config:false,
type:Object,
default:{}
})
// Register the menu to setup the world's skill list.
game.settings.registerMenu("fate-core-official", "SkillSetup", {
name: game.i18n.localize("fate-core-official.SetupSkills"),
label: game.i18n.localize("fate-core-official.Setup"), // The text label used in the button
hint: game.i18n.localize("fate-core-official.SetupSkillsHint"),
type: SkillSetup, // A FormApplication subclass which should be created
restricted: true // Restrict this submenu to gamemaster only?
});
game.settings.register("fate-core-official", "defaultSkills", {
name: game.i18n.localize("fate-core-official.ReplaceSkills"),
hint: game.i18n.localize("fate-core-official.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,
requiresReload: true,
choices: { // If choices are defined, the resulting setting will be a select menu
"nothing":game.i18n.localize("fate-core-official.No"),
"fateCore":game.i18n.localize("fate-core-official.YesFateCore"),
"fateCondensed":game.i18n.localize("fate-core-official.YesFateCondensed"),
"accelerated":game.i18n.localize("fate-core-official.YesFateAccelerated"),
"dfa":game.i18n.localize("fate-core-official.YesDFA"),
"clearAll":game.i18n.localize("fate-core-official.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("fate-core-official","skills",game.system["lang"]["FateCoreDefaultSkills"]);
game.settings.set("fate-core-official","defaultSkills","nothing");
game.settings.set("fate-core-official","skillsLabel",game.i18n.localize("fate-core-official.defaultSkillsLabel"));
}
}
if (value=="clearAll"){
if (game.user.isGM) {
game.settings.set("fate-core-official","skills",{});
game.settings.set("fate-core-official","skillsLabel",game.i18n.localize("fate-core-official.defaultSkillsLabel"));
}
}
if (value=="fateCondensed"){
if (game.user.isGM){
game.settings.set("fate-core-official","skills",game.system["lang"]["FateCondensedDefaultSkills"]);
game.settings.set("fate-core-official","defaultSkills","nothing");
game.settings.set("fate-core-official","skillsLabel",game.i18n.localize("fate-core-official.defaultSkillsLabel"));
}
}
if (value=="accelerated"){
if (game.user.isGM){
game.settings.set("fate-core-official","skills",game.system["lang"]["FateAcceleratedDefaultSkills"]);
game.settings.set("fate-core-official","defaultSkills","nothing");
game.settings.set("fate-core-official","skillsLabel",game.i18n.localize("fate-core-official.FateAcceleratedSkillsLabel"));
}
}
if (value=="dfa"){
if (game.user.isGM){
game.settings.set("fate-core-official","skills",game.system["lang"]["DresdenFilesAcceleratedDefaultSkills"]);
game.settings.set("fate-core-official","defaultSkills","nothing");
game.settings.set("fate-core-official","skillsLabel",game.i18n.localize("fate-core-official.FateAcceleratedSkillsLabel"));
}
}
}
});
// Register a setting for replacing the existing aspect list with one of the pre-defined default sets.
game.settings.register("fate-core-official", "defaultAspects", {
name: game.i18n.localize("fate-core-official.ReplaceAspectsName"),
hint: game.i18n.localize("fate-core-official.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,
requiresReload: true,
choices: { // If choices are defined, the resulting setting will be a select menu
"nothing":game.i18n.localize("No"),
"fateCore":game.i18n.localize("fate-core-official.YesFateCore"),
"fateCondensed":game.i18n.localize("fate-core-official.YesFateCondensed"),
"accelerated":game.i18n.localize("fate-core-official.YesFateAccelerated"),
"dfa":game.i18n.localize("fate-core-official.YesDFA"),
"clearAll":game.i18n.localize("fate-core-official.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("fate-core-official","aspects",game.system["lang"]["FateCoreDefaultAspects"]);
game.settings.set("fate-core-official","defaultAspects","nothing");
}
}
if (value == "fateCondensed"){
if (game.user.isGM){
game.settings.set("fate-core-official","aspects",game.system["lang"]["FateCondensedDefaultAspects"]);
game.settings.set("fate-core-official","defaultAspects","nothing");
}
}
if (value=="clearAll"){
if (game.user.isGM){
game.settings.set("fate-core-official","aspects",{});
game.settings.set("fate-core-official","defaultAspects","nothing");
}
}
if (value=="accelerated"){
if (game.user.isGM){
game.settings.set("fate-core-official","aspects",game.system["lang"]["FateAcceleratedDefaultAspects"]);
game.settings.set("fate-core-official","defaultAspects","nothing");
}
}
if (value=="dfa"){
if (game.user.isGM){
game.settings.set("fate-core-official","aspects",game.system["lang"]["DresdenFilesAcceleratedDefaultAspects"]);
game.settings.set("fate-core-official","defaultAspects","nothing");
}
}
}
});
// Register a setting for replacing the existing track list with one of the pre-defined default sets.
game.settings.register("fate-core-official", "defaultTracks", {
name: game.i18n.localize("fate-core-official.ReplaceTracksName"),
hint: game.i18n.localize("fate-core-official.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,
requiresReload: true,
choices: { // If choices are defined, the resulting setting will be a select menu
"nothing":game.i18n.localize("fate-core-official.No"),
"fateCore":game.i18n.localize("fate-core-official.YesFateCore"),
"fateCondensed":game.i18n.localize("fate-core-official.YesFateCondensed"),
"accelerated":game.i18n.localize("fate-core-official.YesFateAccelerated"),
"dfa":game.i18n.localize("fate-core-official.YesDFA"),
"clearAll":game.i18n.localize("fate-core-official.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("fate-core-official","tracks",game.system["lang"]["FateCoreDefaultTracks"]);
game.settings.set("fate-core-official","defaultTracks","nothing");
game.settings.set("fate-core-official","track_categories",{"Combat":"Combat","Other":"Other"});
}
}
if (value=="clearAll"){
if (game.user.isGM){
game.settings.set("fate-core-official","tracks",{});
game.settings.set("fate-core-official","defaultTracks","nothing");
game.settings.set("fate-core-official","track_categories",{"Combat":"Combat","Other":"Other"});
}
}
if (value=="fateCondensed"){
if (game.user.isGM){
game.settings.set("fate-core-official","tracks",game.system["lang"]["FateCondensedDefaultTracks"]);
game.settings.set("fate-core-official","defaultTracks","nothing");
game.settings.set("fate-core-official","track_categories",{"Combat":"Combat","Other":"Other"});
}
}
if (value=="accelerated"){
if (game.user.isGM){
game.settings.set("fate-core-official","tracks",game.system["lang"]["FateAcceleratedDefaultTracks"]);
game.settings.set("fate-core-official","defaultTracks","nothing");
game.settings.set("fate-core-official","track_categories",{"Combat":"Combat","Other":"Other"});
}
}
if (value == "dfa"){
if (game.user.isGM){
game.settings.set("fate-core-official","tracks",game.system["lang"]["DresdenFilesAcceleratedDefaultTracks"]);
game.settings.set("fate-core-official","track_categories",game.system["lang"]["DresdenFilesAcceleratedDefaultTrackCategories"]);
game.settings.set("fate-core-official","defaultTracks","nothing");
}
}
}
});
game.settings.register("fate-core-official","exportSettings", {
name: game.i18n.localize("fate-core-official.ExportSettingsName"),
scope:"world",
config:true,
type:Boolean,
restricted:true,
default:false,
onChange: value => {
if (value == true && game.user.isGM){
let text = fcoConstants.exportSettings();
new Dialog({
title: game.i18n.localize("fate-core-official.ExportSettingsDialogTitle"),
content: `<div style="background-color:white; color:black;"><textarea rows="20" style="font-family:var(--fco-font-family); width:382px; background-color:white; border:1px solid var(--fco-foundry-interactable-color); color:black;" id="export_settings">${text}</textarea></div>`,
buttons: {
},
}).render(true);
game.settings.set("fate-core-official","exportSettings",false);
}
}
})
game.settings.register("fate-core-official","importSettings", {
name: game.i18n.localize("fate-core-official.ImportSettingsName"),
scope:"world",
hint:game.i18n.localize("fate-core-official.ImportSettingsHint"),
config:true,
type:Boolean,
restricted:true,
default:false,
onChange: async value => {
if (value == true && game.user.isGM){
let text = await fcoConstants.getSettings();
await fcoConstants.importSettings(text);
await game.settings.set("fate-core-official","importSettings",false);
foundry.utils.debouncedReload();
}
}
})
//Register a setting for the game's current Refresh total
game.settings.register("fate-core-official", "refreshTotal", {
name: game.i18n.localize("fate-core-official.RefreshTotalName"),
hint: game.i18n.localize("fate-core-official.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 == "fate-core-official"){
ui.windows[app]?.render(false);
}
}
}
});
// Register a setting to determine whether the refresh total on PCs should be enforced
game.settings.register("fate-core-official", "enforceRefresh", {
name: game.i18n.localize("fate-core-official.enforceRefreshMenuName"),
hint: game.i18n.localize("fate-core-official.enforceRefreshMenuHint"),
scope: "world",
config: true,
type: Boolean,
default:true,
});
game.settings.register("fate-core-official","freeStunts", {
name:game.i18n.localize("fate-core-official.FreeStunts"),
hint:game.i18n.localize("fate-core-official.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 == "fate-core-official"){
ui.windows[app]?.render(false);
}
}
}
})
//Register a setting for the game's current skill total
game.settings.register("fate-core-official", "skillTotal", {
name: game.i18n.localize("fate-core-official.SkillPointTotal"),
hint: game.i18n.localize("fate-core-official.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 == "fate-core-official"){
ui.windows[app]?.render(false);
}
}
}
});
game.settings.register("fate-core-official","enforceSkillTotal", {
name: game.i18n.localize("fate-core-official.EnforceSkillTotal"),
hint: game.i18n.localize("fate-core-official.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 == "fate-core-official"){
ui.windows[app]?.render(false);
}
}
}
})
game.settings.register("fate-core-official","enforceColumn", {
name: game.i18n.localize("fate-core-official.EnforceColumn"),
hint: game.i18n.localize("fate-core-official.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 == "fate-core-official"){
ui.windows[app]?.render(false);
}
}
}