slifer 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/ffi.ts +15 -0
- package/src/global.ts +1 -0
- package/src/modules/graphics.ts +2 -0
- package/src/modules/keyboard.ts +2 -0
- package/src/modules/mouse.ts +2 -0
- package/src/slifer.ts +34 -1
- package/tsconfig.json +1 -0
package/package.json
CHANGED
package/src/ffi.ts
CHANGED
@@ -28,6 +28,7 @@ if (process.platform == "win32") {
|
|
28
28
|
libTTFImport = await import("../libs/libSDL2_ttf.so");
|
29
29
|
}
|
30
30
|
|
31
|
+
/** @internal */
|
31
32
|
export const libsdl = dlopen(libSDLImport.default, {
|
32
33
|
SDL_Init: {
|
33
34
|
args: [FFIType.int],
|
@@ -156,6 +157,10 @@ export const libsdl = dlopen(libSDLImport.default, {
|
|
156
157
|
args: ["pointer"],
|
157
158
|
returns: "void",
|
158
159
|
},
|
160
|
+
SDL_MaximizeWindow: {
|
161
|
+
args: ["pointer"],
|
162
|
+
returns: 'void'
|
163
|
+
},
|
159
164
|
SDL_GetShapedWindowMode: {
|
160
165
|
args: ["pointer", "pointer"],
|
161
166
|
returns: "int",
|
@@ -188,8 +193,17 @@ export const libsdl = dlopen(libSDLImport.default, {
|
|
188
193
|
],
|
189
194
|
returns: "int",
|
190
195
|
},
|
196
|
+
SDL_SetWindowSize: {
|
197
|
+
args: ['pointer', 'int', 'int'],
|
198
|
+
returns: 'void'
|
199
|
+
},
|
200
|
+
SDL_SetWindowTitle: {
|
201
|
+
args: ['pointer', 'cstring'],
|
202
|
+
returns: 'void'
|
203
|
+
}
|
191
204
|
});
|
192
205
|
|
206
|
+
/** @internal */
|
193
207
|
export const libimage = dlopen(libImageImport.default, {
|
194
208
|
IMG_Init: {
|
195
209
|
args: ["int"],
|
@@ -201,6 +215,7 @@ export const libimage = dlopen(libImageImport.default, {
|
|
201
215
|
},
|
202
216
|
});
|
203
217
|
|
218
|
+
/** @internal */
|
204
219
|
export const libttf = dlopen(libTTFImport.default, {
|
205
220
|
TTF_Init: {
|
206
221
|
returns: "int",
|
package/src/global.ts
CHANGED
package/src/modules/graphics.ts
CHANGED
@@ -3,6 +3,7 @@ import Global from "../global";
|
|
3
3
|
import { type Pointer, ptr } from 'bun:ffi';
|
4
4
|
import path from 'path';
|
5
5
|
|
6
|
+
/** @internal */
|
6
7
|
class Graphics {
|
7
8
|
/**
|
8
9
|
* Slifers draw function. Used to draw everything to the screen.
|
@@ -153,4 +154,5 @@ class Color {
|
|
153
154
|
}
|
154
155
|
}
|
155
156
|
|
157
|
+
/** @internal */
|
156
158
|
export default Graphics;
|
package/src/modules/keyboard.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/** @internal */
|
1
2
|
class Keyboard {
|
2
3
|
|
3
4
|
static downKeyMap = new Map<string, boolean>();
|
@@ -75,4 +76,5 @@ type keys = 'a' |'b' |'c' |'d' |'e' |'f' |'g' |'h' |'i' |'j' |'k' |'l' |'m' |'n'
|
|
75
76
|
'left ctrl' |
|
76
77
|
'escape';
|
77
78
|
|
79
|
+
/** @internal */
|
78
80
|
export default Keyboard;
|
package/src/modules/mouse.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { libsdl } from "../ffi";
|
2
2
|
import { ptr } from 'bun:ffi';
|
3
3
|
|
4
|
+
/** @internal */
|
4
5
|
class Mouse {
|
5
6
|
|
6
7
|
static downKeyMap = new Map<string, boolean>();
|
@@ -97,4 +98,5 @@ class Mouse {
|
|
97
98
|
|
98
99
|
type buttons = 'left' | 'middle' | 'right';
|
99
100
|
|
101
|
+
/** @internal */
|
100
102
|
export default Mouse;
|
package/src/slifer.ts
CHANGED
@@ -4,7 +4,34 @@ import { ptr } from "bun:ffi";
|
|
4
4
|
import Graphics from "./modules/graphics";
|
5
5
|
import Keyboard from "./modules/keyboard";
|
6
6
|
import Mouse from "./modules/mouse";
|
7
|
+
import { version } from '../package.json';
|
7
8
|
|
9
|
+
/** @internal */
|
10
|
+
class Window {
|
11
|
+
public width: number;
|
12
|
+
public height: number;
|
13
|
+
public title: string;
|
14
|
+
|
15
|
+
constructor(title: string, width: number, height: number) {
|
16
|
+
this.width = width;
|
17
|
+
this.height = height;
|
18
|
+
this.title = title;
|
19
|
+
}
|
20
|
+
|
21
|
+
setSize(width: number, height: number) : void {
|
22
|
+
libsdl.symbols.SDL_SetWindowSize(Global.ptrWindow, width, height);
|
23
|
+
}
|
24
|
+
|
25
|
+
setTitle(title: string) : void {
|
26
|
+
libsdl.symbols.SDL_SetWindowTitle(Global.ptrWindow, Buffer.from(title+'\x00'));
|
27
|
+
}
|
28
|
+
|
29
|
+
setFullscreen(flag: boolean) {
|
30
|
+
libsdl.symbols.SDL_SetWindowFullscreen(Global.ptrWindow, Number(flag));
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
/** @interal */
|
8
35
|
export class SliferClass {
|
9
36
|
isRunning: boolean = true;
|
10
37
|
|
@@ -45,7 +72,7 @@ export class SliferClass {
|
|
45
72
|
* @param width Width of window
|
46
73
|
* @param height Height of window
|
47
74
|
*/
|
48
|
-
createWindow(title: string, width: number, height: number):
|
75
|
+
createWindow(title: string, width: number, height: number): Window {
|
49
76
|
// Creating cstring buffer from string
|
50
77
|
const _title = Buffer.from(title + "\x00");
|
51
78
|
|
@@ -65,6 +92,8 @@ export class SliferClass {
|
|
65
92
|
const _ren = libsdl.symbols.SDL_CreateRenderer(Global.ptrWindow, -1, 0);
|
66
93
|
if (_ren == null) throw `Renderer Creation failed`;
|
67
94
|
Global.ptrRenderer = _ren;
|
95
|
+
|
96
|
+
return new Window(title, width, height);
|
68
97
|
}
|
69
98
|
|
70
99
|
/**
|
@@ -123,4 +152,8 @@ export class SliferClass {
|
|
123
152
|
libsdl.symbols.SDL_DestroyWindow(Global.ptrWindow);
|
124
153
|
libsdl.symbols.SDL_Quit();
|
125
154
|
}
|
155
|
+
|
156
|
+
getVersion() {
|
157
|
+
return version;
|
158
|
+
}
|
126
159
|
}
|