UNPKG

@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.

833 lines (806 loc) 27.9 kB
export * from '@drincs/nqtr/handlers'; import * as registries from '@drincs/nqtr/registries'; import { ActivityIdType, CommitmentIdType } from '@drincs/nqtr/registries'; export { ActivityIdType, CommitmentIdType, LocationIdType, MapIdType, NqtrActivityIds, NqtrCommitmentIds, NqtrLocationIds, NqtrMapIds, NqtrQuestIds, NqtrRoomIds, QuestIdType, RegisteredActivities, RegisteredCommitments, RegisteredLocations, RegisteredMaps, RegisteredQuests, RegisteredRooms, RoomIdType } from '@drincs/nqtr/registries'; import { T as TimeSchedulingInterface, D as DateSchedulingInterface, C as CommitmentInterface, E as ExecutionType, O as OnRunEvent, A as ActivityInterface, Q as QuestInterface, a as QuestsRequiredType, S as StageInterface, b as ActivityBaseInternalInterface, c as ActiveScheduling, d as OnRunAsyncFunction, e as CommitmentBaseInternalInterface, f as OnRunProps, N as NavigationAbstractInterface, L as LocationInternalInterface, M as MapInterface, R as RoomInterface, g as MapBaseInternalInterface, h as LocationInterface, i as RoomBaseInternalInterface, j as QuestBaseInternalInterface, k as StageBaseInternalInterface } from './StageInterface-BN_O8nDA.js'; export { l as OnRunFunction } from './StageInterface-BN_O8nDA.js'; import { StoredClassModel } from '@drincs/pixi-vn/storage'; import { CharacterInterface, CharacterIdType } from '@drincs/pixi-vn/characters'; import { CharacterInterface as CharacterInterface$1, CharacterIdType as CharacterIdType$1 } from '@drincs/pixi-vn'; import { h as handlers$1 } from './index-CtxMgD9N.js'; export { T as ITimeStlot, a as TimeSettings } from './index-CtxMgD9N.js'; import '@drincs/nqtr'; interface ActivityProps { /** * The name * @default "" */ name?: string; /** * Time slot in which activity/commitment will be active. */ timeSlot?: TimeSchedulingInterface; /** * Used to schedule what date it will be added and removed. */ dateScheduling?: DateSchedulingInterface; /** * Whether is disabled. You can also pass a Pixi'VN flag name. * @default false */ disabled?: boolean | string; /** * Whether is hidden. You can also pass a Pixi'VN flag name. * @default false */ hidden?: boolean | string; /** * The icon of the activity. * @default undefined */ renderIcon?: string; } interface CommitmentInfo { commitment: CommitmentInterface; roomId: string; } interface CommitmentProps { /** * The name * @default "" */ name?: string; /** * Time slot in which activity/commitment will be active. */ readonly timeSlot?: TimeSchedulingInterface | undefined; /** * Used to schedule what date it will be added and removed. */ readonly dateScheduling?: DateSchedulingInterface | undefined; /** * The image ofthe Commitment. */ image?: string; /** * Execution type. If is "automatic" the onRun() runned automatically when the palayer is in the room. If is "interaction" the player must interact with the character to run the onRun() function. * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time. * @default "interaction" */ executionType?: ExecutionType; /** * Is a function that is called when the player interacts with the character. * @param commitment * @returns * @default undefined */ onRun?: OnRunEvent<CommitmentInterface>; /** * Whether is disabled. You can also pass a Pixi'VN flag name. * If it is disabled this commitment will not be taken into consideration. So the characters will not be in the room, but will be busy with other commitments. * @default false */ disabled?: boolean | string; /** * Whether is hidden. You can also pass a Pixi'VN flag name. * @default false */ hidden?: boolean | string; /** * The icon of the commitment. */ icon?: string; /** * The priority. The higher the number, the higher the priority. * To ensure that a character is not in 2 places at the same time, if there are 2 or more valid commits at the same time and with the same character, the one with the highest priority will be chosen. * @default 0 */ priority?: number; } interface LocationBaseModelProps { /** * The name * @default "" */ name?: string; /** * Whether is disabled. You can also pass a Pixi'VN flag name. * @default false */ disabled?: boolean | string; /** * Whether is hidden. You can also pass a Pixi'VN flag name. * @default false */ hidden?: boolean | string; /** * The icon of the location. * @default undefined */ icon?: string; /** * The activities that are available in this location. * @default [] */ activities?: (ActivityInterface | ActivityIdType)[]; } interface MapBaseModelProps { /** * The name * @default "" */ name?: string; /** * The image of the map. * @default undefined */ image?: string; /** * The activities that are available in this map. * @default [] */ activities?: (ActivityInterface | ActivityIdType)[]; } interface RoomBaseModelProps { /** * The name * @default "" */ name?: string; /** * The image of the room. * @default undefined */ image?: string; /** * The activities that are available in this room. * @default [] */ activities?: (ActivityInterface | ActivityIdType)[]; /** * The routine of the room, it is an array of commitments that are executed in the room. You can also add commitments during the game session, but this property is useful to set the initial routine of the room. * @default undefined */ routine?: (CommitmentInterface | CommitmentIdType)[]; /** * Whether is disabled. You can also pass a Pixi'VN flag name. * @default false */ disabled?: boolean | string; /** * Whether is hidden. You can also pass a Pixi'VN flag name. * @default false */ hidden?: boolean | string; /** * The icon of the room. * @default undefined */ icon?: string; } interface QuestProps { /** * The name of the quest. * @default "" */ name?: string; /** * The description of the quest. * @default "" */ description?: string; /** * The icon of the quest. * @default undefined */ icon?: string; /** * The image of the quest. */ image?: string; /** * If the quest is in development. * @default false */ inDevelopment?: boolean; /** * The function that will be executed when the quest starts. */ onStart?: OnRunEvent<QuestInterface>; /** * @deprecated Use {@link onContinue} instead. The function that will be executed when a stage end in the quest. */ onNextStage?: OnRunEvent<QuestInterface>; /** * The function that will be executed when a stage end in the quest. */ onContinue?: OnRunEvent<QuestInterface>; } interface StageFlags { /** * The flag for checking if the condition is met. */ flag: string; /** * The description of the flag. */ description: string; } interface StageProps { /** * The flags of the stage. * @default [] */ flags?: StageFlags[]; /** * The name of the stage. * @default "" */ name?: string; /** * The description of the stage. * @default "" */ description?: string; /** * The advice description of the stage. * @default "" */ adviceDescription?: string; /** * The image of the stage. */ image?: string; /** * The number of day/date required to start the stage. * @example If the value is 3, and the previous stage ends on date 1, the stage will start on date 4. */ deltaDateRequired?: number; /** * The flags required to start the stage. * @default [] */ flagsRequired?: StageFlags[]; /** * The quests required to start the stage. * @default [] */ questsRequired?: QuestsRequiredType[]; /** * The description to request to start the stage. * @default "" */ requestDescriptionToStart?: string; /** * The function that will be executed when the stage starts. */ onStart?: OnRunEvent<StageInterface>; /** * The function that will be executed when the stage ends. */ onEnd?: OnRunEvent<StageInterface>; } interface ActivityStoredClassProps extends ActiveScheduling { } declare class ActivityStoredClass<OnRunEventType = ActivityInterface> extends StoredClassModel implements ActivityBaseInternalInterface { protected readonly _onRun: OnRunEvent<OnRunEventType>; constructor(id: string, _onRun: OnRunEvent<OnRunEventType>, props: ActivityStoredClassProps, category?: string); private _timeSlot?; get timeSlot(): TimeSchedulingInterface[] | TimeSchedulingInterface | undefined; private _dateScheduling?; get dateScheduling(): DateSchedulingInterface | undefined; protected addTempHistoryItem(): void; get run(): OnRunAsyncFunction; get expired(): boolean; isActive(options?: ActiveScheduling): boolean; } /** * The activity model. It is used to create an activity. * @example * ```tsx * export const nap = new ActivityModel("nap", * (_, event) => { * if (event) { * event.navigate("/game") * callLabelWithGoNavigationCallBack(napLabel, event) * } * else { * console.error("Event is undefined") * } * }, * { * name: "Nap", * timeSlot: { * from: 5, * to: 23, * }, * icon: "https://icon.jpg", * } * ) * ``` */ declare class ActivityBaseModel extends ActivityStoredClass<ActivityInterface> { /** * @param id The activity id, that must be unique. * @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function. * @param props The activity properties. */ constructor(id: string, onRun: OnRunEvent<ActivityInterface>, props: ActivityProps); private defaultName; /** * The name of the activity. */ get name(): string; set name(value: string | undefined); private defaultDisabled; /** * Whether is disabled. If it is a string, it is a Pixi'VN flag name. */ get disabled(): boolean; set disabled(value: boolean | string); private defaultHidden; /** * Whether is hidden. If it is a string, it is a Pixi'VN flag name. */ get hidden(): boolean; set hidden(value: boolean | string); private _icon?; /** * The icon of the activity. */ get icon(): string | undefined; } interface CommitmentStoredClassProps { /** * Execution type. If is "automatic" the onRun() runned automatically when the palayer is in the room. If is "interaction" the player must interact with the character to run the onRun() function. * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time. */ executionType?: ExecutionType; /** * The priority. The higher the number, the higher the priority. * To ensure that a character is not in 2 places at the same time, if there are 2 or more valid commits at the same time and with the same character, the one with the highest priority will be chosen. */ priority?: number; /** * Time slot in which activity/commitment will be active. */ timeSlot?: TimeSchedulingInterface; /** * Used to schedule what date it will be added and removed. */ dateScheduling?: DateSchedulingInterface; } declare class CommitmentStoredClass extends ActivityStoredClass<CommitmentInterface> implements CommitmentBaseInternalInterface { constructor(id: string, characters: (CharacterInterface | CharacterIdType)[], onRun: OnRunEvent<CommitmentInterface> | undefined, props: CommitmentStoredClassProps); private readonly defaultExecutionType; private readonly defaultPriority?; readonly characters: CharacterInterface[]; get executionType(): ExecutionType; set executionType(value: ExecutionType); get priority(): number; set priority(value: number); protected addTempHistoryItem(): void; /** * Options for {@link run}. */ runOptions?: CommitmentRunOptions; /** * Executes the commitment's `onRun` callback. * @param props - Standard run props. * @param options - Additional options. * @param options.removeFromRoutine - Whether to call `routine.remove` for this commitment. * Defaults to `true` when {@link executionType} is `"automatic"`, `false` otherwise. */ get run(): (props: OnRunProps, options?: CommitmentRunOptions) => Promise<any>; } /** * Options accepted by {@link CommitmentStoredClass.run}. */ interface CommitmentRunOptions { /** * Whether to call `routine.remove` for this commitment after running. * Defaults to `true` when {@link CommitmentStoredClass.executionType} is `"automatic"`, `false` otherwise. */ removeFromRoutine?: boolean; } /** * The base model of a commitment. I suggest you extend this class to create your own commitment model. * You must use the saveCommitment function to save the commitment in the registered commitments. * @example * ```ts * export const miaPlay = new CommitmentBaseModel("mia_play", mia, { * name: "Test", * image: "https://image.jpg", * executionType: ExecutionTypeEnum.INTERACTION, * onRun: (commitment) => { * // Do something * } * }) * saveCommitment(miaPlay) * ``` */ declare class CommitmentBaseModel extends CommitmentStoredClass { /** * @param id The id of the commitment, it must be unique. * @param character The character or characters that are in the commitment and so in the room. * @param props The properties of the commitment. */ constructor(id: string, character: (CharacterInterface$1 | CharacterIdType$1) | (CharacterInterface$1 | CharacterIdType$1)[] | undefined, props: CommitmentProps); private _name; /** * The name of the commitment. */ get name(): string; private _image?; /** * The image of the commitment. */ get image(): string | undefined; private _icon?; /** * The icon of the commitment. */ get icon(): string | undefined; private defaultDisabled; /** * Whether is disabled. You can also pass a Pixi'VN flag name. */ get disabled(): boolean; set disabled(value: boolean | string); private defaultHidden; /** * Whether is hidden. You can also pass a Pixi'VN flag name. */ get hidden(): boolean; set hidden(value: boolean | string); } declare abstract class NavigationAbstractClass extends StoredClassModel implements NavigationAbstractInterface { constructor(categoryId: string, id: string, activities?: (ActivityInterface | ActivityIdType)[]); private readonly defaultActivitiesIds; private get activeActivityScheduling(); private get excludedActivitiesScheduling(); private removeActivityScheduling; private editActivityScheduling; private editExcludedActivityScheduling; private get additionalActivitiesIds(); private get excludedActivitiesIds(); get activitiesIds(): string[]; addActivity(activity: ActivityInterface | ActivityIdType, options?: ActiveScheduling): void; removeActivity(activity: ActivityInterface | ActivityIdType): void; clearExpiredActivities(): void; get activities(): ActivityInterface[]; } declare class LocationStoredClass extends NavigationAbstractClass implements LocationInternalInterface { /** * The map where the location is. */ private readonly _map; constructor(id: string, /** * The map where the location is. */ _map: MapInterface, activities?: (ActivityInterface | ActivityIdType)[]); get map(): MapInterface; get rooms(): RoomInterface[]; } /** * The base model of a location. I suggest you extend this class to create your own location model. * @example * ```typescript * export const mcHome = new LocationBaseModel('mc_home', mainMap, { * name: 'MC Home', * icon: "https://icon.jpg", * }); * ``` */ declare class LocationBaseModel extends LocationStoredClass implements LocationInternalInterface { /** * @param id The id of the location, it must be unique. * @param map The map where the location is. * @param props The properties of the location. */ constructor(id: string, map: MapInterface, props?: LocationBaseModelProps); private defaultName; /** * The name of the location. * If you set undefined, it will return the initial value of name. */ get name(): string; set name(value: string | undefined); private defaultDisabled; /** * Whether is disabled. If it is a string, it is a Pixi'VN flag name. */ get disabled(): boolean; set disabled(value: boolean | string); private defaultHidden; /** * Whether is hidden. If it is a string, it is a Pixi'VN flag name. */ get hidden(): boolean; set hidden(value: boolean | string); private _icon?; /** * The icon of the location. */ get icon(): string | undefined; } declare class MapStoredClass extends NavigationAbstractClass implements MapBaseInternalInterface { constructor(id: string, activities?: (ActivityInterface | ActivityIdType)[]); get locations(): LocationInterface[]; } /** * The base model of a map. I suggest you extend this class to create your own map model. * @example * ```typescript * export const mainMap = new MapBaseModel('main_map', { * name: 'Main Map', * image: "https://image.jpg", * }); * ``` */ declare class MapBaseModel extends MapStoredClass implements MapBaseInternalInterface { /** * @param id The id of the map, it must be unique. * @param props The properties of the map. */ constructor(id: string, props?: MapBaseModelProps); private defaultName; /** * The name of the map. * If you set undefined, it will return the initial value of name. */ get name(): string; set name(value: string | undefined); private _image?; /** * The image of the map. */ get image(): string | undefined; } declare class RoomStoredClass extends NavigationAbstractClass implements RoomBaseInternalInterface { private readonly _location; constructor(id: string, /** * The location where the room is. */ location: LocationInterface, activities?: (ActivityInterface | ActivityIdType)[] | { activities: (ActivityInterface | ActivityIdType)[]; routine: (CommitmentInterface | CommitmentIdType)[]; }); get routine(): CommitmentInterface[]; addCommitment(commitment: CommitmentInterface | CommitmentIdType, options?: ActiveScheduling): void; removeCommitment(commitment: CommitmentInterface | CommitmentIdType): void; get location(): LocationInterface; get characters(): CharacterInterface$1[]; get automaticFunctions(): OnRunAsyncFunction[]; } /** * The base model of a room. I suggest you extend this class to create your own room model. * **You must use the {@link RegisteredRooms.add} function to save the room in the registered rooms.** * @example * ```ts * export const mcRoom = new RoomBaseModel('mc_room', mcHome, { * name: "MC Room", * icon: "https://icon.jpg", * image: "https://image.jpg", * }) * RegisteredRooms.add(mcRoom) * ``` */ declare class RoomBaseModel extends RoomStoredClass { /** * @param id The id of the room, it must be unique. * @param location The location where the room is. * @param props The properties of the room. */ constructor(id: string, location: LocationInterface, props?: RoomBaseModelProps); private defaultName; /** * The name. * If you set undefined, it will return the initial value of name. */ get name(): string; set name(value: string | undefined); private _image?; /** * The image of the room. */ get image(): string | undefined; private defaultDisabled; /** * Whether is disabled. If it is a string, it is a Pixi'VN flag name. */ get disabled(): boolean; set disabled(value: boolean | string); private defaultHidden; /** * Whether is hidden. If it is a string, it is a Pixi'VN flag name. */ get hidden(): boolean; set hidden(value: boolean | string); private _icon?; /** * The function for rendering the icon of the room. */ get icon(): string | undefined; } interface QuestStoredClassProps { /** * The function that will be executed when the quest starts. */ onStart?: OnRunEvent<QuestInterface>; /** * @deprecated Use {@link onContinue} instead. */ onNextStage?: OnRunEvent<QuestInterface>; /** * The function that will be executed when a stage end in the quest. */ onContinue?: OnRunEvent<QuestInterface>; } declare class QuestStoredClass extends StoredClassModel implements QuestBaseInternalInterface { private readonly _stages; constructor(id: string, _stages: StageInterface[], props?: QuestStoredClassProps); get stages(): StageInterface[]; get currentStageIndex(): number | undefined; private set currentStageIndex(value); get currentStage(): StageInterface | undefined; get started(): boolean; get completed(): boolean; get inProgress(): boolean; get failed(): boolean; set failed(value: boolean); private _onStart?; get onStart(): undefined | OnRunEvent<QuestInterface>; private _onContinue?; get onContinue(): undefined | OnRunEvent<QuestInterface>; get onNextStage(): undefined | OnRunEvent<QuestInterface>; start(props: OnRunProps): Promise<void>; /** * @deprecated Use {@link advanceIfCompleted} instead. */ goNextIfCompleted(props: OnRunProps): Promise<boolean>; advanceIfCompleted(props: OnRunProps): Promise<boolean>; /** * @deprecated Use {@link continue} instead. */ goNext(props: OnRunProps): Promise<boolean>; continue(props: OnRunProps): Promise<boolean>; /** * @deprecated Use {@link advanceUnconditionally} instead. */ forceGoNext(props: OnRunProps): Promise<boolean>; advanceUnconditionally(props: OnRunProps): Promise<boolean>; get currentStageMustStart(): boolean; startCurrentStage(props: OnRunProps): Promise<void>; } declare class QuestBaseModel extends QuestStoredClass { constructor(id: string, stages: StageInterface[], props: QuestProps); private _name; /** * The name of the quest. */ get name(): string; private _description; /** * The description of the quest. */ get description(): string; private _icon?; /** * Icon of the quest. */ get icon(): string | undefined; private _image?; /** * Image of the quest. */ get image(): string | undefined; private _inDevelopment; /** * If the quest is in development. */ get inDevelopment(): boolean; } interface StageStoredClassProps { /** * The function that will be executed when the stage starts. */ onStart?: OnRunEvent<StageInterface>; /** * The function that will be executed when the stage ends. */ onEnd?: OnRunEvent<StageInterface>; /** * The number of day/date required to start the stage. * @example If the value is 3, and the previous stage ends on day 1, the stage will start on day 4. */ deltaDateRequired?: number; /** * The quests required to start the stage. * @default [] */ questsRequired?: QuestsRequiredType[]; } declare class StageStoredClass extends StoredClassModel implements StageBaseInternalInterface { constructor(id: string, props?: StageStoredClassProps); private _onStart?; get onStart(): undefined | OnRunEvent<StageInterface>; private _onEnd?; get onEnd(): undefined | OnRunEvent<StageInterface>; get completed(): boolean; set completed(value: boolean); get started(): boolean; set started(value: boolean); private get inizializeDate(); private set inizializeDate(value); get startDate(): number | undefined; get canStart(): boolean; inizialize(): void; start(props: OnRunProps): Promise<void>; private _deltaDateRequired?; get deltaDateRequired(): number; private _questsRequired; get questsRequired(): QuestsRequiredType[]; } declare class StageBaseModel extends StageStoredClass { constructor(id: string, props: StageProps); private _name; /** * The name of the stage. */ get name(): string; private _description; /** * The description of the stage. */ get description(): string; private _adviceDescription; /** * The advice description of the stage. */ get adviceDescription(): string; private _image?; /** * The image of the stage. */ get image(): string | undefined; private _flags; /** * The list of flags that the player must complete to finish the stage. */ get flags(): StageFlags[]; private _flagsRequired; /** * The list of flags required to start the stage. */ get flagsRequired(): StageFlags[]; private _requestDescriptionToStart; /** * The description of the request to start the stage. */ get requestDescriptionToStart(): string; get completed(): boolean; set completed(value: boolean); get canStart(): boolean; } declare const nqtr: { handlers: typeof handlers$1; registries: typeof registries; ActivityBaseModel: typeof ActivityBaseModel; ActivityStoredClass: typeof ActivityStoredClass; CommitmentBaseModel: typeof CommitmentBaseModel; CommitmentStoredClass: typeof CommitmentStoredClass; LocationBaseModel: typeof LocationBaseModel; LocationStoredClass: typeof LocationStoredClass; MapBaseModel: typeof MapBaseModel; MapStoredClass: typeof MapStoredClass; RoomBaseModel: typeof RoomBaseModel; RoomStoredClass: typeof RoomStoredClass; QuestBaseModel: typeof QuestBaseModel; QuestStoredClass: typeof QuestStoredClass; StageBaseModel: typeof StageBaseModel; StageStoredClass: typeof StageStoredClass; }; export { ActiveScheduling, ActivityBaseModel, ActivityInterface, type ActivityProps, ActivityStoredClass, type ActivityStoredClassProps, CommitmentBaseModel, type CommitmentInfo, CommitmentInterface, type CommitmentProps, CommitmentStoredClass, type CommitmentStoredClassProps, DateSchedulingInterface, ExecutionType, LocationBaseModel, type LocationBaseModelProps, LocationInterface, LocationStoredClass, MapBaseModel, type MapBaseModelProps, MapInterface, MapStoredClass, OnRunAsyncFunction, OnRunEvent, OnRunProps, QuestBaseModel, QuestInterface, type QuestProps, QuestStoredClass, type QuestStoredClassProps, QuestsRequiredType, RoomBaseModel, type RoomBaseModelProps, RoomInterface, RoomStoredClass, StageBaseModel, StageInterface, type StageProps, StageStoredClass, type StageStoredClassProps, TimeSchedulingInterface, nqtr as default };