LogoPixi’VN

Navigation and Map

Nomenclature

Usually in video games the navigation elements used to identify the position of the characters are the room, the location (for example restaurant, house, hospital etc...), the map. For this reason it was decided to keep names that follow this logic.

This does not prevent using these elements to manage navigation with the same logic but with different terms. For example in a game set in the space in which the player moves between planets, the rooms can be the planets, the locations can be the solar systems and the maps can be the galaxy.

The navigation system is composed of the following elements:

  • rooms: These are the core elements of navigation, from which the position of the mc and npc is deduced.
  • locations: is a container of rooms.
  • maps: is a container of locations.

The player can move between rooms. The location and the map are also determined based on the room in which the player is located.

The developer can designate "index" rooms for places or maps, to implement features that allow moving from one location or map to another.

Inizializzare

To initialize a room/location/map, create a new instance of the RoomBaseModel / LocationBaseModel / MapBaseModel class (or your custom class) and add it to the game room/location/map dictionary when the game is initialized.

To create a new instance of RoomBaseModel / LocationBaseModel / MapBaseModel, you need the following parameters:

import { RegisteredRooms, RoomBaseModel } from "@drincs/nqtr";
import { bed } from "./activity";
import { mcHome } from "./locations";

export const mcRoom = new RoomBaseModel("mc_room", mcHome, {
    name: "MC room",
    image: "location_myroom",
    activities: [bed],
});

export const aliceRoom = new RoomBaseModel("alice_room", mcHome, {
    name: "Alice room",
    image: "location_aliceroom",
});

export const annRoom = new RoomBaseModel("ann_room", mcHome, {
    name: "Ann room",
    image: "location_annroom",
});

export const bathroom = new RoomBaseModel("bathroom", mcHome, {
    name: "Bathroom",
    image: "location_bathroom",
});

export const lounge = new RoomBaseModel("lounge", mcHome, {
    name: "Lounge",
    image: "location_lounge",
});

export const terrace = new RoomBaseModel("terrace", mcHome, {
    name: "Terrace",
    image: "location_terrace",
});

RegisteredRooms.add([mcRoom, aliceRoom, annRoom, bathroom, lounge, terrace]);

RegisteredRooms.add / RegisteredLocations.add / RegisteredMaps.add is required to save the rooms/locations/maps in the game.

You can also create a function to load rooms/locations/maps. The important thing is that it is called at least once before the rooms/locations/maps are used in the game, otherwise they will not be available.

It is also recommended to set the current room during the start of the game.

labels/startLabel.ts
import { navigator } from "@drincs/nqtr";
import { newLabel } from "@drincs/pixi-vn";
import { mcRoom } from "../values/rooms";

const startLabel = newLabel("start", [
    async () => {
        navigator.currentRoom = mcRoom;
        // ... other initialization logic
    },
]);
export default startLabel;

Ottieni

To get a room/location/map by its id, use the RegisteredRooms.get / RegisteredLocations.get / RegisteredMaps.get function.

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

const mcRoom = RegisteredRooms.get('mc_room');

Ottieni tutti

To get all rooms/locations/maps, use the RegisteredRooms.values / RegisteredLocations.values / RegisteredMaps.values function.

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

const rooms = RegisteredRooms.values();

As explained above, the player can navigate between rooms, and the current room determines the current location and map.

To navigate to a room, set the navigator.currentRoom property to the desired room instance. This will automatically update the current location and map based on the room's location and map.

import { navigator } from "@drincs/nqtr";
import { mcRoom } from "../values/rooms";

navigator.currentRoom = mcRoom;

Classe personalizzata

Templates

In all templates, the Room / Location / Map class is already defined in the file models/nqtr/Room.ts / models/nqtr/Location.ts / models/nqtr/Map.ts. You can use it directly or modify it to suit your needs.

It is recommended to create your own class Room / Location / Map that extends RoomStoredClass / LocationStoredClass / MapStoredClass and "override" the interface RoomInterface / LocationInterface / MapInterface to add, edit, or remove properties or methods.

For example, if you want to create a class Room / Location / Map, you must "override" the interface RoomInterface / LocationInterface / MapInterface to use your properties or methods. (See the file nqtr.d.ts)

Now you can create a class Room / Location / Map that extends RoomStoredClass / LocationStoredClass / MapStoredClass and implements the RoomInterface / LocationInterface / MapInterface. (Per maggiori informazioni su come creare una classe in TypeScript, leggi la documentazione ufficiale)

To create a property that stores its value in the game storage, you can create Getters/Setters and use the this.getStorageProperty() / this.setStorageProperty() methods. (See the file Room.ts / Location.ts / Map.ts)

import { ActivityInterface, LocationInterface, RoomInterface, RoomStoredClass } from "@drincs/nqtr";
import ImageTimeSlots from "../ImageTimeSlots";

export default class Room extends RoomStoredClass implements RoomInterface {
    constructor(
        id: string,
        location: LocationInterface,
        props: {
            name: string;
            disabled?: boolean | (() => boolean);
            hidden?: boolean | (() => boolean);
            image: ImageTimeSlots;
            activities?: ActivityInterface[];
            isEntrance?: boolean;
        }
    ) {
        super(id, location, props.activities);
        this.name = props.name;
        this._defaultdisabled = props.disabled || false;
        this._defaulthidden = props.hidden || false;
        this.image = props.image;
        this.isEntrance = props.isEntrance || false;
    }
    readonly name: string;
    readonly image: ImageTimeSlots;
    readonly isEntrance: boolean;
    private _defaultdisabled: boolean | (() => boolean) = false;
    get disabled(): boolean {
        let value = this.getStorageProperty<boolean>("disabled") || this._defaultdisabled;
        if (typeof value === "function") {
            return value();
        }
        return value;
    }
    set disabled(value: boolean) {
        this.setStorageProperty("disabled", value);
    }
    private _defaulthidden: boolean | (() => boolean) = false;
    get hidden(): boolean {
        let value = this.getStorageProperty<boolean>("hidden") || this._defaulthidden;
        if (typeof value === "function") {
            return value();
        }
        return value;
    }
    set hidden(value: boolean) {
        this.setStorageProperty("hidden", value);
    }
}