slifer 0.2.3 → 0.2.5

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/.npmignore ADDED
@@ -0,0 +1,138 @@
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
+ Resources
11
+ .idea
12
+
13
+ # Diagnostic reports (https://nodejs.org/api/report.html)
14
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15
+
16
+ # Runtime data
17
+ pids
18
+ *.pid
19
+ *.seed
20
+ *.pid.lock
21
+
22
+ # Directory for instrumented libs generated by jscoverage/JSCover
23
+ lib-cov
24
+
25
+ # Coverage directory used by tools like istanbul
26
+ coverage
27
+ *.lcov
28
+
29
+ # nyc test coverage
30
+ .nyc_output
31
+
32
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33
+ .grunt
34
+
35
+ # Bower dependency directory (https://bower.io/)
36
+ bower_components
37
+
38
+ # node-waf configuration
39
+ .lock-wscript
40
+
41
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
42
+ build/Release
43
+
44
+ # Dependency directories
45
+ node_modules/
46
+ jspm_packages/
47
+
48
+ # Snowpack dependency directory (https://snowpack.dev/)
49
+ web_modules/
50
+
51
+ # TypeScript cache
52
+ *.tsbuildinfo
53
+
54
+ # Optional npm cache directory
55
+ .npm
56
+
57
+ # Optional eslint cache
58
+ .eslintcache
59
+
60
+ # Optional stylelint cache
61
+ .stylelintcache
62
+
63
+ # Microbundle cache
64
+ .rpt2_cache/
65
+ .rts2_cache_cjs/
66
+ .rts2_cache_es/
67
+ .rts2_cache_umd/
68
+
69
+ # Optional REPL history
70
+ .node_repl_history
71
+
72
+ # Output of 'npm pack'
73
+ *.tgz
74
+
75
+ # Yarn Integrity file
76
+ .yarn-integrity
77
+
78
+ # dotenv environment variable files
79
+ .env
80
+ .env.development.local
81
+ .env.test.local
82
+ .env.production.local
83
+ .env.local
84
+
85
+ # parcel-bundler cache (https://parceljs.org/)
86
+ .cache
87
+ .parcel-cache
88
+
89
+ # Next.js build output
90
+ .next
91
+ out
92
+
93
+ # Nuxt.js build / generate output
94
+ .nuxt
95
+ dist
96
+
97
+ # Gatsby files
98
+ .cache/
99
+ # Comment in the public line in if your project uses Gatsby and not Next.js
100
+ # https://nextjs.org/blog/next-9-1#public-directory-support
101
+ # public
102
+
103
+ # vuepress build output
104
+ .vuepress/dist
105
+
106
+ # vuepress v2.x temp and cache directory
107
+ .temp
108
+ .cache
109
+
110
+ # Docusaurus cache and generated files
111
+ .docusaurus
112
+
113
+ # Serverless directories
114
+ .serverless/
115
+
116
+ # FuseBox cache
117
+ .fusebox/
118
+
119
+ # DynamoDB Local files
120
+ .dynamodb/
121
+
122
+ # TernJS port file
123
+ .tern-port
124
+
125
+ # Stores VSCode versions used for testing VSCode extensions
126
+ .vscode-test
127
+
128
+ # yarn v2
129
+ .yarn/cache
130
+ .yarn/unplugged
131
+ .yarn/build-state.yml
132
+ .yarn/install-state.gz
133
+ .pnp.*
134
+ test.ts
135
+ char.png
136
+
137
+ .wakatime-project
138
+ libs/
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Slifer : Native Typescript Game Framework
2
2
 
3
3
  <p align="center">
4
- <img width="80%" src="./logo-alpha.png">
4
+ <img width="80%" src="https://ucarecdn.com/288f053f-61e0-42e6-804a-8c1d48a41aac/-/preview/1000x562/">
5
5
  </p>
6
6
 
7
7
  > [!CAUTION]
@@ -12,12 +12,14 @@
12
12
  > window customization. As such, I recommend waiting for a beta release of
13
13
  > Slifer before using it for a long term project.
14
14
 
15
+ For up to date docs, please head over to the [Slifer Webpage](https://slifer.hazyvt.com).
16
+
17
+ ## Introduction
18
+
15
19
  Slifer is a game framework made to allow users to code games in typescript. The
16
20
  framework uses bun and SDL2 under the hood to allow your game to render and
17
21
  build natively to desktop.
18
22
 
19
- If you'd like to learn more about Slifer, feel free to head to [Slifers Webpage](https://slifer.hazyvt.com).
20
-
21
23
  ## Contents
22
24
 
23
25
  - [Goals](#goals)
@@ -38,19 +40,19 @@ If you'd like to learn more about Slifer, feel free to head to [Slifers Webpage]
38
40
  - Create a native desktop window with custom title and size.
39
41
  - Handle both keyboard and mouse inputs
40
42
  - Load and draw images onto the window
43
+ - Play Audio
41
44
 
42
45
  ## Future Features
43
46
 
44
- - Audio Implementation
45
47
  - Animation library
46
48
  - Save file library
47
49
 
48
50
  ## Example
49
51
 
50
52
  ```ts
51
- import Slifer from "slifer";
53
+ import Slifer, { Vector2 } from "slifer";
52
54
 
53
- Slifer.createWindow("Example Window", 640, 480);
55
+ Slifer.createWindow("Example Window", new Vector2(640, 480));
54
56
 
55
57
  const bg = Slifer.Graphics.makeColor(36, 36, 36, 255);
56
58
 
package/bun.lockb CHANGED
Binary file
package/index.ts CHANGED
@@ -1,11 +1,8 @@
1
- import { SliferClass } from "./src/slifer";
2
-
3
- export { Image } from './src/engine/image';
4
- export { Vector2 } from './src/engine/vector';
5
- export { Rectangle } from './src/engine/rectangle';
6
- export { Timer } from './src/engine/time';
7
- export { AudioSource } from './src/modules/audio'
8
-
9
- const Slifer = new SliferClass();
10
- export default Slifer;
1
+ import Slifer from "./src/slifer";
2
+ import Image from "./src/engine/image";
3
+ import Vector2 from "./src/engine/vector2";
4
+ import Color from "./src/engine/color";
5
+ import Audio from "./src/engine/audio";
11
6
 
7
+ const slf = new Slifer();
8
+ export { Vector2, Color, Image, Audio, slf as Slifer };
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "slifer",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "A game framework made for bun and typescript",
5
5
  "module": "index.ts",
6
6
  "devDependencies": {
7
- "@types/bun": "latest",
8
- "typedoc": "^0.26.7"
7
+ "@types/bun": "latest"
9
8
  },
10
9
  "peerDependencies": {
11
10
  "typescript": "^5.0.0"
12
11
  },
13
- "type": "module"
12
+ "type": "module",
13
+ "scripts": {
14
+ "postinstall": "bun run src/download.ts"
15
+ },
16
+ "exports": "./index.ts"
14
17
  }
@@ -0,0 +1,23 @@
1
+ import * as https from 'https';
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+
5
+ const libDir = path.join(__dirname, '../libs/');
6
+
7
+ async function downloadLibrary(url: string, filename: string) {
8
+ const response = await fetch(url);
9
+ await Bun.write(libDir + filename, response);
10
+
11
+
12
+ }
13
+
14
+ if (process.platform == "darwin") {
15
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2.dylib", "libSDL2.dylib");
16
+
17
+
18
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_image.dylib", "libSDL2_image.dylib");
19
+
20
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_mixer.dylib", "libSDL2_mixer.dylib");
21
+
22
+ downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_ttf.dylib", "libSDL2_ttf.dylib");
23
+ }
@@ -1,27 +1,12 @@
1
- import { ptr } from "bun:ffi";
2
1
  import { libmixer } from "../ffi";
3
2
 
4
- class Audio {
5
- static #instance: Audio;
6
-
7
- private constructor() {}
8
-
9
- public static get instance() {
10
- if (!Audio.#instance) Audio.#instance = new Audio();
11
-
12
- return Audio.#instance;
13
- }
14
-
15
- public loadAudio(path: string): AudioSource {
16
- return new AudioSource(path);
17
- }
18
- }
19
-
20
- export class AudioSource {
21
- public readonly pointer;
3
+ /** @internal */
4
+ export default class Audio {
5
+ private readonly pointer;
22
6
 
23
7
  constructor(path: string) {
24
8
  const audiomix = libmixer.symbols.Mix_LoadWAV(
9
+ //@ts-expect-error Buffer error
25
10
  Buffer.from(path + "\x00")
26
11
  );
27
12
 
@@ -36,6 +21,4 @@ export class AudioSource {
36
21
  public destroy() {
37
22
  libmixer.symbols.Mix_FreeChunk(this.pointer);
38
23
  }
39
- }
40
-
41
- export default Audio;
24
+ }
@@ -1,4 +1,5 @@
1
- class Color {
1
+ /** @internal */
2
+ export default class Color {
2
3
  readonly r;
3
4
  readonly g;
4
5
  readonly b;
@@ -11,5 +12,3 @@ class Color {
11
12
  this.a = a;
12
13
  }
13
14
  }
14
-
15
- export default Color;
@@ -1,28 +1,34 @@
1
+ import { libimage, libsdl } from "../ffi";
1
2
  import { type Pointer, ptr } from 'bun:ffi';
2
- import { libsdl } from '../ffi';
3
- import { Vector2 } from './vector';
3
+ import Render from "./render";
4
4
 
5
- export class Image {
6
- public readonly pointer: Pointer;
7
- public readonly size: Vector2;
8
- public flipH: boolean = false;
5
+ /** @internal */
6
+ export default class Image {
9
7
 
10
- constructor(texture: Pointer) {
11
- this.pointer = texture;
8
+ private pointer: Pointer;
9
+ private destArr: Uint32Array;
12
10
 
13
- const _wArr = new Uint32Array(1);
14
- const _hArr = new Uint32Array(1);
11
+ public readonly width;
12
+ public readonly height;
15
13
 
16
- libsdl.symbols.SDL_QueryTexture(
17
- texture,
18
- null,
19
- null,
20
- ptr(_wArr),
21
- ptr(_hArr)
22
- );
14
+ constructor(path: string) {
15
+ const cs = Buffer.from(path+'\x00');
16
+ //@ts-expect-error Buffer error;
17
+ const texture = libimage.symbols.IMG_LoadTexture(Render.pointer, cs);
18
+ if (texture == null) throw `Texture creation failed.`;
19
+ this.pointer = texture;
23
20
 
24
- this.size = new Vector2(_wArr[0], _hArr[0]);
25
- }
21
+ const wArr = new Uint32Array(1);
22
+ const hArr = new Uint32Array(1);
23
+ libsdl.symbols.SDL_QueryTexture(texture, null, null, ptr(wArr), ptr(hArr));
26
24
 
27
- }
25
+ this.width = wArr[0];
26
+ this.height = hArr[0];
28
27
 
28
+ this.destArr = new Uint32Array(4);
29
+ this.destArr[0] = 0;
30
+ this.destArr[1] = 0;
31
+ this.destArr[2] = this.width;
32
+ this.destArr[3] = this.height;
33
+ }
34
+ }
@@ -1,26 +1,17 @@
1
- import { ptr } from "bun:ffi";
2
- import { Vector2 } from "./vector";
1
+ import type Vector2 from "./vector2";
2
+ import { ptr, type Pointer } from 'bun:ffi';
3
3
 
4
- export class Rectangle {
5
- public readonly pointer;
6
- public position: Vector2;
7
- public size: Vector2;
4
+ /** @internal */
5
+ export default class Rectangle {
6
+
7
+ public readonly position;
8
+ public readonly size;
8
9
 
9
10
  constructor(position: Vector2, size: Vector2) {
10
- const arr = new Uint32Array(4);
11
- arr[0] = position.x;
12
- arr[1] = position.y;
13
- arr[2] = size.x;
14
- arr[3] = size.y;
15
- this.pointer = ptr(arr);
16
11
  this.position = position;
17
12
  this.size = size;
18
13
  }
19
14
 
20
- static empty() {
21
- return new Rectangle(new Vector2(0, 0), new Vector2(0, 0));
22
- }
23
-
24
15
  public isColliding(rectangle: Rectangle) : boolean {
25
16
  if (
26
17
  this.position.x < rectangle.position.x + rectangle.size.x &&
@@ -33,5 +24,4 @@ export class Rectangle {
33
24
 
34
25
  return false;
35
26
  }
36
- }
37
-
27
+ }
@@ -0,0 +1,15 @@
1
+ import { type Pointer } from 'bun:ffi';
2
+ import { libsdl } from "../ffi";
3
+ import Window from "./window";
4
+
5
+ /** @internal */
6
+ export default class Render {
7
+
8
+ public static pointer : Pointer;
9
+
10
+ public static createRenderer() {
11
+ const renPointer = libsdl.symbols.SDL_CreateRenderer(Window.pointer, -1, 0);
12
+ if (renPointer == null) throw `Renderer creation failed.`;
13
+ this.pointer = renPointer;
14
+ }
15
+ }
@@ -0,0 +1,10 @@
1
+ /** @internal */
2
+ export default class Vector2 {
3
+ public x;
4
+ public y;
5
+
6
+ constructor(x: number, y: number) {
7
+ this.x = x;
8
+ this.y = y;
9
+ }
10
+ }
@@ -1,60 +1,32 @@
1
- import { type Pointer } from "bun:ffi";
2
- import { Vector2 } from "./vector";
3
- import { libsdl } from "../ffi";
4
-
5
- class Window {
6
- static #instance: Window;
7
- static #pointer: Pointer;
8
-
9
- private title!: string;
10
- private size!: Vector2;
11
-
12
- private static readonly centerPos = 0x2fff0000;
13
-
14
- private constructor() {}
15
-
16
- public static get instance() {
17
- if (!Window.#instance) {
18
- Window.#instance = new Window();
19
- }
20
-
21
- return Window.#instance;
22
- }
23
-
24
- public static get pointer() {
25
- return Window.#pointer;
26
- }
27
-
28
- public static createWindow(title: string, size: Vector2): void {
29
- Window.instance.title = title;
30
- Window.instance.size = size;
31
-
32
- // Create cstring by buffer from string
33
- const _titleBuffer = new Buffer(Window.instance.title + "\x00");
34
-
35
- // Create window pointer
36
- const _winPointer = libsdl.symbols.SDL_CreateWindow(
37
- _titleBuffer,
38
- Window.centerPos,
39
- Window.centerPos,
40
- Window.instance.size.x,
41
- Window.instance.size.y,
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
+ public static pointer: Pointer;
8
+
9
+ private static centerPos = 0x2fff0000;
10
+
11
+ public static createWindow(title: string, size: Vector2) : void {
12
+ const winPointer = libsdl.symbols.SDL_CreateWindow(
13
+ //@ts-expect-error Buffer error
14
+ Buffer.from(title + '\x00'),
15
+ this.centerPos,
16
+ this.centerPos,
17
+ size.x,
18
+ size.y,
42
19
  0
43
- );
44
-
45
- if (_winPointer == null) throw `Window Creation Failed`;
46
- Window.#pointer = _winPointer;
47
- }
20
+ )
48
21
 
49
- public setSize(size: Vector2): void {
50
- this.size = size;
51
- libsdl.symbols.SDL_SetWindowSize(Window.pointer, size.x, size.y);
22
+ if (winPointer == null) throw `Window creation failed.`;
23
+ this.pointer = winPointer;
52
24
  }
53
25
 
54
26
  public setTitle(title: string): void {
55
- this.title = title;
56
27
  libsdl.symbols.SDL_SetWindowTitle(
57
28
  Window.pointer,
29
+ //@ts-expect-error Buffer error
58
30
  Buffer.from(title + "\x00")
59
31
  );
60
32
  }
@@ -74,6 +46,4 @@ class Window {
74
46
  public centerWindow() {
75
47
  this.setPosition(new Vector2(Window.centerPos, Window.centerPos));
76
48
  }
77
- }
78
-
79
- export default Window;
49
+ }
package/src/engine.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { libsdl, libimage, libttf, libmixer } from "./ffi";
2
- import Graphics from "./modules/graphics";
3
2
 
4
3
  export function initSDL() {
5
4
  const initVideo = 0x00000020;
package/src/ffi.ts CHANGED
@@ -221,6 +221,10 @@ export const libsdl = dlopen(libSDLImport.default, {
221
221
  args: ["cstring"],
222
222
  returns: "int",
223
223
  },
224
+ SDL_GetMouseState: {
225
+ args: ['pointer', 'pointer'],
226
+ returns: 'u32'
227
+ }
224
228
  });
225
229
 
226
230
  /** @internal */
@@ -233,6 +237,10 @@ export const libimage = dlopen(libImageImport.default, {
233
237
  args: ["cstring"],
234
238
  returns: "pointer",
235
239
  },
240
+ IMG_LoadTexture: {
241
+ args: ['pointer', 'cstring'],
242
+ returns: 'pointer'
243
+ }
236
244
  });
237
245
 
238
246
  /** @internal */