Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "litecanvas",
"version": "0.301.0",
"version": "0.301.1",
"description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and p5.js/Processing.",
"license": "MIT",
"author": "Luiz Bills <luizbills@pm.me>",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ export default function litecanvas(settings = {}) {
'resize() 3rd argument must be a boolean or a number > 1'
)

settings.width = width
settings.height = height
settings.autoscale = null == autoscale ? settings.autoscale : autoscale

Expand Down
2 changes: 1 addition & 1 deletion src/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions tests/resize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import test from 'ava'
import litecanvas from '../src/index.js'
import { defaultPalette as colors } from '../src/palette.js'
import * as sinon from 'sinon'

let /** @type {LitecanvasInstance} */ local

test.before(() => {
sinon.stub(console) // silent console

local = litecanvas({
global: false,
})
})

test.after(() => {
local.quit()
})

test('resizes the canvas with width and height', async (t) => {
await onLitecanvas(local, 'init', () => {
const w = 320,
h = 160

local.resize(w, h)

{
const actual = local.canvas().width
const expected = w
t.is(actual, expected)
}

{
const actual = local.W
const expected = w
t.is(actual, expected)
}

{
const actual = local.canvas().height
const expected = h
t.is(actual, expected)
}

{
const actual = local.H
const expected = h
t.is(actual, expected)
}
})
})

test('resizes the canvas with width only', async (t) => {
await onLitecanvas(local, 'init', () => {
const w = 320

local.resize(w)

{
const actual = local.W
const expected = w
t.is(actual, expected)
}

{
const actual = local.H
const expected = w
t.is(actual, expected)
}
})
})

test('overrides the user-defined (or default) settings.autoscale', async (t) => {
await onLitecanvas(local, 'init', () => {
const newAutoscale = 3

local.resize(1, 1, newAutoscale)

const actual = local.stat(0).autoscale
const expected = newAutoscale

t.is(actual, expected)
})
})

test('preserves the user-defined (or default) settings.autoscale', async (t) => {
const expected = 3
const e = litecanvas({
global: false,
autoscale: expected,
})

e.resize(1, 1)

const actual = e.stat(0).autoscale

t.is(actual, expected)

e.quit()
})
Loading