@drincs/nqtr
Version:
A complete system introducing the concepts of location, time and event, producing the framework of a not-quite-point-and-click adventure game.
1 lines • 12.7 kB
Source Map (JSON)
{"version":3,"sources":["../../src/constants.ts","../../src/managers/TimeManagerSettings.ts","../../src/managers/TimeManager.ts"],"names":["TIME_DATA_KEY","TimeManagerSettings","TimeManager","settings","minDayHours","maxDayHours","defaultTimeSpent","timeSlots","weekLength","weekendStartDay","weekDaysNames","data","storage","value","weekDayNumber","index","slot","timeSpent","newHour","newDayHour","days","newDay","fromHour","toHour","currentHour"],"mappings":"sCACO,IAAMA,CAAAA,CAAgB,+BCC7B,IAAqBC,CAAAA,CAArB,KAAiE,CAC7D,OAAO,WAAA,CAAsB,EAC7B,OAAO,WAAA,CAAsB,EAC7B,CAAA,OAAO,gBAA2B,CAAA,CAAA,CAClC,OAAO,SAA0B,CAAA,EACjC,CAAA,OAAO,UAAqB,CAAA,CAAA,CAC5B,OAAO,eAA0B,CAAA,IAAA,CAAK,UAAa,CAAA,CAAA,CACnD,OAAO,aAAA,CAA0B,EACrC,CAAA,CCJqBC,IAAAA,CAAAA,CAArB,KAAiC,CAC7B,WAAWC,CAAwB,CAAA,CAC/B,GAAM,CACF,WAAAC,CAAAA,CAAAA,CAAc,EACd,WAAAC,CAAAA,CAAAA,CAAc,EACd,CAAA,gBAAA,CAAAC,CAAmB,CAAA,CAAA,CACnB,UAAAC,CAAY,CAAA,EACZ,CAAA,UAAA,CAAAC,CAAa,CAAA,CAAA,CACb,gBAAAC,CAAkBD,CAAAA,CAAAA,CAAa,CAC/B,CAAA,aAAA,CAAAE,CAAgB,CAAA,EACpB,CAAIP,CAAAA,CAAAA,CACJF,CAAoB,CAAA,WAAA,CAAcG,CAClCH,CAAAA,CAAAA,CAAoB,YAAcI,CAClCJ,CAAAA,CAAAA,CAAoB,gBAAmBK,CAAAA,CAAAA,CACvCL,CAAoB,CAAA,SAAA,CAAYM,EAChCN,CAAoB,CAAA,UAAA,CAAaO,CAC7BC,CAAAA,CAAAA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":["export const TIME_SETTINGS_KEY = '___nqtr-time_manager_settings___';\nexport const TIME_DATA_KEY = '___nqtr-time_manager_data___';\n\n","import { ITimeStlot, TimeSettings } from \"../types/TimeSettings\";\n\nexport default class TimeManagerSettings implements TimeSettings {\n static minDayHours: number = 0\n static maxDayHours: number = 24\n static defaultTimeSpent: number = 1\n static timeSlots: ITimeStlot[] = []\n static weekLength: number = 7\n static weekendStartDay: number = this.weekLength - 1\n static weekDaysNames: string[] = []\n}\n","import { storage } from \"@drincs/pixi-vn\";\nimport { TIME_DATA_KEY } from \"../constants\";\nimport TimeDataType from \"../types/TimeDataType\";\nimport { ITimeStlot, TimeSettings } from \"../types/TimeSettings\";\nimport TimeManagerSettings from \"./TimeManagerSettings\";\n\nexport default class TimeManager {\n initialize(settings: TimeSettings) {\n const {\n minDayHours = 0,\n maxDayHours = 24,\n defaultTimeSpent = 1,\n timeSlots = [],\n weekLength = 7,\n weekendStartDay = weekLength - 1,\n weekDaysNames = [],\n } = settings;\n TimeManagerSettings.minDayHours = minDayHours;\n TimeManagerSettings.maxDayHours = maxDayHours;\n TimeManagerSettings.defaultTimeSpent = defaultTimeSpent;\n TimeManagerSettings.timeSlots = timeSlots;\n TimeManagerSettings.weekLength = weekLength;\n if (weekendStartDay >= TimeManagerSettings.weekLength) {\n console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}, so will be ignored`);\n } else {\n TimeManagerSettings.weekendStartDay = weekendStartDay;\n }\n if (weekDaysNames.length !== weekLength) {\n console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}, so will be ignored`);\n } else {\n TimeManagerSettings.weekDaysNames = weekDaysNames;\n }\n }\n get minDayHours(): number {\n return TimeManagerSettings.minDayHours;\n }\n get maxDayHours(): number {\n return TimeManagerSettings.maxDayHours;\n }\n get defaultTimeSpent(): number {\n return TimeManagerSettings.defaultTimeSpent;\n }\n get timeSlots(): ITimeStlot[] {\n return TimeManagerSettings.timeSlots;\n }\n get weekLength(): number {\n return TimeManagerSettings.weekLength;\n }\n get weekendStartDay(): number {\n return TimeManagerSettings.weekendStartDay;\n }\n get weekDaysNames(): string[] {\n return TimeManagerSettings.weekDaysNames;\n }\n\n /**\n * Get the current hour\n */\n get currentHour(): number {\n let data = storage.getVariable<TimeDataType>(TIME_DATA_KEY) || {};\n if (data.hasOwnProperty(\"currentHour\") && typeof data.currentHour === \"number\") {\n return data.currentHour;\n }\n return this.minDayHours;\n }\n set currentHour(value: number | undefined) {\n let data = storage.getVariable<TimeDataType>(TIME_DATA_KEY) || {};\n if (typeof value === \"number\") {\n data.currentHour = value;\n } else {\n delete data.currentHour;\n }\n storage.setVariable(TIME_DATA_KEY, data);\n }\n /**\n * Get the current day\n */\n get currentDay(): number {\n let data = storage.getVariable<TimeDataType>(TIME_DATA_KEY) || {};\n if (data.hasOwnProperty(\"currentDay\") && typeof data.currentDay === \"number\") {\n return data.currentDay;\n }\n return 0;\n }\n set currentDay(value: number | undefined) {\n let data = storage.getVariable<TimeDataType>(TIME_DATA_KEY) || {};\n if (typeof value === \"number\") {\n data.currentDay = value;\n } else {\n delete data.currentDay;\n }\n storage.setVariable(TIME_DATA_KEY, data);\n }\n /**\n * If the current day is greater than or equal to the weekend start day, then it will return true.\n */\n get isWeekend(): boolean {\n return this.currentWeekDayNumber >= this.weekendStartDay;\n }\n /**\n * Get the current week day number (1 - {@link weekLength}).\n * For example, if the week length is 7 and the current day is 10, then the result will be 4.\n */\n get currentWeekDayNumber(): number {\n let result = this.currentDay % this.weekLength;\n return result + 1;\n }\n /**\n * Get the current week day name. If the week days names are not defined, then it will return undefined.\n * For example, if the week days names are ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] and the current day is 10, then the result will be 'Thursday'.\n * @default \"\"\n */\n get currentDayName(): string {\n let weekDayNumber = this.currentWeekDayNumber - 1;\n if (weekDayNumber >= this.weekDaysNames.length) {\n console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, this.weekDaysNames);\n return \"\";\n }\n return this.weekDaysNames[weekDayNumber];\n }\n /**\n * Get the current {@link timeSlots} index.\n * You can use this property to create \"Image that changes based on the time period\":\n * @example\n * ```tsx\n * import { weekLength } from '@drincs/nqtr';\n *\n * function changeBackground() {\n * return (\n * <img src={`background-currentTimeSlot.currentTimeSlot.png`} />\n * )\n * }\n */\n get currentTimeSlot(): number {\n if (this.timeSlots.length === 0) {\n console.warn(\"[NQTR] Time slots are not defined\");\n return 0;\n }\n for (let index = 0; index < this.timeSlots.length; index++) {\n let slot = this.timeSlots[index];\n if (this.timeSlots.length > index + 1) {\n if (this.nowIsBetween(slot.startHour, this.timeSlots[index + 1].startHour)) {\n return index;\n }\n }\n }\n return this.timeSlots.length - 1;\n }\n\n /**\n * This function will increase the current hour by the given time spent.\n * If the new hour is greater than or equal to the max day hours, then it will increase the day and set the new hour.\n * @param timeSpent is the time spent in hours (default: {@link defaultTimeSpent})\n * @returns currentTimeSlot.currentHour\n */\n increaseHour(timeSpent: number = this.defaultTimeSpent): number {\n let newHour = this.currentHour + timeSpent;\n if (newHour >= this.maxDayHours) {\n this.increaseDay();\n newHour = this.minDayHours + (newHour - this.maxDayHours);\n }\n this.currentHour = newHour;\n return this.currentHour;\n }\n\n /**\n * This function will increase the current day by the given days.\n * @param newDayHour is the hour of the new day (default: {@link minDayHours})\n * @param days is the number of days to increase (default: 1)\n * @returns timeTracker.currentDay\n */\n increaseDay(newDayHour: number = this.minDayHours, days: number = 1): number {\n let newDay = this.currentDay + days;\n this.currentDay = newDay;\n this.currentHour = newDayHour;\n return this.currentDay;\n }\n\n /**\n * This function will check if the current hour is between the given hours.\n * @param fromHour the starting hour. If the {@link currentHour} is equal to this hour, the function will return true.\n * @param toHour the ending hour.\n * @returns true if the current hour is between the given hours, otherwise false.\n */\n nowIsBetween(fromHour: number | undefined, toHour: number | undefined): boolean {\n if (fromHour === undefined) {\n fromHour = this.minDayHours - 1;\n }\n if (toHour === undefined) {\n toHour = this.maxDayHours + 1;\n }\n let currentHour = this.currentHour;\n if (fromHour < toHour) {\n return currentHour >= fromHour && currentHour < toHour;\n }\n return currentHour >= fromHour || currentHour < toHour;\n }\n}\n"]}