slifer 0.2.8 → 0.3.0

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.
@@ -1,52 +1,62 @@
1
- import { type Pointer } from 'bun:ffi';
2
- import Vector2 from './vector2';
3
- import { libsdl } from '../ffi';
4
-
5
- /** @internal */
6
- export default class Window {
7
-
8
- public static pointer: Pointer;
9
- public static size: Vector2;
10
-
11
- private static centerPos = 0x2fff0000;
12
-
13
-
14
-
15
- public static createWindow(title: string, size: Vector2) : void {
16
- const winPointer = libsdl.symbols.SDL_CreateWindow(
17
- Buffer.from(title + '\x00'),
18
- this.centerPos,
19
- this.centerPos,
20
- size.x,
21
- size.y,
22
- 0
23
- );
24
-
25
- if (winPointer == null) throw `Window creation failed.`;
26
- this.pointer = winPointer;
27
- this.size = size;
28
- }
29
-
30
- public setTitle(title: string): void {
31
- libsdl.symbols.SDL_SetWindowTitle(
32
- Window.pointer,
33
- Buffer.from(title + "\x00")
34
- );
35
- }
36
-
37
- public setFullscreen(flag: boolean) {
38
- libsdl.symbols.SDL_SetWindowFullscreen(Window.pointer, Number(flag));
39
- }
40
-
41
- public setPosition(position: Vector2) {
42
- libsdl.symbols.SDL_SetWindowPosition(
43
- Window.pointer,
44
- position.x,
45
- position.y
46
- );
47
- }
48
-
49
- public centerWindow() {
50
- this.setPosition(new Vector2(Window.centerPos, Window.centerPos));
51
- }
52
- }
1
+ import { type Pointer } from 'bun:ffi';
2
+ import Vector2 from './vector2';
3
+ import Image from './image';
4
+ import { libsdl } from '../ffi';
5
+
6
+ /** @internal */
7
+ export default class Window {
8
+
9
+ public static pointer: Pointer;
10
+ public static size: Vector2;
11
+
12
+ private static centerPos = 0x2fff0000;
13
+
14
+
15
+
16
+ public static createWindow(title: string, width: number, height: number) : void {
17
+ const winPointer = libsdl.symbols.SDL_CreateWindow(
18
+ Buffer.from(title + '\x00'),
19
+ this.centerPos,
20
+ this.centerPos,
21
+ width,
22
+ height,
23
+ 0
24
+ );
25
+
26
+ if (winPointer == null) throw `Window creation failed.`;
27
+ this.pointer = winPointer;
28
+ this.size = new Vector2(width, height);
29
+ }
30
+
31
+ public setTitle(title: string): void {
32
+ libsdl.symbols.SDL_SetWindowTitle(
33
+ Window.pointer,
34
+ Buffer.from(title + "\x00")
35
+ );
36
+ }
37
+
38
+ public setFullscreen(flag: boolean) {
39
+ libsdl.symbols.SDL_SetWindowFullscreen(Window.pointer, Number(flag));
40
+ }
41
+
42
+ public setPosition(position: Vector2) {
43
+ libsdl.symbols.SDL_SetWindowPosition(
44
+ Window.pointer,
45
+ position.x,
46
+ position.y
47
+ );
48
+ }
49
+
50
+ public centerWindow() {
51
+ this.setPosition(new Vector2(Window.centerPos, Window.centerPos));
52
+ }
53
+
54
+ public setSize(width: number, height: number) {
55
+ libsdl.symbols.SDL_SetWindowSize(Window.pointer, width, height);
56
+ }
57
+
58
+ public setIcon(image: Image) {
59
+ libsdl.symbols.SDL_SetWindowIcon(Window.pointer, (image as any).pointer);
60
+ }
61
+
62
+ }
package/src/engine.ts CHANGED
@@ -1,30 +1,30 @@
1
- import { libsdl, libimage, libttf, libmixer } from "./ffi";
2
-
3
- export function initSDL() {
4
- const initVideo = 0x00000020;
5
- const initAudio = 0x00000010;
6
- const baseInit = libsdl.symbols.SDL_Init(initVideo + initAudio);
7
- if (baseInit != 0) throw `SDL failed to initialize`;
8
- }
9
-
10
- export function initSDLImage() {
11
- const imageInit = libimage.symbols.IMG_Init(3);
12
- if (imageInit != 3) throw `SDL Image failed to initialize`;
13
- }
14
-
15
- export function initSDLTypeFont() {
16
- const ttfInit = libttf.symbols.TTF_Init();
17
- if (ttfInit != 0) throw `SDL TTF failed to initialize`;
18
- }
19
-
20
- export function initSDLMixer() {
21
- const mixInit = libmixer.symbols.Mix_OpenAudio(22050, null, 2, 4096);
22
- if (mixInit != 0) throw `SDL Audio failed to initialize`;
23
- }
24
-
25
- export function initLibraries(): void {
26
- initSDL();
27
- initSDLImage();
28
- initSDLTypeFont();
29
- initSDLMixer();
30
- }
1
+ import { libsdl, libimage, libttf, libmixer } from "./ffi";
2
+
3
+ export function initSDL() {
4
+ const initVideo = 0x00000020;
5
+ const initAudio = 0x00000010;
6
+ const baseInit = libsdl.symbols.SDL_Init(initVideo + initAudio);
7
+ if (baseInit != 0) throw `SDL failed to initialize`;
8
+ }
9
+
10
+ export function initSDLImage() {
11
+ const imageInit = libimage.symbols.IMG_Init(3);
12
+ if (imageInit != 3) throw `SDL Image failed to initialize`;
13
+ }
14
+
15
+ export function initSDLTypeFont() {
16
+ const ttfInit = libttf.symbols.TTF_Init();
17
+ if (ttfInit != 0) throw `SDL TTF failed to initialize`;
18
+ }
19
+
20
+ export function initSDLMixer() {
21
+ const mixInit = libmixer.symbols.Mix_OpenAudio(22050, null, 2, 4096);
22
+ if (mixInit != 0) throw `SDL Audio failed to initialize`;
23
+ }
24
+
25
+ export function initLibraries(): void {
26
+ initSDL();
27
+ initSDLImage();
28
+ initSDLTypeFont();
29
+ initSDLMixer();
30
+ }