Pixi’VN

Activity

The activity are actions the player can take, and they can be linked to a navigation element. The developer will decide how the player interacts with them.

Initialize

To initialize a activity, create a new instance of the ActivityBaseModel class (or your custom class) and add it to the game activity dictionary when the game is initialized.

RegisteredActivities.add is required to save the activities in the game.

content/activities.ts
import {
    ActivityBaseModel,
    RegisteredActivities,
    timeTracker,
} from "@drincs/nqtr";
import { RegisteredActivities, timeTracker } from "@drincs/nqtr";
import { narration } from "@drincs/pixi-vn";

export const bed = new ActivityBaseModel(
    "bed",
    async (_, props) => {
        await props.navigate({ to: "/game/narration" });
        if (timeTracker.nowIsBetween(5, 22)) {
            await narration.jump("nap", props);
        } else {
            await narration.jump("sleep", props);
        }
    },
    {
        name: "bed",
    },
);

export const orderProduct = new ActivityBaseModel(
    "order_product",
    async (_, props) => {
        await props.navigate({ to: "/game/narration" });
        await narration.jump("order_product", props);
    },
    {
        name: "order_product",
    },
);

export const takeProduct = new ActivityBaseModel(
    "take_product",
    async (_, props) => {
        await props.navigate({ to: "/game/narration" });
        await narration.jump("take_product", props);
    },
    {
        name: "take_product",
    },
);

RegisteredActivities.add(bed, orderProduct, takeProduct);

For an activity to be available to the player, it must be linked to a navigation element. The relationship between an activity and a navigation element is many-to-many, meaning that an activity can be linked to multiple navigation elements and a navigation element can have multiple activities associated with it.

There are two ways to do this:

During game initialization

When the game starts, a list of related activities will be defined. This list will not be saved when the game is saved. Therefore, the developer can modify this list from one version of the game to another without having to worry about migrations for older versions.

import { RegisteredRooms, RoomBaseModel } from "@drincs/nqtr";
import { mcHome } from "@/content/locations";

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

RegisteredRooms.add(mcRoom);

During the game

You can also link an activity to a navigation element during the game. This feature is useful if you want to temporarily add an activity. The list of activities added this way will be included in your game saves.

To link an activity to a navigation element during the game, you can use the room.addActivity method.

content/labels/start.label.ts
import { newLabel, showImageContainer } from "@drincs/pixi-vn";
import { mcRoom } from "@/content/rooms";

export const startLabel = newLabel("start", [
    async () => {
        mcRoom.addActivity("order_product"); 
    },
]);

To unlink an activity from a navigation element, you can use the room.removeActivity method.

content/labels/start.label.ts
import { mcRoom } from "@/content/rooms";

mcRoom.removeActivity("order_product");

Get

To get a activity by its id, use the RegisteredActivities.get function.

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

const orderProduct = RegisteredActivities.get("order_product");

Get all

To get all activities, use the RegisteredActivities.values function.

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

const activities = RegisteredActivities.values();

Other features

On this page