Skip to content

Commit 8848683

Browse files
committed
Allowed for users to add their own custom calanders
1 parent 1db1bda commit 8848683

File tree

2 files changed

+267
-15
lines changed

2 files changed

+267
-15
lines changed

QuestTracker/1.0/QuestTracker.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var QuestTracker = QuestTracker || (function () {
1313
if (state.CalenderData.CALENDARS) CALENDARS = state.CalenderData.CALENDARS;
1414
if (state.CalenderData.WEATHER) WEATHER = state.CalenderData.WEATHER;
1515
}
16+
Object.assign(CALENDARS, state.QUEST_TRACKER.calendar);
1617
return { CALENDARS, WEATHER };
1718
};
1819
const { CALENDARS, WEATHER } = getCalendarAndWeatherData();
@@ -39,10 +40,12 @@ var QuestTracker = QuestTracker || (function () {
3940
let QUEST_TRACKER_globalQuestArray = [];
4041
let QUEST_TRACKER_globalRumours = {};
4142
let QUEST_TRACKER_Events = {};
43+
let QUEST_TRACKER_Calendar = {};
4244
let QUEST_TRACKER_QuestHandoutName = "QuestTracker Quests";
4345
let QUEST_TRACKER_RumourHandoutName = "QuestTracker Rumours";
4446
let QUEST_TRACKER_EventHandoutName = "QuestTracker Events";
4547
let QUEST_TRACKER_WeatherHandoutName = "QuestTracker Weather";
48+
let QUEST_TRACKER_CalendarHandoutName = "QuestTracker Calendar";
4649
let QUEST_TRACKER_rumoursByLocation = {};
4750
let QUEST_TRACKER_readableJSON = true;
4851
let QUEST_TRACKER_pageName = "Quest Tree Page";
@@ -102,6 +105,7 @@ var QuestTracker = QuestTracker || (function () {
102105
QUEST_TRACKER_questGrid = state.QUEST_TRACKER.questGrid || [];
103106
QUEST_TRACKER_jumpGate = state.QUEST_TRACKER.jumpGate || true;
104107
QUEST_TRACKER_Events = state.QUEST_TRACKER.events || {};
108+
QUEST_TRACKER_Calendar = state.QUEST_TRACKER.calendar || {};
105109
QUEST_TRACKER_calenderType = state.QUEST_TRACKER.calenderType || 'gregorian';
106110
QUEST_TRACKER_currentDate = state.QUEST_TRACKER.currentDate || CALENDARS[QUEST_TRACKER_calenderType]?.defaultDate
107111
QUEST_TRACKER_defaultDate = state.QUEST_TRACKER.defaultDate || CALENDARS[QUEST_TRACKER_calenderType]?.defaultDate
@@ -150,6 +154,7 @@ var QuestTracker = QuestTracker || (function () {
150154
state.QUEST_TRACKER.questGrid = QUEST_TRACKER_questGrid;
151155
state.QUEST_TRACKER.jumpGate = QUEST_TRACKER_jumpGate;
152156
state.QUEST_TRACKER.events = QUEST_TRACKER_Events;
157+
state.QUEST_TRACKER.calendar = QUEST_TRACKER_Calendar;
153158
state.QUEST_TRACKER.currentDate = QUEST_TRACKER_currentDate;
154159
state.QUEST_TRACKER.defaultDate = QUEST_TRACKER_defaultDate;
155160
state.QUEST_TRACKER.calenderType = QUEST_TRACKER_calenderType;
@@ -179,6 +184,7 @@ var QuestTracker = QuestTracker || (function () {
179184
TreeObjRef: {},
180185
jumpGate: true,
181186
events: {},
187+
calendar: {},
182188
calenderType: 'gregorian',
183189
currentDate: CALENDARS[QUEST_TRACKER_calenderType]?.defaultDate,
184190
defaultDate: CALENDARS[QUEST_TRACKER_calenderType]?.defaultDate,
@@ -208,16 +214,16 @@ var QuestTracker = QuestTracker || (function () {
208214
};
209215
if (!findObjs({ type: 'rollabletable', name: QUEST_TRACKER_ROLLABLETABLE_QUESTS })[0]) {
210216
const tableQuests = createObj('rollabletable', { name: QUEST_TRACKER_ROLLABLETABLE_QUESTS });
211-
tableQuests.set('showplayers', false); // Hide table from players
217+
tableQuests.set('showplayers', false);
212218
}
213219
if (!findObjs({ type: 'rollabletable', name: QUEST_TRACKER_ROLLABLETABLE_QUESTGROUPS })[0]) {
214220
const tableQuestGroups = createObj('rollabletable', { name: QUEST_TRACKER_ROLLABLETABLE_QUESTGROUPS });
215-
tableQuestGroups.set('showplayers', false); // Hide table from players
221+
tableQuestGroups.set('showplayers', false);
216222
}
217223
let locationTable = findObjs({ type: 'rollabletable', name: QUEST_TRACKER_ROLLABLETABLE_LOCATIONS })[0];
218224
if (!locationTable) {
219225
locationTable = createObj('rollabletable', { name: QUEST_TRACKER_ROLLABLETABLE_LOCATIONS });
220-
locationTable.set('showplayers', false); // Hide table from players
226+
locationTable.set('showplayers', false);
221227
createObj('tableitem', {
222228
_rollabletableid: locationTable.id,
223229
name: 'Everywhere',
@@ -236,6 +242,9 @@ var QuestTracker = QuestTracker || (function () {
236242
if (!findObjs({ type: 'handout', name: QUEST_TRACKER_WeatherHandoutName })[0]) {
237243
createObj('handout', { name: QUEST_TRACKER_WeatherHandoutName });
238244
}
245+
if (!findObjs({ type: 'handout', name: QUEST_TRACKER_CalendarHandoutName })[0]) {
246+
createObj('handout', { name: QUEST_TRACKER_CalendarHandoutName });
247+
}
239248
Utils.sendGMMessage("QuestTracker has been initialized.");
240249
}
241250
};
@@ -358,6 +367,9 @@ var QuestTracker = QuestTracker || (function () {
358367
case 'quest':
359368
handoutName = QUEST_TRACKER_QuestHandoutName;
360369
break;
370+
case 'calendar':
371+
handoutName = QUEST_TRACKER_CalendarHandoutName;
372+
break;
361373
default:
362374
return;
363375
}
@@ -384,12 +396,14 @@ var QuestTracker = QuestTracker || (function () {
384396
case 'weather':
385397
updatedData = QUEST_TRACKER_HISTORICAL_WEATHER;
386398
break;
387-
case 'weatherevents':
388-
updatedData = QUEST_TRACKER_Events;
399+
case 'calendar':
400+
updatedData = QUEST_TRACKER_Calendar;
389401
break;
390-
default:
402+
case 'quest':
391403
updatedData = QUEST_TRACKER_globalQuestData;
392404
break;
405+
default:
406+
return;
393407
}
394408
const updatedContent = QUEST_TRACKER_readableJSON
395409
? JSON.stringify(updatedData, null, 2)
@@ -406,9 +420,17 @@ var QuestTracker = QuestTracker || (function () {
406420
case 'event':
407421
QUEST_TRACKER_Events = JSON.parse(cleanedContent);
408422
break;
409-
default:
423+
case 'weather':
424+
QUEST_TRACKER_HISTORICAL_WEATHER = JSON.parse(cleanedContent);
425+
break;
426+
case 'calendar':
427+
QUEST_TRACKER_Calendar = JSON.parse(cleanedContent);
428+
break;
429+
case 'quest':
410430
QUEST_TRACKER_globalQuestData = JSON.parse(cleanedContent);
411431
break;
432+
default:
433+
return;
412434
}
413435
}
414436
});
@@ -425,7 +447,7 @@ var QuestTracker = QuestTracker || (function () {
425447
updateHandoutField('rumour');
426448
updateHandoutField('event');
427449
updateHandoutField('weather');
428-
updateHandoutField('weatherdescription');
450+
updateHandoutField('calendar');
429451
};
430452
const toggleWeather = (value) => {
431453
QUEST_TRACKER_WEATHER = (value === 'true');
@@ -481,8 +503,7 @@ var QuestTracker = QuestTracker || (function () {
481503
importData: (handoutName, dataType) => {
482504
let handout = findObjs({ type: 'handout', name: handoutName })[0];
483505
if (!handout) {
484-
errorCheck(7, 'msg', null,`${dataType} handout "${handoutName}" not found. Please create it.`);
485-
return;
506+
createObj('handout', { name: handoutName });
486507
}
487508
handout.get('gmnotes', (notes) => {
488509
const cleanedContent = Utils.stripJSONContent(notes);
@@ -533,9 +554,9 @@ var QuestTracker = QuestTracker || (function () {
533554
} else if (dataType === 'Weather') {
534555
parsedData = Utils.normalizeKeys(parsedData);
535556
QUEST_TRACKER_HISTORICAL_WEATHER = parsedData;
536-
} else if (dataType === 'Weather Description') {
557+
} else if (dataType === 'Calendar') {
537558
parsedData = Utils.normalizeKeys(parsedData);
538-
QUEST_TRACKER_WEATHER_DESCRIPTION = parsedData;
559+
QUEST_TRACKER_Calendar = parsedData;
539560
}
540561
saveQuestTrackerData();
541562
Utils.sendGMMessage(`${dataType} handout "${handoutName}" Imported.`);
@@ -599,17 +620,24 @@ var QuestTracker = QuestTracker || (function () {
599620
});
600621
saveQuestTrackerData();
601622
Utils.updateHandoutField('quest');
623+
},
624+
refreshCalendarData: () => {
625+
Object.keys(CALENDARS).forEach(key => delete CALENDARS[key]);
626+
Object.assign(CALENDARS, state.CalenderData.CALENDARS);
627+
Object.assign(CALENDARS, state.QUEST_TRACKER.calendar);
602628
}
603629
};
604630
const fullImportProcess = () => {
605631
H.importData(QUEST_TRACKER_QuestHandoutName, 'Quest');
606632
H.importData(QUEST_TRACKER_RumourHandoutName, 'Rumour');
607633
H.importData(QUEST_TRACKER_EventHandoutName, 'Events');
608634
H.importData(QUEST_TRACKER_WeatherHandoutName, 'Weather');
635+
H.importData(QUEST_TRACKER_CalendarHandoutName, 'Calendar');
609636
H.syncQuestRollableTable();
610637
Quest.cleanUpLooseEnds();
611638
H.cleanUpDataFields();
612639
Quest.populateQuestsToAutoAdvance();
640+
H.refreshCalendarData();
613641
};
614642
return {
615643
fullImportProcess

0 commit comments

Comments
 (0)