Skip to content

Commit

Permalink
fix: test against bitsy 7.11
Browse files Browse the repository at this point in the history
  • Loading branch information
seleb committed Jan 1, 2022
1 parent d7ad6e5 commit ed0ed06
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 11 deletions.
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": "19.2.5",
"bitsyVersion": "7.10",
"bitsyVersion": "7.11",
"scripts": {
"build": "rollup -c",
"test": "jest --runInBand",
Expand Down
81 changes: 71 additions & 10 deletions src/test/Bitsy 7.10.html → src/test/Bitsy 7.11.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script type="text/bitsyGameData" id="exportedGameData">
Write your game's title here

# BITSY VERSION 7.10
# BITSY VERSION 7.11

! ROOM_FORMAT 1

Expand Down Expand Up @@ -543,6 +543,7 @@
Tile : 1,
Clear : 2,
Textbox : 3,
PixelIndex : 4,
};

function attachCanvas(c) {
Expand Down Expand Up @@ -595,6 +596,39 @@
}
}

function renderPixelAtIndexInstruction(bufferId, buffer, paletteIndex, index) {
if (bufferId === screenBufferId && curGraphicsMode != 0) {
return;
}

if (!systemPalette[paletteIndex]) {
// bitsyLog("invalid index " + paletteIndex + " @ " + x + "," + y, "system");
return;
}

var color = systemPalette[paletteIndex];

if (buffer.imageData) {
for (var sy = 0; sy < buffer.scale; sy++) {
for (var sx = 0; sx < buffer.scale; sx++) {
var pixelIndex = index * 4;

buffer.imageData.data[pixelIndex + 0] = color[0];
buffer.imageData.data[pixelIndex + 1] = color[1];
buffer.imageData.data[pixelIndex + 2] = color[2];
buffer.imageData.data[pixelIndex + 3] = 255;
}
}
}
else {
var y = Math.floor(index / buffer.width);
var x = index - (y * buffer.width);
var bufferContext = buffer.canvas.getContext("2d");
bufferContext.fillStyle = "rgb(" + color[0] + "," + color[1] + "," + color[2] + ")";
bufferContext.fillRect(x * buffer.scale, y * buffer.scale, buffer.scale, buffer.scale);
}
}

function renderTileInstruction(bufferId, buffer, tileId, x, y) {
if (bufferId != screenBufferId || curGraphicsMode != 1) {
return;
Expand Down Expand Up @@ -668,6 +702,8 @@
case DrawingInstruction.Textbox:
renderTextboxInstruction(bufferId, buffer, instruction.x, instruction.y);
break;
case DrawingInstruction.PixelIndex:
renderPixelAtIndexInstruction(bufferId, buffer, instruction.id, instruction.index);
}
}

Expand Down Expand Up @@ -800,6 +836,23 @@
buffer.instructions.push({ type: DrawingInstruction.Pixel, id: paletteIndex, x: x, y: y, });
}

// todo : name is too long :(
// todo : merge with function above?
function bitsySetPixelAtIndex(paletteIndex, pixelIndex) {
if (curBufferId === screenBufferId && curGraphicsMode != 0) {
return;
}

// avoid trying to render out-of-bounds colors
if (paletteIndex >= systemPalette.length) {
bitsyLog("invalid color! " + paletteIndex, "system");
paletteIndex = systemPalette.length - 1;
}

var buffer = drawingBuffers[curBufferId];
buffer.instructions.push({ type: DrawingInstruction.PixelIndex, id: paletteIndex, index: pixelIndex, });
}

function bitsyDrawTile(tileId, x, y) {
if (curBufferId != screenBufferId || curGraphicsMode != 1) {
return;
Expand Down Expand Up @@ -2091,18 +2144,26 @@
transition.UpdateTransition(0);
}

player().room = destRoom;
player().x = destX;
player().y = destY;
curRoom = destRoom;
initRoom(curRoom);
var movePlayerAndResumeScript = function() {
// update world state
player().room = destRoom;
player().x = destX;
player().y = destY;
curRoom = destRoom;

// update game state
initRoom(curRoom);

// resume dialog script
onReturn(null);
};

// TODO : this doesn't play nice with pagebreak because it thinks the dialog is finished!
if (transition.IsTransitionActive()) {
transition.OnTransitionComplete(function() { onReturn(null); });
transition.OnTransitionComplete(movePlayerAndResumeScript);
}
else {
onReturn(null);
movePlayerAndResumeScript();
}
}

Expand Down Expand Up @@ -3981,7 +4042,7 @@
var i = (y * char.width) + x;
if (charData[i] == 1) {
// todo : other colors
bitsyDrawPixel(char.color, left + x, top + y);
bitsySetPixelAtIndex(char.color, ((top + y) * (textboxInfo.width * text_scale)) + (left + x));
}
}
}
Expand Down Expand Up @@ -4971,7 +5032,7 @@
/* VERSION */
var version = {
major: 7, // major changes
minor: 10, // smaller changes
minor: 11, // smaller changes
devBuildPhase: "RELEASE",
};
function getEngineVersion() {
Expand Down

0 comments on commit ed0ed06

Please sign in to comment.