Skip to content

Commit

Permalink
Merge pull request #268 from seleb/8.0
Browse files Browse the repository at this point in the history
Bitsy 8.0
  • Loading branch information
seleb authored Jul 10, 2022
2 parents 79f4cc2 + 943511c commit f8ab714
Show file tree
Hide file tree
Showing 136 changed files with 8,697 additions and 6,488 deletions.
1 change: 1 addition & 0 deletions ReadmePlugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Bitsy and the hacks are generally not backwards-compatible: when Bitsy updates,
If you are using an older version of Bitsy (or a fork based on an older version), you may require old versions of the hacks. Support is not guaranteed across versions, and old versions are not maintained, but some helpful points in history are listed below.
- [Bitsy 7.12](https://github.com/seleb/bitsy-hacks/tree/v20.2.5/dist)
- [Bitsy 7.11](https://github.com/seleb/bitsy-hacks/tree/v19.2.7/dist)
- [Bitsy 7.8-7.9](https://github.com/seleb/bitsy-hacks/tree/v17.0.0/dist)
- [Bitsy 7.2-7.7](https://github.com/seleb/bitsy-hacks/tree/v16.0.3/dist)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"main": "index.mjs",
"version": "20.2.5",
"bitsyVersion": "7.12",
"bitsyVersion": "8.0",
"scripts": {
"build": "rollup -c",
"test": "jest --runInBand",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/__image_snapshots__/backdrops-test-js-permanent-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/__image_snapshots__/backdrops-test-js-title-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file modified src/__image_snapshots__/end-from-dialog-test-js-end-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/__image_snapshots__/end-from-dialog-test-js-end-now-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/__image_snapshots__/javascript-dialog-test-js-now-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Binary file modified src/__image_snapshots__/save-test-js-save-3-snap.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
3 changes: 3 additions & 0 deletions src/avatar by room.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export var hackOptions = {
// and store the original player sprite
var originalDrw;
var originalAnimation;
var isReady = false;
after('load_game', function () {
var room;
Object.keys(hackOptions.avatarByRoom).forEach(function (i) {
Expand All @@ -50,10 +51,12 @@ after('load_game', function () {
});
originalDrw = bitsy.player().drw;
originalAnimation = bitsy.player().animation;
isReady = true;
});

var currentRoom;
before('drawRoom', function () {
if (!isReady) return;
var player = bitsy.player();
if (player.room === currentRoom) {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/avatar by room.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { press, snapshot, start } from './test/bitsy';
import { press, snapshot, start, waitForFrame } from './test/bitsy';

test('avatar by room', async () => {
await start({
Expand Down Expand Up @@ -88,6 +88,7 @@ VAR a
],
],
});
await waitForFrame();
await snapshot();
await press('ArrowRight'); // walk through exit
await snapshot();
Expand Down Expand Up @@ -271,6 +272,7 @@ VAR a
],
],
});
await waitForFrame();
await snapshot();
await press('ArrowRight'); // walk through exit
await snapshot();
Expand Down
3 changes: 2 additions & 1 deletion src/backdrops.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { press, snapshot, start, walkToCat } from './test/bitsy';
import { press, snapshot, start, waitForBlip, walkToCat } from './test/bitsy';

test('by room', async () => {
await start({
Expand All @@ -21,6 +21,7 @@ test('by room', async () => {
await walkToCat();
await snapshot();
await press('ArrowRight'); // talk to cat
await waitForBlip();
await press('ArrowRight'); // complete dialog page
await snapshot();
});
Expand Down
6 changes: 4 additions & 2 deletions src/basic sfx.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ before('startExportedGame', function () {
var px;
var py;
var pr;
before('update', function () {
before('bitsy._update', function () {
var player = bitsy.player();
if (!player) return;
px = player.x;
py = player.y;
pr = player.room;
});
after('update', function () {
after('bitsy._update', function () {
var player = bitsy.player();
if (!player) return;
if ((px !== player.x || py !== player.y || pr !== player.room) && sounds.walk) {
sounds.walk();
}
Expand Down
6 changes: 3 additions & 3 deletions src/bitsymuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ function changeMusic(newMusic) {
}

after('drawRoom', function () {
if (roomMusicFlag !== bitsy.curRoom) {
changeMusic(hackOptions.musicByRoom[bitsy.curRoom]);
roomMusicFlag = bitsy.curRoom;
if (roomMusicFlag !== bitsy.state.room) {
changeMusic(hackOptions.musicByRoom[bitsy.state.room]);
roomMusicFlag = bitsy.state.room;
}
});

Expand Down
14 changes: 6 additions & 8 deletions src/bitsymuse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ test('bitsymuse', async () => {

// hack audio elements to test playback
await evaluate(() => {
function play() {
this.dataset.playing = true;
}
function pause() {
this.dataset.playing = false;
}
Array.from(window.document.querySelectorAll('audio')).forEach(i => {
i.play = play;
i.pause = pause;
i.play = () => {
i.dataset.playing = true;
};
i.pause = () => {
i.dataset.playing = false;
};
});
});
await press('ArrowRight'); // complete title dialog
Expand Down
2 changes: 1 addition & 1 deletion src/canvas replacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ after('startExportedGame', function () {
}
});

after('update', function () {
after('bitsy._update', function () {
if (hackOptions.update) {
hackOptions.update(glazy);
}
Expand Down
12 changes: 10 additions & 2 deletions src/character portraits animated.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ after('startExportedGame', function () {
// override portrait drawing to use frames
var animation;
var animationStart = 0;
before('drawRoom', function () {
before('bitsy._graphics.drawImage', function (id) {
// eslint-disable-next-line no-underscore-dangle
var layers = bitsy.bitsy._getTileMapLayers();
if (id !== layers[layers.length - 1]) return;

if (animation !== state.portrait) {
animationStart = bitsy.prevTime;
}
Expand All @@ -151,6 +155,10 @@ before('drawRoom', function () {
state.portrait = animation.frames[frame].img;
}
});
after('renderGame', function () {
after('bitsy._graphics.drawImage', function (id) {
// eslint-disable-next-line no-underscore-dangle
var layers = bitsy.bitsy._getTileMapLayers();
if (id !== layers[layers.length - 1]) return;

state.portrait = animation;
});
7 changes: 5 additions & 2 deletions src/character portraits animated.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { delay, press, snapshot, start, walkToCat } from './test/bitsy';
import { delay, press, snapshot, start, waitForBlip, walkToCat } from './test/bitsy';

test('autoreset, dialog only', async () => {
await start({
Expand All @@ -19,6 +19,7 @@ test('autoreset, dialog only', async () => {
});
await walkToCat();
await press('ArrowRight'); // talk to cat
await waitForBlip();
await press('ArrowRight'); // complete dialog page
await snapshot();
await delay(2000);
Expand All @@ -30,7 +31,7 @@ test('autoreset, dialog only', async () => {
test('no reset, persist', async () => {
await start({
catDialog: `"""
{sequence
{cycle
- (portrait "cat")\\(portrait "cat"\\)
- (portrait "")\\(portrait ""\\)
}
Expand All @@ -51,13 +52,15 @@ test('no reset, persist', async () => {
});
await walkToCat();
await press('ArrowRight'); // talk to cat
await waitForBlip();
await press('ArrowRight'); // complete dialog page
await snapshot();
await delay(2000);
await snapshot();
await press('ArrowRight'); // end dialog page
await snapshot();
await press('ArrowRight'); // talk to cat
await waitForBlip();
await press('ArrowRight'); // complete dialog page
await snapshot();
await press('ArrowRight'); // end dialog page
Expand Down
17 changes: 6 additions & 11 deletions src/character portraits.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,14 @@ addDialogTag('portrait', function (environment, parameters, onReturn) {
});

// draw portrait on top of screen
after('renderDrawingBuffer', function (bufferId, buffer) {
if (bufferId !== bitsy.screenBufferId || (hackOptions.dialogOnly && !bitsy.isDialogMode && !bitsy.isNarrating) || !state.portrait) return;

var context = buffer.canvas.getContext('2d');
context.imageSmoothingEnabled = false;
after('bitsy._graphics.drawImage', function (id) {
// eslint-disable-next-line no-underscore-dangle
var layers = bitsy.bitsy._getTileMapLayers();
if (id !== layers[layers.length - 1] || (hackOptions.dialogOnly && !bitsy.isDialogMode && !bitsy.isNarrating) || !state.portrait) return;
// eslint-disable-next-line no-underscore-dangle
var context = bitsy.bitsy._getContext();
try {
context.drawImage(state.portrait, 0, 0, bitsy.width * hackOptions.scale, bitsy.height * hackOptions.scale, 0, 0, bitsy.width * bitsy.scale, bitsy.height * bitsy.scale);

// if text is present, redraw it on top of the portrait
var lastInstruction = buffer.instructions[buffer.instructions.length - 1];
if (lastInstruction.type === bitsy.DrawingInstruction.Textbox) {
bitsy.renderTextboxInstruction(bufferId, buffer, lastInstruction.x, lastInstruction.y);
}
} catch (error) {
// log and ignore errors
// so broken images don't break the game
Expand Down
7 changes: 5 additions & 2 deletions src/character portraits.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { press, snapshot, start, walkToCat } from './test/bitsy';
import { press, snapshot, start, waitForBlip, walkToCat } from './test/bitsy';

test('autoreset, dialog only', async () => {
await start({
Expand All @@ -19,6 +19,7 @@ test('autoreset, dialog only', async () => {
});
await walkToCat();
await press('ArrowRight'); // talk to cat
await waitForBlip();
await press('ArrowRight'); // complete dialog page
await snapshot();
await press('ArrowRight'); // end dialog page
Expand All @@ -28,7 +29,7 @@ test('autoreset, dialog only', async () => {
test('no reset, persist', async () => {
await start({
catDialog: `"""
{sequence
{cycle
- (portrait "cat")\\(portrait "cat"\\)
- (portrait "")\\(portrait ""\\)
}
Expand All @@ -49,11 +50,13 @@ test('no reset, persist', async () => {
});
await walkToCat();
await press('ArrowRight'); // talk to cat
await waitForBlip();
await press('ArrowRight'); // complete dialog page
await snapshot();
await press('ArrowRight'); // end dialog page
await snapshot();
await press('ArrowRight'); // talk to cat
await waitForBlip();
await press('ArrowRight'); // complete dialog page
await snapshot();
await press('ArrowRight'); // end dialog page
Expand Down
15 changes: 8 additions & 7 deletions src/close on ending.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ Copy-paste this script into a script tag after the bitsy source
import bitsy from 'bitsy';
import { after, before } from './helpers/kitsy-script-toolkit';

var closed = false;

// prevent ctrl+r restart prompt
before('bitsyGetButton', function (button) {
if (button === 5) return [-1];
before('bitsy.button', function (button) {
if (closed) return [-1];
if (button === bitsy.bitsy.BTN_MENU) return [-1];
return [button];
});

after('onExitDialog', function () {
if (bitsy.isEnding) {
// prevent further input
var no = function () {
return false;
};
bitsy.input.isKeyDown = bitsy.input.anyKeyPressed = bitsy.input.swipeLeft = bitsy.input.swipeRight = bitsy.input.swipeUp = bitsy.input.swipeDown = bitsy.input.isTapReleased = no;
closed = true;
// remove canvas
bitsy.canvas.remove();
// eslint-disable-next-line no-underscore-dangle
bitsy.bitsy._getCanvas().remove();
// attempt to close
window.close();
}
Expand Down
4 changes: 3 additions & 1 deletion src/close on ending.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { press, snapshot, start, walkToCat } from './test/bitsy';
import { press, snapshot, start, waitForBlip, walkToCat } from './test/bitsy';

test('with ending text', async () => {
await start({
Expand All @@ -7,6 +7,7 @@ test('with ending text', async () => {
});
await walkToCat();
await press('ArrowRight');
await waitForBlip();
await press('ArrowRight');
await snapshot();
await press('ArrowRight');
Expand All @@ -21,6 +22,7 @@ test('without ending text', async () => {
});
await walkToCat();
await press('ArrowRight');
await waitForBlip();
await press('ArrowRight');
await snapshot();
});
17 changes: 10 additions & 7 deletions src/corrupt.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ export var hackOptions = {
var px;
var py;
var pr;
before('update', function () {
var player = bitsy.player();
var player;
before('bitsy._update', function () {
player = bitsy.player();
if (!player) return;
px = player.x;
py = player.y;
pr = player.room;
});
after('update', function () {
var player = bitsy.player();
after('bitsy._update', function () {
if (!player) return;
if (px !== player.x || py !== player.y || pr !== player.room) {
corrupt();
bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true });
}
});

Expand All @@ -83,7 +86,7 @@ after('dialogRenderer.SetFont', function (font) {
});

function corrupt() {
var currentRoom = bitsy.room[bitsy.curRoom];
var currentRoom = bitsy.room[bitsy.state.room];
// corrupt pixels of visible tiles
var visibleTiles = {};
currentRoom.tilemap.forEach(function (row) {
Expand All @@ -108,7 +111,7 @@ function corrupt() {
// corrupt pixels of visible sprites
var visibleSprites = {};
Object.keys(bitsy.sprite).forEach(function (spr) {
if (bitsy.sprite[spr].room === bitsy.curRoom) {
if (bitsy.sprite[spr].room === bitsy.state.room) {
visibleSprites[spr] = true;
}
});
Expand Down Expand Up @@ -152,7 +155,7 @@ function corrupt() {
});

// corrupt visible palette colours
var visibleColors = bitsy.getPal(bitsy.curPal());
var visibleColors = bitsy.getPal(bitsy.state.pal);
iterate(hackOptions.paletteFreq * hackOptions.globalFreq, function () {
var c = rndItem(visibleColors);
var i = rndIndex(c);
Expand Down
3 changes: 2 additions & 1 deletion src/corrupt.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { evaluate, press, snapshot, start, walkToCat } from './test/bitsy';
import { evaluate, press, snapshot, start, waitForBlip, walkToCat } from './test/bitsy';

test('corrupt', async () => {
await start({
Expand All @@ -25,6 +25,7 @@ test('corrupt', async () => {
});
await walkToCat();
await press('ArrowRight'); // talk to cat
await waitForBlip();
await press('ArrowRight'); // skip dialogue
await snapshot();
});
Loading

0 comments on commit f8ab714

Please sign in to comment.