like2d 2.5.1 → 2.7.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/README.md +55 -8
- package/dist/core/graphics.d.ts +28 -16
- package/dist/core/graphics.d.ts.map +1 -1
- package/dist/core/graphics.js +26 -9
- package/dist/core/like.d.ts +5 -0
- package/dist/core/like.d.ts.map +1 -1
- package/dist/engine.d.ts +4 -7
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +46 -50
- package/dist/index.d.ts +14 -34
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -21
- package/dist/scene.d.ts +10 -0
- package/dist/scene.d.ts.map +1 -0
- package/dist/scenes/startup.d.ts +18 -0
- package/dist/scenes/startup.d.ts.map +1 -0
- package/dist/scenes/startup.js +48 -0
- package/package.json +9 -17
- package/dist/adapters/callback/index.d.ts +0 -23
- package/dist/adapters/callback/index.d.ts.map +0 -1
- package/dist/adapters/callback/index.js +0 -30
- package/dist/adapters/scene/index.d.ts +0 -18
- package/dist/adapters/scene/index.d.ts.map +0 -1
- package/dist/adapters/scene/index.js +0 -57
- package/dist/adapters/scene/scene.d.ts +0 -19
- package/dist/adapters/scene/scene.d.ts.map +0 -1
- package/dist/adapters/scene/startup-scene.d.ts +0 -18
- package/dist/adapters/scene/startup-scene.d.ts.map +0 -1
- package/dist/adapters/scene/startup-scene.js +0 -61
- package/dist/core/gamepad-button-map.d.ts +0 -5
- package/dist/core/gamepad-button-map.d.ts.map +0 -1
- package/dist/core/gamepad-button-map.js +0 -56
- package/dist/core/gamepad-db.d.ts +0 -49
- package/dist/core/gamepad-db.d.ts.map +0 -1
- package/dist/core/gamepad-db.js +0 -192
- package/dist/core/player-movement.d.ts +0 -16
- package/dist/core/player-movement.d.ts.map +0 -1
- package/dist/core/player-movement.js +0 -20
- /package/dist/{adapters/scene/scene.js → scene.js} +0 -0
package/dist/core/gamepad-db.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
// SDL Game Controller Database parser
|
|
2
|
-
// Parses the gamecontrollerdb.txt file format
|
|
3
|
-
// SDL button names that we care about for standard layout
|
|
4
|
-
export const SDL_BUTTONS = [
|
|
5
|
-
'a', 'b', 'x', 'y',
|
|
6
|
-
'back', 'start', 'guide',
|
|
7
|
-
'leftshoulder', 'rightshoulder',
|
|
8
|
-
'lefttrigger', 'righttrigger',
|
|
9
|
-
'leftstick', 'rightstick',
|
|
10
|
-
'dpup', 'dpdown', 'dpleft', 'dpright',
|
|
11
|
-
'misc1', 'misc2', 'paddle1', 'paddle2', 'paddle3', 'paddle4',
|
|
12
|
-
'touchpad',
|
|
13
|
-
];
|
|
14
|
-
// SDL axis names
|
|
15
|
-
export const SDL_AXES = [
|
|
16
|
-
'leftx', 'lefty',
|
|
17
|
-
'rightx', 'righty',
|
|
18
|
-
];
|
|
19
|
-
export class GamepadDatabase {
|
|
20
|
-
constructor() {
|
|
21
|
-
Object.defineProperty(this, "mappings", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: new Map()
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "vendorProductIndex", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: new Map()
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(this, "loaded", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: false
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
load(dbContent) {
|
|
41
|
-
this.mappings.clear();
|
|
42
|
-
this.vendorProductIndex.clear();
|
|
43
|
-
const lines = dbContent.split('\n');
|
|
44
|
-
for (const line of lines) {
|
|
45
|
-
const trimmed = line.trim();
|
|
46
|
-
if (!trimmed || trimmed.startsWith('#')) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const mapping = this.parseLine(trimmed);
|
|
50
|
-
if (mapping) {
|
|
51
|
-
this.mappings.set(mapping.guid, mapping);
|
|
52
|
-
const vpKey = this.extractVendorProductKey(mapping.guid);
|
|
53
|
-
if (vpKey !== null && !this.vendorProductIndex.has(vpKey)) {
|
|
54
|
-
this.vendorProductIndex.set(vpKey, mapping);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
this.loaded = true;
|
|
59
|
-
}
|
|
60
|
-
extractVendorProductKey(guid) {
|
|
61
|
-
if (guid.length < 20)
|
|
62
|
-
return null;
|
|
63
|
-
const vendorHex = guid.substring(8, 12);
|
|
64
|
-
const productHex = guid.substring(16, 20);
|
|
65
|
-
const vendor = parseInt(vendorHex.substring(2, 4) + vendorHex.substring(0, 2), 16);
|
|
66
|
-
const product = parseInt(productHex.substring(2, 4) + productHex.substring(0, 2), 16);
|
|
67
|
-
if (isNaN(vendor) || isNaN(product))
|
|
68
|
-
return null;
|
|
69
|
-
return 0x10000 * vendor + product;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Check if the database has been loaded
|
|
73
|
-
*/
|
|
74
|
-
isLoaded() {
|
|
75
|
-
return this.loaded;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Get the number of loaded mappings
|
|
79
|
-
*/
|
|
80
|
-
getMappingCount() {
|
|
81
|
-
return this.mappings.size;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Look up a controller mapping by GUID
|
|
85
|
-
*/
|
|
86
|
-
getMapping(guid) {
|
|
87
|
-
return this.mappings.get(guid.toLowerCase());
|
|
88
|
-
}
|
|
89
|
-
getMappingByVendorProduct(vendor, product) {
|
|
90
|
-
const key = 0x10000 * vendor + product;
|
|
91
|
-
return this.vendorProductIndex.get(key);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Check if a controller is in the database
|
|
95
|
-
*/
|
|
96
|
-
hasController(guid) {
|
|
97
|
-
return this.mappings.has(guid.toLowerCase());
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Get all mappings for a specific platform
|
|
101
|
-
*/
|
|
102
|
-
getMappingsByPlatform(platform) {
|
|
103
|
-
const result = [];
|
|
104
|
-
const platformLower = platform.toLowerCase();
|
|
105
|
-
for (const mapping of this.mappings.values()) {
|
|
106
|
-
if (mapping.platform.toLowerCase() === platformLower) {
|
|
107
|
-
result.push(mapping);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Parse a single database line
|
|
114
|
-
*/
|
|
115
|
-
parseLine(line) {
|
|
116
|
-
// Format: GUID,Name,mapping pairs...,platform:Platform,
|
|
117
|
-
const parts = line.split(',');
|
|
118
|
-
if (parts.length < 3) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const guid = parts[0].toLowerCase().trim();
|
|
122
|
-
const name = parts[1].trim();
|
|
123
|
-
const buttons = new Map();
|
|
124
|
-
const axes = new Map();
|
|
125
|
-
const dpads = new Map();
|
|
126
|
-
let platform = '';
|
|
127
|
-
// Parse mapping pairs (key:value)
|
|
128
|
-
for (let i = 2; i < parts.length; i++) {
|
|
129
|
-
const part = parts[i].trim();
|
|
130
|
-
if (!part)
|
|
131
|
-
continue;
|
|
132
|
-
// Check for platform specifier
|
|
133
|
-
if (part.startsWith('platform:')) {
|
|
134
|
-
platform = part.substring('platform:'.length).trim();
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
// Parse key:value pairs
|
|
138
|
-
const colonIndex = part.indexOf(':');
|
|
139
|
-
if (colonIndex === -1)
|
|
140
|
-
continue;
|
|
141
|
-
const key = part.substring(0, colonIndex).trim();
|
|
142
|
-
const value = part.substring(colonIndex + 1).trim();
|
|
143
|
-
if (!key || !value)
|
|
144
|
-
continue;
|
|
145
|
-
// Parse button mapping (b0, b1, etc.)
|
|
146
|
-
if (value.startsWith('b')) {
|
|
147
|
-
const buttonIndex = parseInt(value.substring(1), 10);
|
|
148
|
-
if (!isNaN(buttonIndex)) {
|
|
149
|
-
buttons.set(key, buttonIndex);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// Parse axis mapping (a0, a1, etc.)
|
|
153
|
-
else if (value.startsWith('a')) {
|
|
154
|
-
const axisIndex = parseInt(value.substring(1), 10);
|
|
155
|
-
if (!isNaN(axisIndex)) {
|
|
156
|
-
axes.set(key, axisIndex);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
// Parse hat mapping (h0.1, h0.4, etc.) - used for D-pad
|
|
160
|
-
else if (value.startsWith('h')) {
|
|
161
|
-
const hatParts = value.substring(1).split('.');
|
|
162
|
-
if (hatParts.length === 2) {
|
|
163
|
-
const hatIndex = parseInt(hatParts[0], 10);
|
|
164
|
-
const hatValue = parseInt(hatParts[1], 10);
|
|
165
|
-
if (!isNaN(hatIndex) && !isNaN(hatValue)) {
|
|
166
|
-
dpads.set(key, { hat: hatIndex, value: hatValue });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
// Parse axis-as-button mappings (+a0, -a0) - some controllers use axes for D-pad
|
|
171
|
-
else if (value.startsWith('+a') || value.startsWith('-a')) {
|
|
172
|
-
const axisIndex = parseInt(value.substring(2), 10);
|
|
173
|
-
const direction = value[0];
|
|
174
|
-
if (!isNaN(axisIndex)) {
|
|
175
|
-
// Store as special button with axis info
|
|
176
|
-
// We'll handle this in the mapping layer
|
|
177
|
-
buttons.set(`${key}:${direction}`, axisIndex);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
guid,
|
|
183
|
-
name,
|
|
184
|
-
platform,
|
|
185
|
-
buttons,
|
|
186
|
-
axes,
|
|
187
|
-
dpads,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
// Singleton instance
|
|
192
|
-
export const gamepadDatabase = new GamepadDatabase();
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface PlayerState {
|
|
2
|
-
pos: [number, number];
|
|
3
|
-
speed: number;
|
|
4
|
-
}
|
|
5
|
-
export interface MovementInput {
|
|
6
|
-
left: boolean;
|
|
7
|
-
right: boolean;
|
|
8
|
-
up: boolean;
|
|
9
|
-
down: boolean;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Calculate new player position based on input and delta time.
|
|
13
|
-
* Handles movement in 4 directions with speed scaling and boundary clamping.
|
|
14
|
-
*/
|
|
15
|
-
export declare function updatePlayerPosition(player: PlayerState, input: MovementInput, dt: number, minBounds: [number, number], maxBounds: [number, number]): [number, number];
|
|
16
|
-
//# sourceMappingURL=player-movement.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"player-movement.d.ts","sourceRoot":"","sources":["../../src/core/player-movement.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,aAAa,EACpB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3B,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,CAAC,MAAM,EAAE,MAAM,CAAC,CAalB"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Vec2 } from '../core/vector2';
|
|
2
|
-
/**
|
|
3
|
-
* Calculate new player position based on input and delta time.
|
|
4
|
-
* Handles movement in 4 directions with speed scaling and boundary clamping.
|
|
5
|
-
*/
|
|
6
|
-
export function updatePlayerPosition(player, input, dt, minBounds, maxBounds) {
|
|
7
|
-
let moveDelta = [0, 0];
|
|
8
|
-
if (input.left)
|
|
9
|
-
moveDelta = Vec2.add(moveDelta, [-1, 0]);
|
|
10
|
-
if (input.right)
|
|
11
|
-
moveDelta = Vec2.add(moveDelta, [1, 0]);
|
|
12
|
-
if (input.up)
|
|
13
|
-
moveDelta = Vec2.add(moveDelta, [0, -1]);
|
|
14
|
-
if (input.down)
|
|
15
|
-
moveDelta = Vec2.add(moveDelta, [0, 1]);
|
|
16
|
-
// Apply movement with speed scaling
|
|
17
|
-
const newPos = Vec2.add(player.pos, Vec2.mul(moveDelta, player.speed * dt));
|
|
18
|
-
// Keep player in bounds
|
|
19
|
-
return Vec2.clamp(newPos, minBounds, maxBounds);
|
|
20
|
-
}
|
|
File without changes
|