Skip to content

Commit 75e292f

Browse files
committed
v0.202
* remove "stat" event
1 parent bb655cd commit 75e292f

File tree

6 files changed

+24
-56
lines changed

6 files changed

+24
-56
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "litecanvas",
3-
"version": "0.201.0",
3+
"version": "0.202.0",
44
"description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and p5.js/Processing.",
55
"license": "MIT",
66
"author": "Luiz Bills <luizbills@pm.me>",

src/index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,14 +1257,11 @@ export default function litecanvas(settings = {}) {
12571257
/**
12581258
* Returns information about the engine instance.
12591259
*
1260-
* @param {number|string} index
1260+
* @param {number} index
12611261
* @returns {any}
12621262
*/
12631263
stat(index) {
1264-
DEV: assert(
1265-
isNumber(index) || 'string' === typeof index,
1266-
loggerPrefix + 'stat() 1st param must be a number or string'
1267-
)
1264+
DEV: assert(isNumber(index), loggerPrefix + 'stat() 1st param must be a number')
12681265

12691266
const internals = [
12701267
// 0
@@ -1297,12 +1294,14 @@ export default function litecanvas(settings = {}) {
12971294
_fontLineHeight,
12981295
]
12991296

1300-
const data = { index, value: internals[index] }
1301-
1302-
// plugins can modify or create new stats
1303-
instance.emit('stat', data)
1297+
DEV: assert(
1298+
index >= 0 && index < internals.length,
1299+
loggerPrefix +
1300+
'stat() 1st param must be a number between 0 and ' +
1301+
(internals.length - 1)
1302+
)
13041303

1305-
return data.value
1304+
return internals[index]
13061305
},
13071306

13081307
/**

src/version.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/stat.js

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -233,52 +233,23 @@ test('stat(12) returns the current color palette state modified by palc()', (t)
233233
}
234234
})
235235

236-
test('stat modified via event', async (t) => {
237-
const expected = 'BAR'
236+
test('stat(13) returns the current font line height factor', (t) => {
237+
const expected = 2
238238

239-
await onLitecanvas(local, 'init', () => {
240-
local.listen('stat', (data) => {
241-
// modify only the stat(0)
242-
if (0 === data.index) {
243-
data.value.foo = expected
244-
}
245-
})
239+
local.textgap(expected)
246240

247-
const actual = local.stat(0).foo
248-
t.is(actual, expected)
249-
})
241+
const actual = local.stat(13)
242+
t.deepEqual(actual, expected)
250243
})
251244

252-
test('number stat created via event', async (t) => {
253-
await onLitecanvas(local, 'init', () => {
254-
const customIndex = 42
255-
const expected = 'The answer to the Ultimate Question of Life, the Universe, and Everything'
256-
257-
local.listen('stat', (data) => {
258-
// create a value for stat(42)
259-
if (customIndex === data.index) {
260-
data.value = expected
261-
}
262-
})
245+
test('stat with invalid indexes must throw error in dev mode', (t) => {
246+
const last = 13
263247

264-
const actual = local.stat(customIndex)
265-
t.is(actual, expected)
248+
t.throws(() => {
249+
local.stat(last + 1)
266250
})
267-
})
268-
269-
test('string stat created via event', async (t) => {
270-
await onLitecanvas(local, 'init', () => {
271-
const customIndex = 'forty-two'
272-
const expected = 'The answer to the Ultimate Question of Life, the Universe, and Everything'
273-
274-
local.listen('stat', (data) => {
275-
// create a value for stat(42)
276-
if (customIndex === data.index) {
277-
data.value = expected
278-
}
279-
})
280251

281-
const actual = local.stat(customIndex)
282-
t.is(actual, expected)
252+
t.throws(() => {
253+
local.stat(-1)
283254
})
284255
})

types/global.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,10 @@ declare global {
634634
* - n = 11: the current font family
635635
* - n = 12: the current state of the color palette
636636
* - n = 13: the current font gap
637-
* - n = *any other value*: probably returns undefined
638637
*
639638
* @param index
640639
*/
641-
function stat(index: number | string): any
640+
function stat(index: number): any
642641
/**
643642
* Pauses the engine loop (update & draw).
644643
*/

types/types.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,10 @@ type LitecanvasInstance = {
618618
* - n = 11: the current font family
619619
* - n = 12: the current state of the color palette
620620
* - n = 13: the current font gap
621-
* - n = *any other value*: probably returns undefined
622621
*
623622
* @param index
624623
*/
625-
stat(index: number | string): any
624+
stat(index: number): any
626625
/**
627626
* Pauses the engine loop (update & draw).
628627
*/

0 commit comments

Comments
 (0)