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.
package/src/slifer.ts CHANGED
@@ -1,87 +1,92 @@
1
- import { libsdl } from "./ffi";
2
- import Window from "./engine/window";
3
- import { ptr } from "bun:ffi";
4
- import { initLibraries } from "./engine";
5
- import { version } from "../package.json";
6
- import type Vector2 from "./engine/vector2";
7
- import Graphics from "./modules/graphics";
8
- import Keyboard from "./modules/keyboard";
9
- import Mouse from "./modules/mouse";
10
- import Render from "./engine/render";
11
- import Color from './engine/color';
12
-
13
- class Slifer {
14
- public isRunning: boolean;
15
- public deltaTime: number;
16
-
17
- // Modules
18
- public Graphics = new Graphics();
19
- public Keyboard = new Keyboard();
20
- public Mouse = new Mouse();
21
-
22
- private start = 0;
23
- private end = 0;
24
- private black : Color;
25
-
26
- constructor() {
27
- initLibraries();
28
- this.isRunning = true;
29
- this.deltaTime = 0;
30
- this.black = new Color(0,0,0,0);
31
- }
32
-
33
- public createWindow(title: string, size: Vector2): Window {
34
- Window.createWindow(title, size);
35
- Render.createRenderer(size.x, size.y);
36
-
37
- this.start = Number(libsdl.symbols.SDL_GetTicks64());
38
-
39
- return new Window();
40
- }
41
-
42
- public shouldClose(): boolean {
43
- libsdl.symbols.SDL_RenderClear(Render.pointer);
44
-
45
- const eventArray = new Uint16Array(32);
46
- const event = libsdl.symbols.SDL_PollEvent(ptr(eventArray));
47
- if (event) {
48
- switch (eventArray[0]) {
49
- case 256:
50
- this.isRunning = false;
51
- break;
52
- case 1024:
53
- Mouse.onMove(eventArray[10], eventArray[12]);
54
- break;
55
- case 1026:
56
- Mouse.onRelease(eventArray[8]);
57
- break;
58
- }
59
- }
60
-
61
-
62
- Keyboard.handleStates();
63
-
64
- Mouse.handleState();
65
-
66
- this.end = Number(libsdl.symbols.SDL_GetTicks64());
67
-
68
- this.deltaTime = (this.end - this.start) / 1000;
69
-
70
- this.start = this.end;
71
-
72
-
73
- return !this.isRunning;
74
- }
75
-
76
- public getVersion(): string {
77
- return "v" + version;
78
- }
79
-
80
- public quit(): void {
81
- libsdl.symbols.SDL_DestroyRenderer(Render.pointer);
82
- libsdl.symbols.SDL_DestroyWindow(Window.pointer);
83
- libsdl.symbols.SDL_Quit();
84
- }
85
- }
86
-
87
- export default Slifer;
1
+ import { libsdl } from "./ffi";
2
+ import Window from "./engine/window";
3
+ import { ptr } from "bun:ffi";
4
+ import { initLibraries } from "./engine";
5
+ import { version } from "../package.json";
6
+ import type Vector2 from "./engine/vector2";
7
+ import Graphics from "./modules/graphics";
8
+ import Keyboard from "./modules/keyboard";
9
+ import Mouse from "./modules/mouse";
10
+ import Render from "./engine/render";
11
+ import Color from './engine/color';
12
+ import Cursor from './engine/cursor';
13
+
14
+ class Slifer {
15
+ public isRunning: boolean;
16
+ public deltaTime: number;
17
+
18
+ // Modules
19
+ public Graphics = new Graphics();
20
+ public Keyboard = new Keyboard();
21
+ public Mouse = new Mouse();
22
+
23
+ private start = 0;
24
+ private end = 0;
25
+ private black : Color;
26
+
27
+ constructor() {
28
+ initLibraries();
29
+ this.isRunning = true;
30
+ this.deltaTime = 0;
31
+ this.black = new Color(0,0,0,0);
32
+ }
33
+
34
+ public createWindow(title: string, width: number, height: number): Window {
35
+ Window.createWindow(title, width, height);
36
+ Render.createRenderer(width, height);
37
+
38
+ this.start = Number(libsdl.symbols.SDL_GetTicks64());
39
+
40
+ return new Window();
41
+ }
42
+
43
+ public setCursor(cursor: Cursor) {
44
+ libsdl.symbols.SDL_SetCursor((cursor as any).pointer);
45
+ }
46
+
47
+ public shouldClose(): boolean {
48
+ libsdl.symbols.SDL_SetRenderDrawColor(Render.pointer, this.black.r, this.black.g, this.black.b, this.black.a);
49
+ libsdl.symbols.SDL_RenderClear(Render.pointer);
50
+
51
+ const eventArray = new Uint16Array(32);
52
+ const event = libsdl.symbols.SDL_PollEvent(ptr(eventArray));
53
+ if (event) {
54
+ switch (eventArray[0]) {
55
+ case 256:
56
+ this.isRunning = false;
57
+ break;
58
+ case 1024:
59
+ Mouse.onMove(eventArray[10], eventArray[12]);
60
+ break;
61
+ case 1026:
62
+ Mouse.onRelease(eventArray[8]);
63
+ break;
64
+ }
65
+ }
66
+
67
+
68
+ Keyboard.handleStates();
69
+
70
+ Mouse.handleState();
71
+
72
+ this.end = Number(libsdl.symbols.SDL_GetTicks64());
73
+
74
+ this.deltaTime = (this.end - this.start) / 1000;
75
+
76
+ this.start = this.end;
77
+
78
+ return !this.isRunning;
79
+ }
80
+
81
+ public getVersion(): string {
82
+ return "v" + version;
83
+ }
84
+
85
+ public quit(): void {
86
+ libsdl.symbols.SDL_DestroyRenderer(Render.pointer);
87
+ libsdl.symbols.SDL_DestroyWindow(Window.pointer);
88
+ libsdl.symbols.SDL_Quit();
89
+ }
90
+ }
91
+
92
+ export default Slifer;
package/tsconfig.json CHANGED
@@ -1,28 +1,28 @@
1
- {
2
- "compilerOptions": {
3
- // Enable latest features
4
- "lib": ["ESNext", "DOM"],
5
- "target": "ESNext",
6
- "module": "ESNext",
7
- "moduleDetection": "force",
8
- "jsx": "react-jsx",
9
- "allowJs": true,
10
-
11
- // Bundler mode
12
- "moduleResolution": "bundler",
13
- "allowImportingTsExtensions": true,
14
- "verbatimModuleSyntax": true,
15
- "noEmit": true,
16
-
17
- // Best practices
18
- "strict": true,
19
- "skipLibCheck": true,
20
- "noFallthroughCasesInSwitch": true,
21
- "stripInternal": true,
22
-
23
- // Some stricter flags (disabled by default)
24
- "noUnusedLocals": false,
25
- "noUnusedParameters": false,
26
- "noPropertyAccessFromIndexSignature": false
27
- }
28
- }
1
+ {
2
+ "compilerOptions": {
3
+ // Enable latest features
4
+ "lib": ["ESNext", "DOM"],
5
+ "target": "ESNext",
6
+ "module": "ESNext",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+
11
+ // Bundler mode
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "noEmit": true,
16
+
17
+ // Best practices
18
+ "strict": true,
19
+ "skipLibCheck": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "stripInternal": true,
22
+
23
+ // Some stricter flags (disabled by default)
24
+ "noUnusedLocals": false,
25
+ "noUnusedParameters": false,
26
+ "noPropertyAccessFromIndexSignature": false
27
+ }
28
+ }
package/.npmignore DELETED
@@ -1,139 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
- npm-debug.log*
5
- yarn-debug.log*
6
- yarn-error.log*
7
- lerna-debug.log*
8
- .pnpm-debug.log*
9
- .vs
10
- .DS_Store
11
- Resources
12
- .idea
13
-
14
- # Diagnostic reports (https://nodejs.org/api/report.html)
15
- report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
16
-
17
- # Runtime data
18
- pids
19
- *.pid
20
- *.seed
21
- *.pid.lock
22
-
23
- # Directory for instrumented libs generated by jscoverage/JSCover
24
- lib-cov
25
-
26
- # Coverage directory used by tools like istanbul
27
- coverage
28
- *.lcov
29
-
30
- # nyc test coverage
31
- .nyc_output
32
-
33
- # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
34
- .grunt
35
-
36
- # Bower dependency directory (https://bower.io/)
37
- bower_components
38
-
39
- # node-waf configuration
40
- .lock-wscript
41
-
42
- # Compiled binary addons (https://nodejs.org/api/addons.html)
43
- build/Release
44
-
45
- # Dependency directories
46
- node_modules/
47
- jspm_packages/
48
-
49
- # Snowpack dependency directory (https://snowpack.dev/)
50
- web_modules/
51
-
52
- # TypeScript cache
53
- *.tsbuildinfo
54
-
55
- # Optional npm cache directory
56
- .npm
57
-
58
- # Optional eslint cache
59
- .eslintcache
60
-
61
- # Optional stylelint cache
62
- .stylelintcache
63
-
64
- # Microbundle cache
65
- .rpt2_cache/
66
- .rts2_cache_cjs/
67
- .rts2_cache_es/
68
- .rts2_cache_umd/
69
-
70
- # Optional REPL history
71
- .node_repl_history
72
-
73
- # Output of 'npm pack'
74
- *.tgz
75
-
76
- # Yarn Integrity file
77
- .yarn-integrity
78
-
79
- # dotenv environment variable files
80
- .env
81
- .env.development.local
82
- .env.test.local
83
- .env.production.local
84
- .env.local
85
-
86
- # parcel-bundler cache (https://parceljs.org/)
87
- .cache
88
- .parcel-cache
89
-
90
- # Next.js build output
91
- .next
92
- out
93
-
94
- # Nuxt.js build / generate output
95
- .nuxt
96
- dist
97
-
98
- # Gatsby files
99
- .cache/
100
- # Comment in the public line in if your project uses Gatsby and not Next.js
101
- # https://nextjs.org/blog/next-9-1#public-directory-support
102
- # public
103
-
104
- # vuepress build output
105
- .vuepress/dist
106
-
107
- # vuepress v2.x temp and cache directory
108
- .temp
109
- .cache
110
-
111
- # Docusaurus cache and generated files
112
- .docusaurus
113
-
114
- # Serverless directories
115
- .serverless/
116
-
117
- # FuseBox cache
118
- .fusebox/
119
-
120
- # DynamoDB Local files
121
- .dynamodb/
122
-
123
- # TernJS port file
124
- .tern-port
125
-
126
- # Stores VSCode versions used for testing VSCode extensions
127
- .vscode-test
128
-
129
- # yarn v2
130
- .yarn/cache
131
- .yarn/unplugged
132
- .yarn/build-state.yml
133
- .yarn/install-state.gz
134
- .pnp.*
135
- test.ts
136
- char.png
137
-
138
- .wakatime-project
139
- libs/
package/bun.lockb DELETED
Binary file
@@ -1,58 +0,0 @@
1
- import { type Pointer, ptr } from 'bun:ffi';
2
- import { libsdl } from '../ffi';
3
- import Image from './image';
4
- import Render from './render';
5
- import Color from './color';
6
-
7
- /** @internal */
8
- export default class Canvas {
9
-
10
- private pointer : Pointer;
11
-
12
- public readonly width;
13
- public readonly height;
14
-
15
- constructor(width: number, height: number) {
16
- const surPointer = libsdl.symbols.SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0)
17
- if (surPointer == null) throw `Canvas creation failed`;
18
- this.pointer = surPointer;
19
- this.width = width;
20
- this.height = height;
21
- }
22
-
23
- private drawBG(color: Color) {
24
- const rect = new Uint32Array(4);
25
- rect[0] = 0;
26
- rect[1] = 0;
27
- rect[2] = this.width;
28
- rect[3] = this.height;
29
-
30
- const _col = ((color.r << 16) + (color.g << 8) + (color.b << 0));
31
-
32
- libsdl.symbols.SDL_FillRect(this.pointer, ptr(rect), _col);
33
- }
34
-
35
- clear() {
36
- this.drawBG(new Color(0, 0, 0, 0));
37
- }
38
-
39
- setBackground(color: Color) {
40
- this.drawBG(color);
41
- }
42
-
43
- draw(drawable: Image | Canvas, x: number, y: number, scaleX?: number, scaleY?: number) : void {
44
- const destArray = new Uint32Array(4);
45
- destArray[0] = x;
46
- destArray[1] = y;
47
- destArray[2] = drawable.width * (scaleX ? scaleX : 1);
48
- destArray[3] = drawable.height * (scaleY ? scaleY : 1);
49
-
50
- libsdl.symbols.SDL_UpperBlitScaled(
51
- (drawable as any).pointer,
52
- null,
53
- this.pointer,
54
- ptr(destArray)
55
- );
56
- }
57
-
58
- }