@pixel-wars/core 0.0.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/dist/index.js +68 -0
- package/dist/index.umd.cjs +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/world/generator.d.ts +9 -0
- package/dist/src/world/index.d.ts +42 -0
- package/package.json +30 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/world/generator.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
world;
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this.world = e;
|
|
6
|
+
}
|
|
7
|
+
generateChunk(e, t) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
}, t = class extends e {
|
|
11
|
+
generateChunk() {
|
|
12
|
+
let e = [];
|
|
13
|
+
for (let t = 0; t < this.world.getChunkSize(); t++) {
|
|
14
|
+
e[t] = [];
|
|
15
|
+
for (let n = 0; n < this.world.getChunkSize(); n++) e[t][n] = 0;
|
|
16
|
+
}
|
|
17
|
+
return e;
|
|
18
|
+
}
|
|
19
|
+
}, n = class {
|
|
20
|
+
chunks = {};
|
|
21
|
+
setChunk(e, t, n) {
|
|
22
|
+
let r = `${e},${t}`;
|
|
23
|
+
return this.chunks[r] = n, this.chunks[r];
|
|
24
|
+
}
|
|
25
|
+
getChunk(e, t) {
|
|
26
|
+
let n = `${e},${t}`;
|
|
27
|
+
return this.chunks[n] ?? null;
|
|
28
|
+
}
|
|
29
|
+
getPixel(e, t) {
|
|
30
|
+
let n = Math.floor(e / 16), r = Math.floor(t / 16), i = this.getChunk(n, r);
|
|
31
|
+
if (!i) return null;
|
|
32
|
+
let a = e % 16;
|
|
33
|
+
return i[t % 16][a] ?? null;
|
|
34
|
+
}
|
|
35
|
+
}, r = class {
|
|
36
|
+
pixelTypes;
|
|
37
|
+
chunks = new n();
|
|
38
|
+
generationEnabled = !0;
|
|
39
|
+
generator;
|
|
40
|
+
constructor(e, n = new t(this)) {
|
|
41
|
+
this.pixelTypes = e, this.generator = n;
|
|
42
|
+
}
|
|
43
|
+
getPixelTypes() {
|
|
44
|
+
return this.pixelTypes;
|
|
45
|
+
}
|
|
46
|
+
getChunkSize() {
|
|
47
|
+
return 16;
|
|
48
|
+
}
|
|
49
|
+
chunkGenerationEnabled() {
|
|
50
|
+
return this.generationEnabled;
|
|
51
|
+
}
|
|
52
|
+
setChunkGenerationEnabled(e) {
|
|
53
|
+
this.generationEnabled = e;
|
|
54
|
+
}
|
|
55
|
+
getChunk(e, t) {
|
|
56
|
+
let n = this.chunks.getChunk(e, t);
|
|
57
|
+
if (!n) {
|
|
58
|
+
if (!this.generationEnabled) return null;
|
|
59
|
+
this.generateChunk(e, t), n = this.chunks.getChunk(e, t);
|
|
60
|
+
}
|
|
61
|
+
return n ?? null;
|
|
62
|
+
}
|
|
63
|
+
generateChunk(e, t) {
|
|
64
|
+
return this.generator.generateChunk(e, t);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { e as ChunkGenerator, t as DefaultGenerator, r as World, n as WorldChunks };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.PixelWarsCore={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{world;constructor(e){this.world=e}generateChunk(e,t){return null}},n=class extends t{generateChunk(){let e=[];for(let t=0;t<this.world.getChunkSize();t++){e[t]=[];for(let n=0;n<this.world.getChunkSize();n++)e[t][n]=0}return e}},r=class{chunks={};setChunk(e,t,n){let r=`${e},${t}`;return this.chunks[r]=n,this.chunks[r]}getChunk(e,t){let n=`${e},${t}`;return this.chunks[n]??null}getPixel(e,t){let n=Math.floor(e/16),r=Math.floor(t/16),i=this.getChunk(n,r);if(!i)return null;let a=e%16;return i[t%16][a]??null}},i=class{pixelTypes;chunks=new r;generationEnabled=!0;generator;constructor(e,t=new n(this)){this.pixelTypes=e,this.generator=t}getPixelTypes(){return this.pixelTypes}getChunkSize(){return 16}chunkGenerationEnabled(){return this.generationEnabled}setChunkGenerationEnabled(e){this.generationEnabled=e}getChunk(e,t){let n=this.chunks.getChunk(e,t);if(!n){if(!this.generationEnabled)return null;this.generateChunk(e,t),n=this.chunks.getChunk(e,t)}return n??null}generateChunk(e,t){return this.generator.generateChunk(e,t)}};e.ChunkGenerator=t,e.DefaultGenerator=n,e.World=i,e.WorldChunks=r});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ChunkData, World } from '.';
|
|
2
|
+
export declare class ChunkGenerator {
|
|
3
|
+
protected world: World;
|
|
4
|
+
constructor(world: World);
|
|
5
|
+
generateChunk(_x: number, _y: number): ChunkData;
|
|
6
|
+
}
|
|
7
|
+
export declare class DefaultGenerator extends ChunkGenerator {
|
|
8
|
+
generateChunk(): ChunkData;
|
|
9
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ChunkGenerator } from './generator';
|
|
2
|
+
export interface PixelTexture {
|
|
3
|
+
type: "colour" | "static" | "animated";
|
|
4
|
+
colour?: string;
|
|
5
|
+
staticTexture?: HTMLImageElement;
|
|
6
|
+
animatedTexture?: {
|
|
7
|
+
spriteSheet: HTMLImageElement;
|
|
8
|
+
frames: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
duration: number;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface PixelType {
|
|
18
|
+
name: string;
|
|
19
|
+
collision: boolean;
|
|
20
|
+
texture: PixelTexture;
|
|
21
|
+
}
|
|
22
|
+
export type DefinedChunkData = number[][];
|
|
23
|
+
export type ChunkData = DefinedChunkData | null;
|
|
24
|
+
export declare class WorldChunks {
|
|
25
|
+
private chunks;
|
|
26
|
+
setChunk(x: number, y: number, chunkData: ChunkData): ChunkData;
|
|
27
|
+
getChunk(x: number, y: number): ChunkData;
|
|
28
|
+
getPixel(x: number, y: number): number | null;
|
|
29
|
+
}
|
|
30
|
+
export declare class World {
|
|
31
|
+
private pixelTypes;
|
|
32
|
+
private chunks;
|
|
33
|
+
private generationEnabled;
|
|
34
|
+
private generator;
|
|
35
|
+
constructor(pixelTypes: PixelType[], generator?: ChunkGenerator);
|
|
36
|
+
getPixelTypes(): PixelType[];
|
|
37
|
+
getChunkSize(): number;
|
|
38
|
+
chunkGenerationEnabled(): boolean;
|
|
39
|
+
setChunkGenerationEnabled(enabled: boolean): void;
|
|
40
|
+
getChunk(x: number, y: number): ChunkData;
|
|
41
|
+
generateChunk(x: number, y: number): ChunkData;
|
|
42
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pixel-wars/core",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.umd.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/src/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.umd.cjs",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "~6.0.2",
|
|
21
|
+
"unplugin-dts": "^1.0.2",
|
|
22
|
+
"vite": "^8.0.12"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "vite",
|
|
26
|
+
"build": "vite build",
|
|
27
|
+
"check-types": "tsc",
|
|
28
|
+
"preview": "vite preview"
|
|
29
|
+
}
|
|
30
|
+
}
|