Pixi’VN

Time system

Nomenclature

It was decided to use the very generic terms date and time. The reason is that, depending on what is being developed, time can correspond to hours, minutes, or a long period of time. The same applies to date.

The time system is composed of the following elements:

ElementDescription
dateA counter used to determine the date of the game.
timeA counter used to determine the time of day, which is reset every time the date is incremented.

You can use timeTracker instance to manage your time system. It provides methods to initialize, get, increment time, etc. The time system is designed to be flexible and can be adapted to various game requirements.

Initialize

To initialize the time system, you need use the timeTracker.initialize method.

main.ts
timeTracker.initialize({
    defaultTimeSpent: 1,
    dayStartTime: 0,
    dayEndTime: 24,
    timeSlots: [
        { name: "Morning", startTime: 5 },
        { name: "Afternoon", startTime: 12 },
        { name: "Evening", startTime: 18 },
        { name: "Night", startTime: 22 },
    ],
    getDayName: (weekDayNumber: number) => {
        const weekDaysNames = [
            "Monday",
            "Tuesday",
            "Wednesday",
            "Thursday",
            "Friday",
            "Saturday",
            "Sunday",
        ];
        return weekDaysNames[weekDayNumber];
    },
    weekendStartDay: 6,
    weekLength: 7,
});

Get

To get a current time, use the timeTracker.currentTime property. It returns the current time as a number.

import { timeTracker } from "@drincs/nqtr";

const currentTime: number = timeTracker.currentTime;

To get a current date, use the timeTracker.currentDate property. It returns the current date as a number.

import { timeTracker } from "@drincs/nqtr";

const currentDate: number = timeTracker.currentDate;

Set

To set a specific time, use the timeTracker.currentTime property. It accepts a number representing the time to set.

index.ts
import { timeTracker } from "@drincs/nqtr";

timeTracker.currentTime = 12; // Set time to 12

To set a specific date, use the timeTracker.currentDate property. It accepts a number representing the date to set.

index.ts
import { timeTracker } from "@drincs/nqtr";

timeTracker.currentDate = 5; // Set date to 5

Increment

timeTracker has some functions to increment the time and date with some additional logic.

To increment the current time by a specific amount, use the timeTracker.increaseTime method. In case that the new time exceeds the dayEndTime, it will automatically increment the date and reset the time to the dayStartTime plus the overflow time.

To increment the current date by a specific amount, use the timeTracker.increaseDate method.

index.ts
import { timeTracker } from "@drincs/nqtr";

timeTracker.increaseTime(2);
timeTracker.increaseDate(1, 8); // Increment date by 1 and set time to 8

Is weekend

To check if the current day is a weekend, use the timeTracker.isWeekend property. It returns a boolean indicating whether the current day is a weekend.

import { timeTracker } from "@drincs/nqtr";

const isWeekend: boolean = timeTracker.isWeekend;

Other features

On this page