diff --git a/package.json b/package.json index 0a793766..a40065a6 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ ], "main": "index.mjs", "version": "19.2.5", - "bitsyVersion": "7.10", + "bitsyVersion": "7.11", "scripts": { "build": "rollup -c", "test": "jest --runInBand", diff --git a/src/test/Bitsy 7.10.html b/src/test/Bitsy 7.11.html similarity index 98% rename from src/test/Bitsy 7.10.html rename to src/test/Bitsy 7.11.html index 0dc68c4b..59cea7f1 100644 --- a/src/test/Bitsy 7.10.html +++ b/src/test/Bitsy 7.11.html @@ -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 @@ -543,6 +543,7 @@ Tile : 1, Clear : 2, Textbox : 3, + PixelIndex : 4, }; function attachCanvas(c) { @@ -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; @@ -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); } } @@ -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; @@ -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(); } } @@ -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)); } } } @@ -4971,7 +5032,7 @@ /* VERSION */ var version = { major: 7, // major changes - minor: 10, // smaller changes + minor: 11, // smaller changes devBuildPhase: "RELEASE", }; function getEngineVersion() {