@novely/core 0.0.0-alpha.2 → 0.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.d.ts +229 -0
  2. package/package.json +1 -1
@@ -0,0 +1,229 @@
1
+ import { BaseTranslationStrings, SetupT9N } from '@novely/t9n';
2
+ export { BaseTranslationStrings } from '@novely/t9n';
3
+
4
+ type Name<Keys extends string = string> = string | Record<Keys, string>;
5
+ type Emotions<Keys extends string = string> = Record<Keys, string | {
6
+ body: Record<'left' | 'right', string>;
7
+ head: string;
8
+ }>;
9
+ type Character<LanguageKeys extends string = string> = {
10
+ name: Name<LanguageKeys>;
11
+ color: string;
12
+ emotions: Emotions;
13
+ };
14
+
15
+ type Thenable<T> = T | Promise<T>;
16
+ type PathItem = [null, number | string] | ['choice' & Record<never, never>, number] | ['condition' & Record<never, never>, string];
17
+ type Path = PathItem[];
18
+ /**
19
+ * Значения, которые можно сохранить в `state`.
20
+ */
21
+ type StateValues = null | string | number | boolean | StateValues[] | {
22
+ [name: string]: StateValues;
23
+ };
24
+ type State = Record<string, StateValues>;
25
+ type SaveDate = number;
26
+ type SaveType = "manual" | "auto";
27
+ type SaveMeta = [SaveDate, SaveType];
28
+ type Save = [Path, State, SaveMeta];
29
+ type Lang = string;
30
+ type StorageMeta = [Lang];
31
+ type StorageData = {
32
+ saves: Save[];
33
+ meta: StorageMeta;
34
+ };
35
+ type Stack = {
36
+ value: Save;
37
+ back(): void;
38
+ push(value: Save): void;
39
+ clear(): void;
40
+ };
41
+
42
+ type ValidAction = [keyof DefaultActionProxyProvider, Parameters<DefaultActionProxyProvider[keyof DefaultActionProxyProvider]>];
43
+ type Story = Record<string, ValidAction[]>;
44
+ type DialogContent = string | ((lang: string, obj: Record<string, unknown>) => string);
45
+ type ChoiceContent = string | ((lang: string, obj: Record<string, unknown>) => string);
46
+ type CustomHandlerGetResultDataFunction = {
47
+ (): Record<string, unknown>;
48
+ (data: Record<string, unknown>): void;
49
+ };
50
+ type CustomHandlerGetResultSkipClearOnGoingBackFunction = {
51
+ (): boolean;
52
+ (value: boolean): void;
53
+ };
54
+ type CustomHandlerGetResult = {
55
+ delete: () => void;
56
+ /**
57
+ * Данные
58
+ */
59
+ data: CustomHandlerGetResultDataFunction;
60
+ /**
61
+ * Элемент слоя
62
+ */
63
+ element: HTMLDivElement;
64
+ /**
65
+ * Будет ли запускаться очистка при проходе назад
66
+ */
67
+ skipClearOnGoingBack: CustomHandlerGetResultSkipClearOnGoingBackFunction;
68
+ /**
69
+ * Устанавливает обработчик очистки
70
+ */
71
+ clear: (fn: () => void) => void;
72
+ };
73
+ type CustomHandlerFunction = (get: (id: string) => CustomHandlerGetResult, goingBack: boolean, resolve: () => void) => Thenable<void>;
74
+ type CustomHandler = CustomHandlerFunction & {
75
+ callOnlyLatest?: boolean;
76
+ requireUserAction?: boolean;
77
+ };
78
+ type ActionProxyProvider<Characters extends Record<string, Character>> = {
79
+ choice: (...choices: ([ChoiceContent, ValidAction[]] | [ChoiceContent, ValidAction[], () => boolean])[]) => ValidAction;
80
+ clear: () => ValidAction;
81
+ condition: <T extends string>(condition: () => T, variants: Record<T, ValidAction[]>) => ValidAction;
82
+ dialog: {
83
+ <C extends keyof Characters>(person: C, content: DialogContent, emotion?: keyof Characters[C]['emotions']): ValidAction;
84
+ (person: undefined, content: DialogContent, emotion?: undefined): ValidAction;
85
+ (person: string, content: DialogContent, emotion?: undefined): ValidAction;
86
+ };
87
+ end: () => ValidAction;
88
+ showBackground: (background: string) => ValidAction;
89
+ playMusic: (audio: string) => ValidAction;
90
+ stopMusic: (audio: string) => ValidAction;
91
+ jump: (scene: string) => ValidAction;
92
+ showCharacter: {
93
+ <C extends keyof Characters>(character: C, emotion: keyof Characters[C]['emotions'], className?: string, style?: string): ValidAction;
94
+ };
95
+ hideCharacter: {
96
+ <C extends keyof Characters>(character: C, className?: string, style?: string, duration?: number): ValidAction;
97
+ };
98
+ wait: (time: number) => ValidAction;
99
+ function: (fn: () => Thenable<void>) => ValidAction;
100
+ input: (question: string, onInput: (meta: {
101
+ input: HTMLInputElement;
102
+ error: (error: string) => void;
103
+ event: InputEvent & {
104
+ currentTarget: HTMLInputElement;
105
+ };
106
+ }) => void, setup?: (input: HTMLInputElement) => void) => ValidAction;
107
+ custom: (handler: CustomHandler) => ValidAction;
108
+ vibrate: (...pattern: number[]) => ValidAction;
109
+ next: () => ValidAction;
110
+ };
111
+ type DefaultActionProxyProvider = ActionProxyProvider<Record<string, Character>>;
112
+ type GetActionParameters<T extends Capitalize<keyof DefaultActionProxyProvider>> = Parameters<DefaultActionProxyProvider[Uncapitalize<T>]>;
113
+
114
+ interface LocalStorageStorageSettings {
115
+ key: string;
116
+ }
117
+ interface Storage {
118
+ get: () => Promise<StorageData>;
119
+ set: (data: StorageData) => Promise<void>;
120
+ }
121
+ declare const localStorageStorage: (options: LocalStorageStorageSettings) => Storage;
122
+
123
+ type Stored<T> = {
124
+ subscribe: (cb: (value: T) => void) => () => void;
125
+ update: (fn: (prev: T) => T) => void;
126
+ get: () => T;
127
+ };
128
+
129
+ interface CharacterHandle {
130
+ canvas: HTMLCanvasElement;
131
+ ctx: CanvasRenderingContext2D;
132
+ withEmotion: (emotion: string) => () => void;
133
+ append: (className?: string, style?: string) => void;
134
+ remove: (className?: string, style?: string, duration?: number) => (resolve: () => void) => void;
135
+ emotions: Record<string, HTMLImageElement | Record<"head" | "left" | "right", HTMLImageElement>>;
136
+ }
137
+ interface AudioHandle {
138
+ element: HTMLAudioElement;
139
+ stop: () => void;
140
+ pause: () => void;
141
+ play: () => void;
142
+ }
143
+ interface RendererStore {
144
+ characters: Record<string, CharacterHandle>;
145
+ audio: Partial<Record<"music", AudioHandle>>;
146
+ }
147
+ type Renderer = {
148
+ character: (character: string) => CharacterHandle;
149
+ background: (background: string) => void;
150
+ dialog: (content: string, character?: string, emotion?: string) => (resolve: () => void) => void;
151
+ choices: (choices: ([string, ValidAction[]] | [string, ValidAction[], () => boolean])[]) => (resolve: (selected: number) => void) => void;
152
+ input: (question: string, onInput: Parameters<DefaultActionProxyProvider['input']>[1], setup?: Parameters<DefaultActionProxyProvider['input']>[2]) => (resolve: () => void) => void;
153
+ music: (source: string, method: keyof RendererStore['audio']) => AudioHandle;
154
+ clear: (goingBack: boolean) => (resolve: () => void) => void;
155
+ custom: (fn: Parameters<DefaultActionProxyProvider['custom']>[0], goingBack: boolean, push: () => void) => Thenable<void>;
156
+ store: RendererStore;
157
+ ui: {
158
+ /**
159
+ * Показывает экран, скрывает другие
160
+ */
161
+ showScreen(name: "mainmenu" | "game" | "saves" | "settings" | 'loading'): void;
162
+ };
163
+ };
164
+ type RendererInit = {
165
+ characters: Record<string, Character>;
166
+ storage: Storage;
167
+ set: (save: Save) => Promise<void>;
168
+ restore: (save?: Save) => Promise<void>;
169
+ save: (override?: boolean, type?: Save[2][1]) => Promise<void>;
170
+ newGame: () => void;
171
+ stack: Stack;
172
+ languages: string[];
173
+ /**
174
+ * Translation function
175
+ */
176
+ t: (key: BaseTranslationStrings, lang: string) => string;
177
+ /**
178
+ * Store that tracks data updates
179
+ */
180
+ $: Stored<StorageData>;
181
+ };
182
+
183
+ interface NovelyInit<Languages extends string, Characters extends Record<string, Character<Languages>>, Inter extends ReturnType<SetupT9N<Languages>>> {
184
+ /**
185
+ * An array of languages supported by the game.
186
+ */
187
+ languages: Languages[];
188
+ /**
189
+ * An object containing the characters in the game.
190
+ */
191
+ characters: Characters;
192
+ /**
193
+ * An object that provides access to the game's storage system.
194
+ */
195
+ storage: Storage;
196
+ /**
197
+ * A function that returns a Renderer object used to display the game's content
198
+ */
199
+ renderer: (characters: RendererInit) => Renderer;
200
+ /**
201
+ * An optional property that specifies the initial screen to display when the game starts
202
+ */
203
+ initialScreen?: "mainmenu" | "game" | "saves" | "settings";
204
+ /**
205
+ * An object containing the translation functions used in the game
206
+ */
207
+ t9n: Inter;
208
+ /**
209
+ * An optional property that specifies whether to preload assets when the game starts
210
+ */
211
+ assetsPreload?: boolean;
212
+ /**
213
+ * An optional property that specifies whether the game should use a single save.
214
+ */
215
+ singleSave?: boolean;
216
+ }
217
+ type Novely = <Languages extends string, Characters extends Record<string, Character<Languages>>, Inter extends ReturnType<SetupT9N<Languages>>>(init: NovelyInit<Languages, Characters, Inter>) => {
218
+ withStory: (s: Story) => void;
219
+ action: ActionProxyProvider<Characters>;
220
+ render: () => void;
221
+ state: {
222
+ (value: State | ((prev: State) => State)): void;
223
+ (): State;
224
+ };
225
+ t: Inter['t'];
226
+ };
227
+ declare const novely: Novely;
228
+
229
+ export { ActionProxyProvider, AudioHandle, Character, CharacterHandle, CustomHandler, CustomHandlerGetResult, CustomHandlerGetResultDataFunction, CustomHandlerGetResultSkipClearOnGoingBackFunction, DefaultActionProxyProvider, Emotions, GetActionParameters, Path, Renderer, RendererInit, RendererStore, Storage, StorageData, Stored, Story, Thenable, ValidAction, localStorageStorage, novely };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novely/core",
3
3
  "description": "Novely - powerful visual novel engine for creating interactive stories and games with branching narratives and rich multimedia content.",
4
- "version": "0.0.0-alpha.2",
4
+ "version": "0.0.0-alpha.3",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "types": "./dist/index.d.ts",