From e8df2b8a73a7f1d7a46e9bf17464075a069625e2 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sun, 10 Jul 2022 21:58:19 +0000 Subject: [PATCH] chore(release): 21.0.0 [skip ci] # [21.0.0](https://github.com/seleb/bitsy-hacks/compare/v20.2.5...v21.0.0) (2022-07-10) ### Bug Fixes * **avatar by room:** modifying animation before player has been setup ([59bc418](https://github.com/seleb/bitsy-hacks/commit/59bc41896477531154d69863f125be4836bf670d)) * **basic sfx:** guard against missing player on init ([053240b](https://github.com/seleb/bitsy-hacks/commit/053240be3069c788d66c3ae7ab56837864ae963f)) * **bitsymuse:** audio tags with multiple sources trying to load file "null" ([2c4c3e8](https://github.com/seleb/bitsy-hacks/commit/2c4c3e8141791cfaaf80582a85c9a746a57dec85)) * **bitsymuse:** update current room reference for v8 ([2124aff](https://github.com/seleb/bitsy-hacks/commit/2124affc387827d0558ba0dab9edc21f1f28fec6)) * **canvas replacement:** use v8 update hook ([51d0dcd](https://github.com/seleb/bitsy-hacks/commit/51d0dcd597f22456f9d07e2b98b15760df00c5fd)) * **character portraits animated:** use same fn hook as non-animated version for v8 ([2706e19](https://github.com/seleb/bitsy-hacks/commit/2706e19e5bf448640e2ec6cee10992bf2eda712f)) * **character portraits:** draw between map layers and textbox for v8 ([9b8aab8](https://github.com/seleb/bitsy-hacks/commit/9b8aab8e6c3bedd0f5d00a1fbc4a723c1a1d7590)) * **close on ending:** prevent additional v8 inputs ([68a8b59](https://github.com/seleb/bitsy-hacks/commit/68a8b59760f38d195b6b7cb5b3c1cfec43e9900a)) * **close on ending:** prevent v8 menu button ([ff9157f](https://github.com/seleb/bitsy-hacks/commit/ff9157f76b92293c71df7a5aa64a76992b56335d)) * **close on ending:** remove v8 canvas ([46186dc](https://github.com/seleb/bitsy-hacks/commit/46186dc29811154313f31b3c5a5ecf140b154efd)) * **corrupt:** guard against unset player ([9019fe3](https://github.com/seleb/bitsy-hacks/commit/9019fe3007662d78bc327ba8bd2548af04a4548d)) * **corrupt:** redraw room after corrupting ([6931e74](https://github.com/seleb/bitsy-hacks/commit/6931e74cad144a05fa229444b3b79c39f6193996)) * **corrupt:** use v8 hooks ([7180884](https://github.com/seleb/bitsy-hacks/commit/7180884b70ba091a022e79b4a56462e5b69490b8)) * **corrupt:** use v8 room state ([2a1d52c](https://github.com/seleb/bitsy-hacks/commit/2a1d52c1681f235497a493f07873341c6c21891b)) * **custom text effect:** add note about new third argument ([3b4f6f4](https://github.com/seleb/bitsy-hacks/commit/3b4f6f4cf89b7814330a7f2f81ac7e487c9e7d8a)) * **custom text effect:** update `doEffect` case for v8 ([7e02e3b](https://github.com/seleb/bitsy-hacks/commit/7e02e3b5adffb9def8564e9315885d1278eef635)) * **custom text effect:** update effect toggle for v8 ([8653a05](https://github.com/seleb/bitsy-hacks/commit/8653a05b82670b45344c02961b07d2fb18db7cf9)) * **custom-keyhandlers:** removed ([dab6e2d](https://github.com/seleb/bitsy-hacks/commit/dab6e2d34497c53f9c6c6a69b6116ff96689aebb)) * **custom-keyhandlers:** update current room reference for v8 ([88a5956](https://github.com/seleb/bitsy-hacks/commit/88a59567214339792f5940b28ea23b3235d61ace)) * **dialog audio vocal synth:** guard against undefined voice ([1a879a9](https://github.com/seleb/bitsy-hacks/commit/1a879a9c6a9e9152a4284651d9296e4769630033)) * **dialog audio:** missing parameter in v8 character constructor ([8ba7a5e](https://github.com/seleb/bitsy-hacks/commit/8ba7a5eb94d8cdfb31f4c2f03e770df03fb68090)) * **dialog box transition:** total rewrite for v8 ([417ccdf](https://github.com/seleb/bitsy-hacks/commit/417ccdf34a387934cb41511c0f5e59a9fb254f1d)) * **dialog choices:** choices not re-rendering ([2fa8710](https://github.com/seleb/bitsy-hacks/commit/2fa8710a25e6975626ceb5e63e08e3c419b1cd9a)) * **dialog choices:** render choice arrow using v8 rendering instructions ([10bc384](https://github.com/seleb/bitsy-hacks/commit/10bc384f3defd356841ce3aafc105dc75235e171)) * **dialog choices:** reserve memory to avoid flickering ([10dcb73](https://github.com/seleb/bitsy-hacks/commit/10dcb739d465a4ba47e08648cdeb278f1484e044)) * **dialog choices:** shuffle node regex ([df95741](https://github.com/seleb/bitsy-hacks/commit/df95741d4dd627ba4469e83648372c3c37e18dc2)) * **dialog choices:** simplify input management ([6384ff2](https://github.com/seleb/bitsy-hacks/commit/6384ff269249b2e88db4e92c9749c4cac272b67c)) * **dialog choices:** text skipped after selection ([79a7698](https://github.com/seleb/bitsy-hacks/commit/79a76987c498ab21722857aafc546629e1ad2e65)) * **dialog choices:** use v8 input management ([387c29c](https://github.com/seleb/bitsy-hacks/commit/387c29c900dacbb5e5d4fc7a8e5e17fba453f650)) * **dialog prompt:** force redrawing to allow interactive preview ([4e6f4b3](https://github.com/seleb/bitsy-hacks/commit/4e6f4b308263bdd376ab4b0f4f040633e2cba945)) * **dialog prompt:** use v8 input management ([eb8ed22](https://github.com/seleb/bitsy-hacks/commit/eb8ed2239f98490549f4222cbc8ec75a1b22bb06)) * **directional avatar:** update hooks for v8 ([929d827](https://github.com/seleb/bitsy-hacks/commit/929d827b0b429e728c8792e303f7a3fbd0c1d1ce)) * **dynamic background:** update hook for v8 ([ea7b748](https://github.com/seleb/bitsy-hacks/commit/ea7b7489de5ec2abde6ccad4df104a8dc5af43a8)) * **dynamic background:** use v8 current palette state ([9214727](https://github.com/seleb/bitsy-hacks/commit/921472729528348f0acdee5e1ae0d04a4ddd583d)) * **dynamic background:** use v8 current room state ([1786ca7](https://github.com/seleb/bitsy-hacks/commit/1786ca7626dc005ea8829c63b37c66bc2007494e)) * **edit image at runtime:** remove unnecessary cache bust ([f6cb152](https://github.com/seleb/bitsy-hacks/commit/f6cb152fd6f8c04c1f68aed7e904cd6100fc407f)) * **edit image from dialog:** redraw room after editing ([7d5e805](https://github.com/seleb/bitsy-hacks/commit/7d5e805598748e106f8c8d82fbc5e44a9f609981)) * **edit player from dialog:** add note about built-in dialog tag ([0f9b8b6](https://github.com/seleb/bitsy-hacks/commit/0f9b8b6e6086ad7873d9fa27f6ac5ea1df594973)) * **edit player from dialog:** edit v8 room state ([4b6768c](https://github.com/seleb/bitsy-hacks/commit/4b6768c6f42b0e36ed8ae584271cc3677b297625)) * **edit player from dialog:** redraw room when player changes ([5741833](https://github.com/seleb/bitsy-hacks/commit/5741833d386ebf1b6371e79762f4a8ccc7cc00a4)) * **edit player from dialog:** update all relevant state ([82e6555](https://github.com/seleb/bitsy-hacks/commit/82e6555cc3c2c8c6d1adb1777a4d9706b9be328d)) * **edit room from dialog:** redraw room after edits ([8a86408](https://github.com/seleb/bitsy-hacks/commit/8a86408a7fd4336eb53dc2929c2849cb1330a702)) * **end-from-dialog:** add deprecation notice ([a0c126a](https://github.com/seleb/bitsy-hacks/commit/a0c126ab05196133c26126ea007c8fa78937fe17)) * **exit-from-dialog:** minor behaviour change ([ce444e6](https://github.com/seleb/bitsy-hacks/commit/ce444e6601a8d0bceafddbfb5a80132793d2c485)) * **follower:** don't use timeout if unnecessary ([32d0530](https://github.com/seleb/bitsy-hacks/commit/32d05309180722230f4759f4ee2e22f2eff66eb1)) * **follower:** guard against unset player ([d04f8d9](https://github.com/seleb/bitsy-hacks/commit/d04f8d9ab78d4e3fc89f1be14d8789e196cd7488)) * **follower:** minor behaviour change ([ca62ba7](https://github.com/seleb/bitsy-hacks/commit/ca62ba79f4a2a7f49a9614afa815eed68bdc3c8a)) * **follower:** redraw room after followers move ([b91325c](https://github.com/seleb/bitsy-hacks/commit/b91325c08566177c9e643e0212311c8e3aed9538)) * **follower:** redraw room after syncing followers ([e7a4af5](https://github.com/seleb/bitsy-hacks/commit/e7a4af5bc19899333bf65e7a88f8e0a54c94cbeb)) * **follower:** use v8 hooks ([cb31f13](https://github.com/seleb/bitsy-hacks/commit/cb31f1383b03a600e64622ac988bd0e495e13355)) * **gamepad input:** missing menu button support ([17af7c8](https://github.com/seleb/bitsy-hacks/commit/17af7c8547c9814c48541b6a5a9f3ae87f385e41)) * **gamepad input:** poke gamepad state directly into v8 virtual memory ([0e0a6c4](https://github.com/seleb/bitsy-hacks/commit/0e0a6c4243bcde4f0c04948551b50071d83fc3d0)) * **gamepad input:** use v8 hooks ([58c9641](https://github.com/seleb/bitsy-hacks/commit/58c96411993e2dda77ffe757b60d75b9468d2e70)) * **gravity:** guard against unset player ([0143631](https://github.com/seleb/bitsy-hacks/commit/01436314512cddd8efab62582497048a41138e89)) * **gravity:** shadowed `player` variables ([cb8191e](https://github.com/seleb/bitsy-hacks/commit/cb8191ef6772ec43918c83e24318098e2f122593)) * **gravity:** use v8 hooks ([7df96f1](https://github.com/seleb/bitsy-hacks/commit/7df96f1a895657e09ae8c66bf6eb42cb4380ff75)) * **itsy-bitsy:** overwrite v8 globals ([2ad7d5a](https://github.com/seleb/bitsy-hacks/commit/2ad7d5a14a87c1c50b6f3f08098d9dfb672512ef)) * **long dialog:** reserve space in v8's textbox virtual memory ([dabb152](https://github.com/seleb/bitsy-hacks/commit/dabb1521e3c38893b5078209fda1cefe85cc70d0)) * **multi-sprite avatar:** force full redraw in v8 ([14b48de](https://github.com/seleb/bitsy-hacks/commit/14b48dedea9f3fb2366ea6cf84762ca177b9f00a)) * **noclip:** removed ([a7ca5c2](https://github.com/seleb/bitsy-hacks/commit/a7ca5c20981a37d204e5757b7d220d5127fdc836)) * **online:** redraw room after receiving sprite updates ([7c5f915](https://github.com/seleb/bitsy-hacks/commit/7c5f915b624f398f7d192b5e9f9174b8de15508e)) * **online:** redraw room on online sprite movement ([13c4a35](https://github.com/seleb/bitsy-hacks/commit/13c4a355b81361aa16a272239e30b7160a27218e)) * **online:** send/receive background colour ([ab8eada](https://github.com/seleb/bitsy-hacks/commit/ab8eada515d6e36c580af165d88a672133c5c8f2)) * **opaque tiles:** transparent sprites compatibility ([25d6cd4](https://github.com/seleb/bitsy-hacks/commit/25d6cd4464b55329cd3fa1132a6689e7f9bb8227)) * **opaque tiles:** use v8 hooks ([c62c412](https://github.com/seleb/bitsy-hacks/commit/c62c412132c89f79db31ae4158909290ec721a74)) * **permanent items:** always redraw to avoid items disappearing ([b5c9a7a](https://github.com/seleb/bitsy-hacks/commit/b5c9a7ac682412573140b08a1863d15b0483b885)) * **permanent items:** use v8 room state ([71801ca](https://github.com/seleb/bitsy-hacks/commit/71801ca38e9dc9d406e3df5ea575ac2df8c303f6)) * **push-sprites:** redraw room after pushing sprite ([2ed672d](https://github.com/seleb/bitsy-hacks/commit/2ed672d9fd2052934b17fa078552e523e1456b74)) * **push-sprites:** use v8 room state ([67e8019](https://github.com/seleb/bitsy-hacks/commit/67e801960a8134770335b616d0cf459d7262a618)) * remove pre-v8 callbacks ([8c76f84](https://github.com/seleb/bitsy-hacks/commit/8c76f843ea706e2d976a7dd0ce7bd03d03e236bd)) * **replace drawing:** use v8 hook ([f7edf0f](https://github.com/seleb/bitsy-hacks/commit/f7edf0f2e35f664778aacec1609f4b75a327d86f)) * **save:** items not redrawn if loading while standing on top of one ([04a2e53](https://github.com/seleb/bitsy-hacks/commit/04a2e53a632007f3c71a2ab6ea203ee49d6babb6)) * **save:** override title if loading ([71f59db](https://github.com/seleb/bitsy-hacks/commit/71f59db52fb5c5992feb5d0b8378692ff9c3bed9)) * **save:** redraw room after loading ([fbebb5f](https://github.com/seleb/bitsy-hacks/commit/fbebb5f8e6b807fa4689212964a6af3dde2aa055)) * **save:** use v8 room state ([4d3fd0d](https://github.com/seleb/bitsy-hacks/commit/4d3fd0dec4e042ee9aa819b7a079c4fe2721da7e)) * **smooth moves:** removed ([c2fdf70](https://github.com/seleb/bitsy-hacks/commit/c2fdf7056538ac93cdfe650a7d447ec662045a5b)) * **solid items:** use v8 room state ([f922585](https://github.com/seleb/bitsy-hacks/commit/f922585b03876493430c16dbaf7bfc165679356d)) * **sprite effects:** removed ([1afe1ab](https://github.com/seleb/bitsy-hacks/commit/1afe1abcf692856cac0b339cc7e98d496afc6dc0)) * **text-to-speech:** use v8 dialog char constructor hook ([6161a8e](https://github.com/seleb/bitsy-hacks/commit/6161a8e4026b3d07fc3cb6119f896ea5e28aea88)) * **transitions:** use v8 room state ([8701fb9](https://github.com/seleb/bitsy-hacks/commit/8701fb9f79c50e14601eae2f23e6fd46f6eeb40b)) * **transparent background:** update clear canvas hook for v8 ([ab3e492](https://github.com/seleb/bitsy-hacks/commit/ab3e492aa8fe6744cea87d83c7148c1d04a0116b)) * **transparent dialog:** overwrite with transparent fill after clearing ([71cb08c](https://github.com/seleb/bitsy-hacks/commit/71cb08ccc11f751735013f1f7f2a84fe1cc6f177)) * **transparent sprites:** use v8's native background colour support ([1800cbf](https://github.com/seleb/bitsy-hacks/commit/1800cbf28d0eb88109faa85ecc2aa61940d2ad53)) * **twine-bitsy-comms:** use v8 hook ([853d6c1](https://github.com/seleb/bitsy-hacks/commit/853d6c1b7951607a8b27464a3daa79fa53a51a16)) * **unique items:** redraw room when unique items are removed ([59d8e42](https://github.com/seleb/bitsy-hacks/commit/59d8e42b9046286658b08116507ce91bd819f31e)) ### BREAKING CHANGES * **sprite effects:** `sprite effects` hack was removed as bitsy's sprites are now represented in an explicit grid in virtual memory similar to tiles * **smooth moves:** `smooth moves` hack was removed as bitsy's sprites are now represented in an explicit grid in virtual memory similar to tiles * **follower:** `follower` behaviour has changed slightly when using multiple followers in a chain: once in sync, followers behave the same, but the initial steps which put them in sync play out in a different order than before * **exit-from-dialog:** `exit-from-dialog` will not reposition the textbox if exited from a high position to a low one, or vice versa * **dialog prompt:** `dialog prompt` no longer supports arrow navigation due to bitsy capturing the arrow keys * **dialog box transition:** the `dialog box transition` hack is very different in v8, and requires you to specify and a duration and an easing function instead of just a single easing constant. see its hack options for more info * **noclip:** `noclip` hack was removed as bitsy's input manager no longer supports arbitrary input, and instead only supports 6 dedicated buttons (4 directions + `OK` + `MENU`) * **custom-keyhandlers:** `custom-keyhandlers` hack was removed as bitsy's input manager no longer supports arbitrary input, and instead only supports 6 dedicated buttons (4 directions + `OK` + `MENU`) --- CHANGELOG.md | 103 ++++++++++++++++++++++++ README.md | 11 +-- dist/avatar-by-room.js | 20 +++-- dist/backdrops.js | 105 +++++++------------------ dist/basic-sfx.js | 25 +++--- dist/bitsymuse.js | 25 +++--- dist/canvas-replacement.js | 15 ++-- dist/character-portraits-animated.js | 46 ++++++----- dist/character-portraits.js | 30 +++---- dist/close-on-ending.js | 28 +++---- dist/corrupt.js | 83 +++++--------------- dist/custom-exit-effects.js | 13 +--- dist/custom-text-effect.js | 43 +++++----- dist/dialog-audio-vocal-synth.js | 25 +++--- dist/dialog-audio.js | 15 ++-- dist/dialog-box-transition.js | 112 ++++++++++++--------------- dist/dialog-choices.js | 108 +++++++++++++------------- dist/dialog-jump.js | 13 +--- dist/dialog-pause.js | 13 +--- dist/dialog-prompt.js | 40 ++++------ dist/direction-in-dialog.js | 13 +--- dist/directional-avatar.js | 76 ++++-------------- dist/dynamic-background.js | 23 +++--- dist/edit-dialog-from-dialog.js | 17 ++-- dist/edit-image-from-dialog.js | 68 +++------------- dist/edit-player-from-dialog.js | 28 ++++--- dist/edit-room-from-dialog.js | 39 +++++----- dist/end-from-dialog.js | 15 ++-- dist/exit-from-dialog.js | 17 ++-- dist/external-game-data.js | 13 +--- dist/favicon-from-sprite.js | 17 ++-- dist/follower.js | 35 +++++---- dist/gamepad-input.js | 47 ++++++----- dist/gravity.js | 97 ++++++----------------- dist/itsy-bitsy.js | 55 +++++++------ dist/javascript-dialog.js | 13 +--- dist/logic-operators-extended.js | 13 +--- dist/long-dialog.js | 44 +++++++---- dist/multi-sprite-avatar.js | 25 +++--- dist/online.js | 92 ++++++---------------- dist/opaque-tiles.js | 53 +++++++------ dist/paragraph-break.js | 13 +--- dist/permanent-items.js | 26 +++---- dist/push-sprites.js | 73 +++-------------- dist/replace-drawing.js | 15 ++-- dist/save.js | 40 +++++----- dist/solid-items.js | 15 ++-- dist/stopwatch.js | 17 ++-- dist/text-to-speech.js | 15 ++-- dist/tracery-processing.js | 13 +--- dist/transitions.js | 21 ++--- dist/transparent-background.js | 101 +++++++----------------- dist/transparent-dialog.js | 19 ++--- dist/transparent-sprites.js | 92 +++++++--------------- dist/twine-bitsy-comms.js | 15 ++-- dist/unique-items.js | 14 ++-- package-lock.json | 4 +- package.json | 2 +- 58 files changed, 850 insertions(+), 1318 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3bc56f7..a3253faf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,106 @@ +# [21.0.0](https://github.com/seleb/bitsy-hacks/compare/v20.2.5...v21.0.0) (2022-07-10) + + +### Bug Fixes + +* **avatar by room:** modifying animation before player has been setup ([59bc418](https://github.com/seleb/bitsy-hacks/commit/59bc41896477531154d69863f125be4836bf670d)) +* **basic sfx:** guard against missing player on init ([053240b](https://github.com/seleb/bitsy-hacks/commit/053240be3069c788d66c3ae7ab56837864ae963f)) +* **bitsymuse:** audio tags with multiple sources trying to load file "null" ([2c4c3e8](https://github.com/seleb/bitsy-hacks/commit/2c4c3e8141791cfaaf80582a85c9a746a57dec85)) +* **bitsymuse:** update current room reference for v8 ([2124aff](https://github.com/seleb/bitsy-hacks/commit/2124affc387827d0558ba0dab9edc21f1f28fec6)) +* **canvas replacement:** use v8 update hook ([51d0dcd](https://github.com/seleb/bitsy-hacks/commit/51d0dcd597f22456f9d07e2b98b15760df00c5fd)) +* **character portraits animated:** use same fn hook as non-animated version for v8 ([2706e19](https://github.com/seleb/bitsy-hacks/commit/2706e19e5bf448640e2ec6cee10992bf2eda712f)) +* **character portraits:** draw between map layers and textbox for v8 ([9b8aab8](https://github.com/seleb/bitsy-hacks/commit/9b8aab8e6c3bedd0f5d00a1fbc4a723c1a1d7590)) +* **close on ending:** prevent additional v8 inputs ([68a8b59](https://github.com/seleb/bitsy-hacks/commit/68a8b59760f38d195b6b7cb5b3c1cfec43e9900a)) +* **close on ending:** prevent v8 menu button ([ff9157f](https://github.com/seleb/bitsy-hacks/commit/ff9157f76b92293c71df7a5aa64a76992b56335d)) +* **close on ending:** remove v8 canvas ([46186dc](https://github.com/seleb/bitsy-hacks/commit/46186dc29811154313f31b3c5a5ecf140b154efd)) +* **corrupt:** guard against unset player ([9019fe3](https://github.com/seleb/bitsy-hacks/commit/9019fe3007662d78bc327ba8bd2548af04a4548d)) +* **corrupt:** redraw room after corrupting ([6931e74](https://github.com/seleb/bitsy-hacks/commit/6931e74cad144a05fa229444b3b79c39f6193996)) +* **corrupt:** use v8 hooks ([7180884](https://github.com/seleb/bitsy-hacks/commit/7180884b70ba091a022e79b4a56462e5b69490b8)) +* **corrupt:** use v8 room state ([2a1d52c](https://github.com/seleb/bitsy-hacks/commit/2a1d52c1681f235497a493f07873341c6c21891b)) +* **custom text effect:** add note about new third argument ([3b4f6f4](https://github.com/seleb/bitsy-hacks/commit/3b4f6f4cf89b7814330a7f2f81ac7e487c9e7d8a)) +* **custom text effect:** update `doEffect` case for v8 ([7e02e3b](https://github.com/seleb/bitsy-hacks/commit/7e02e3b5adffb9def8564e9315885d1278eef635)) +* **custom text effect:** update effect toggle for v8 ([8653a05](https://github.com/seleb/bitsy-hacks/commit/8653a05b82670b45344c02961b07d2fb18db7cf9)) +* **custom-keyhandlers:** removed ([dab6e2d](https://github.com/seleb/bitsy-hacks/commit/dab6e2d34497c53f9c6c6a69b6116ff96689aebb)) +* **custom-keyhandlers:** update current room reference for v8 ([88a5956](https://github.com/seleb/bitsy-hacks/commit/88a59567214339792f5940b28ea23b3235d61ace)) +* **dialog audio vocal synth:** guard against undefined voice ([1a879a9](https://github.com/seleb/bitsy-hacks/commit/1a879a9c6a9e9152a4284651d9296e4769630033)) +* **dialog audio:** missing parameter in v8 character constructor ([8ba7a5e](https://github.com/seleb/bitsy-hacks/commit/8ba7a5eb94d8cdfb31f4c2f03e770df03fb68090)) +* **dialog box transition:** total rewrite for v8 ([417ccdf](https://github.com/seleb/bitsy-hacks/commit/417ccdf34a387934cb41511c0f5e59a9fb254f1d)) +* **dialog choices:** choices not re-rendering ([2fa8710](https://github.com/seleb/bitsy-hacks/commit/2fa8710a25e6975626ceb5e63e08e3c419b1cd9a)) +* **dialog choices:** render choice arrow using v8 rendering instructions ([10bc384](https://github.com/seleb/bitsy-hacks/commit/10bc384f3defd356841ce3aafc105dc75235e171)) +* **dialog choices:** reserve memory to avoid flickering ([10dcb73](https://github.com/seleb/bitsy-hacks/commit/10dcb739d465a4ba47e08648cdeb278f1484e044)) +* **dialog choices:** shuffle node regex ([df95741](https://github.com/seleb/bitsy-hacks/commit/df95741d4dd627ba4469e83648372c3c37e18dc2)) +* **dialog choices:** simplify input management ([6384ff2](https://github.com/seleb/bitsy-hacks/commit/6384ff269249b2e88db4e92c9749c4cac272b67c)) +* **dialog choices:** text skipped after selection ([79a7698](https://github.com/seleb/bitsy-hacks/commit/79a76987c498ab21722857aafc546629e1ad2e65)) +* **dialog choices:** use v8 input management ([387c29c](https://github.com/seleb/bitsy-hacks/commit/387c29c900dacbb5e5d4fc7a8e5e17fba453f650)) +* **dialog prompt:** force redrawing to allow interactive preview ([4e6f4b3](https://github.com/seleb/bitsy-hacks/commit/4e6f4b308263bdd376ab4b0f4f040633e2cba945)) +* **dialog prompt:** use v8 input management ([eb8ed22](https://github.com/seleb/bitsy-hacks/commit/eb8ed2239f98490549f4222cbc8ec75a1b22bb06)) +* **directional avatar:** update hooks for v8 ([929d827](https://github.com/seleb/bitsy-hacks/commit/929d827b0b429e728c8792e303f7a3fbd0c1d1ce)) +* **dynamic background:** update hook for v8 ([ea7b748](https://github.com/seleb/bitsy-hacks/commit/ea7b7489de5ec2abde6ccad4df104a8dc5af43a8)) +* **dynamic background:** use v8 current palette state ([9214727](https://github.com/seleb/bitsy-hacks/commit/921472729528348f0acdee5e1ae0d04a4ddd583d)) +* **dynamic background:** use v8 current room state ([1786ca7](https://github.com/seleb/bitsy-hacks/commit/1786ca7626dc005ea8829c63b37c66bc2007494e)) +* **edit image at runtime:** remove unnecessary cache bust ([f6cb152](https://github.com/seleb/bitsy-hacks/commit/f6cb152fd6f8c04c1f68aed7e904cd6100fc407f)) +* **edit image from dialog:** redraw room after editing ([7d5e805](https://github.com/seleb/bitsy-hacks/commit/7d5e805598748e106f8c8d82fbc5e44a9f609981)) +* **edit player from dialog:** add note about built-in dialog tag ([0f9b8b6](https://github.com/seleb/bitsy-hacks/commit/0f9b8b6e6086ad7873d9fa27f6ac5ea1df594973)) +* **edit player from dialog:** edit v8 room state ([4b6768c](https://github.com/seleb/bitsy-hacks/commit/4b6768c6f42b0e36ed8ae584271cc3677b297625)) +* **edit player from dialog:** redraw room when player changes ([5741833](https://github.com/seleb/bitsy-hacks/commit/5741833d386ebf1b6371e79762f4a8ccc7cc00a4)) +* **edit player from dialog:** update all relevant state ([82e6555](https://github.com/seleb/bitsy-hacks/commit/82e6555cc3c2c8c6d1adb1777a4d9706b9be328d)) +* **edit room from dialog:** redraw room after edits ([8a86408](https://github.com/seleb/bitsy-hacks/commit/8a86408a7fd4336eb53dc2929c2849cb1330a702)) +* **end-from-dialog:** add deprecation notice ([a0c126a](https://github.com/seleb/bitsy-hacks/commit/a0c126ab05196133c26126ea007c8fa78937fe17)) +* **exit-from-dialog:** minor behaviour change ([ce444e6](https://github.com/seleb/bitsy-hacks/commit/ce444e6601a8d0bceafddbfb5a80132793d2c485)) +* **follower:** don't use timeout if unnecessary ([32d0530](https://github.com/seleb/bitsy-hacks/commit/32d05309180722230f4759f4ee2e22f2eff66eb1)) +* **follower:** guard against unset player ([d04f8d9](https://github.com/seleb/bitsy-hacks/commit/d04f8d9ab78d4e3fc89f1be14d8789e196cd7488)) +* **follower:** minor behaviour change ([ca62ba7](https://github.com/seleb/bitsy-hacks/commit/ca62ba79f4a2a7f49a9614afa815eed68bdc3c8a)) +* **follower:** redraw room after followers move ([b91325c](https://github.com/seleb/bitsy-hacks/commit/b91325c08566177c9e643e0212311c8e3aed9538)) +* **follower:** redraw room after syncing followers ([e7a4af5](https://github.com/seleb/bitsy-hacks/commit/e7a4af5bc19899333bf65e7a88f8e0a54c94cbeb)) +* **follower:** use v8 hooks ([cb31f13](https://github.com/seleb/bitsy-hacks/commit/cb31f1383b03a600e64622ac988bd0e495e13355)) +* **gamepad input:** missing menu button support ([17af7c8](https://github.com/seleb/bitsy-hacks/commit/17af7c8547c9814c48541b6a5a9f3ae87f385e41)) +* **gamepad input:** poke gamepad state directly into v8 virtual memory ([0e0a6c4](https://github.com/seleb/bitsy-hacks/commit/0e0a6c4243bcde4f0c04948551b50071d83fc3d0)) +* **gamepad input:** use v8 hooks ([58c9641](https://github.com/seleb/bitsy-hacks/commit/58c96411993e2dda77ffe757b60d75b9468d2e70)) +* **gravity:** guard against unset player ([0143631](https://github.com/seleb/bitsy-hacks/commit/01436314512cddd8efab62582497048a41138e89)) +* **gravity:** shadowed `player` variables ([cb8191e](https://github.com/seleb/bitsy-hacks/commit/cb8191ef6772ec43918c83e24318098e2f122593)) +* **gravity:** use v8 hooks ([7df96f1](https://github.com/seleb/bitsy-hacks/commit/7df96f1a895657e09ae8c66bf6eb42cb4380ff75)) +* **itsy-bitsy:** overwrite v8 globals ([2ad7d5a](https://github.com/seleb/bitsy-hacks/commit/2ad7d5a14a87c1c50b6f3f08098d9dfb672512ef)) +* **long dialog:** reserve space in v8's textbox virtual memory ([dabb152](https://github.com/seleb/bitsy-hacks/commit/dabb1521e3c38893b5078209fda1cefe85cc70d0)) +* **multi-sprite avatar:** force full redraw in v8 ([14b48de](https://github.com/seleb/bitsy-hacks/commit/14b48dedea9f3fb2366ea6cf84762ca177b9f00a)) +* **noclip:** removed ([a7ca5c2](https://github.com/seleb/bitsy-hacks/commit/a7ca5c20981a37d204e5757b7d220d5127fdc836)) +* **online:** redraw room after receiving sprite updates ([7c5f915](https://github.com/seleb/bitsy-hacks/commit/7c5f915b624f398f7d192b5e9f9174b8de15508e)) +* **online:** redraw room on online sprite movement ([13c4a35](https://github.com/seleb/bitsy-hacks/commit/13c4a355b81361aa16a272239e30b7160a27218e)) +* **online:** send/receive background colour ([ab8eada](https://github.com/seleb/bitsy-hacks/commit/ab8eada515d6e36c580af165d88a672133c5c8f2)) +* **opaque tiles:** transparent sprites compatibility ([25d6cd4](https://github.com/seleb/bitsy-hacks/commit/25d6cd4464b55329cd3fa1132a6689e7f9bb8227)) +* **opaque tiles:** use v8 hooks ([c62c412](https://github.com/seleb/bitsy-hacks/commit/c62c412132c89f79db31ae4158909290ec721a74)) +* **permanent items:** always redraw to avoid items disappearing ([b5c9a7a](https://github.com/seleb/bitsy-hacks/commit/b5c9a7ac682412573140b08a1863d15b0483b885)) +* **permanent items:** use v8 room state ([71801ca](https://github.com/seleb/bitsy-hacks/commit/71801ca38e9dc9d406e3df5ea575ac2df8c303f6)) +* **push-sprites:** redraw room after pushing sprite ([2ed672d](https://github.com/seleb/bitsy-hacks/commit/2ed672d9fd2052934b17fa078552e523e1456b74)) +* **push-sprites:** use v8 room state ([67e8019](https://github.com/seleb/bitsy-hacks/commit/67e801960a8134770335b616d0cf459d7262a618)) +* remove pre-v8 callbacks ([8c76f84](https://github.com/seleb/bitsy-hacks/commit/8c76f843ea706e2d976a7dd0ce7bd03d03e236bd)) +* **replace drawing:** use v8 hook ([f7edf0f](https://github.com/seleb/bitsy-hacks/commit/f7edf0f2e35f664778aacec1609f4b75a327d86f)) +* **save:** items not redrawn if loading while standing on top of one ([04a2e53](https://github.com/seleb/bitsy-hacks/commit/04a2e53a632007f3c71a2ab6ea203ee49d6babb6)) +* **save:** override title if loading ([71f59db](https://github.com/seleb/bitsy-hacks/commit/71f59db52fb5c5992feb5d0b8378692ff9c3bed9)) +* **save:** redraw room after loading ([fbebb5f](https://github.com/seleb/bitsy-hacks/commit/fbebb5f8e6b807fa4689212964a6af3dde2aa055)) +* **save:** use v8 room state ([4d3fd0d](https://github.com/seleb/bitsy-hacks/commit/4d3fd0dec4e042ee9aa819b7a079c4fe2721da7e)) +* **smooth moves:** removed ([c2fdf70](https://github.com/seleb/bitsy-hacks/commit/c2fdf7056538ac93cdfe650a7d447ec662045a5b)) +* **solid items:** use v8 room state ([f922585](https://github.com/seleb/bitsy-hacks/commit/f922585b03876493430c16dbaf7bfc165679356d)) +* **sprite effects:** removed ([1afe1ab](https://github.com/seleb/bitsy-hacks/commit/1afe1abcf692856cac0b339cc7e98d496afc6dc0)) +* **text-to-speech:** use v8 dialog char constructor hook ([6161a8e](https://github.com/seleb/bitsy-hacks/commit/6161a8e4026b3d07fc3cb6119f896ea5e28aea88)) +* **transitions:** use v8 room state ([8701fb9](https://github.com/seleb/bitsy-hacks/commit/8701fb9f79c50e14601eae2f23e6fd46f6eeb40b)) +* **transparent background:** update clear canvas hook for v8 ([ab3e492](https://github.com/seleb/bitsy-hacks/commit/ab3e492aa8fe6744cea87d83c7148c1d04a0116b)) +* **transparent dialog:** overwrite with transparent fill after clearing ([71cb08c](https://github.com/seleb/bitsy-hacks/commit/71cb08ccc11f751735013f1f7f2a84fe1cc6f177)) +* **transparent sprites:** use v8's native background colour support ([1800cbf](https://github.com/seleb/bitsy-hacks/commit/1800cbf28d0eb88109faa85ecc2aa61940d2ad53)) +* **twine-bitsy-comms:** use v8 hook ([853d6c1](https://github.com/seleb/bitsy-hacks/commit/853d6c1b7951607a8b27464a3daa79fa53a51a16)) +* **unique items:** redraw room when unique items are removed ([59d8e42](https://github.com/seleb/bitsy-hacks/commit/59d8e42b9046286658b08116507ce91bd819f31e)) + + +### BREAKING CHANGES + +* **sprite effects:** `sprite effects` hack was removed as bitsy's sprites are now represented in an explicit grid in virtual memory similar to tiles +* **smooth moves:** `smooth moves` hack was removed as bitsy's sprites are now represented in an explicit grid in virtual memory similar to tiles +* **follower:** `follower` behaviour has changed slightly when using multiple followers in a chain: once in sync, followers behave the same, but the initial steps which put them in sync play out in a different order than before +* **exit-from-dialog:** `exit-from-dialog` will not reposition the textbox if exited from a high position to a low one, or vice versa +* **dialog prompt:** `dialog prompt` no longer supports arrow navigation due to bitsy capturing the arrow keys +* **dialog box transition:** the `dialog box transition` hack is very different in v8, and requires you to specify and a duration and an easing function instead of just a single easing constant. see its hack options for more info +* **noclip:** `noclip` hack was removed as bitsy's input manager no longer supports arbitrary input, and instead only supports 6 dedicated buttons (4 directions + `OK` + `MENU`) +* **custom-keyhandlers:** `custom-keyhandlers` hack was removed as bitsy's input manager no longer supports arbitrary input, and instead only supports 6 dedicated buttons (4 directions + `OK` + `MENU`) + ## [20.2.5](https://github.com/seleb/bitsy-hacks/compare/v20.2.4...v20.2.5) (2022-07-08) diff --git a/README.md b/README.md index 496283e8..695e64e5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ npm i @bitsy/hecks A collection of re-usable scripts for [Adam Le Doux](https://twitter.com/adamledoux)'s [Bitsy Game Maker](https://ledoux.itch.io/bitsy). See [Ayolland's Borksy](https://ayolland.itch.io/borksy) for a GUI that allows you to use these hacks with less copy-pasting. -Last tested against Bitsy 7.12 +Last tested against Bitsy 8.0 - [Contents](#contents) - [How to use](#how-to-use) @@ -26,7 +26,6 @@ Last tested against Bitsy 7.12 - โ›”๏ธ [close on ending](/dist/close-on-ending.js): Prevents from playing past an ending - โžฟ [corrupt](/dist/corrupt.js): corrupts gamedata at runtime - ๐ŸŽž [custom-exit-effects](/dist/custom-exit-effects.js): make custom exit transition effects -- โŒจ [custom-keyhandlers](/dist/custom-keyhandlers.js): run custom code on key inputs - ๐Ÿ…ฐ [custom text effect](/dist/custom-text-effect.js): make {custom}text effects{custom} - ๐Ÿ’ฌ [dialog audio](/dist/dialog-audio.js): animal crossing-style audio - ๐ŸŽบ [dialog audio vocal synth](/dist/dialog-audio-vocal-synth.js): animal crossing-style audio powered by the pink trombone vocal synth @@ -42,7 +41,7 @@ Last tested against Bitsy 7.12 - ๐Ÿ–Œ [edit image from dialog](/dist/edit-image-from-dialog.js): edit sprites, items, and tiles from dialog - ๐Ÿ‘ฏโ€โ™‚๏ธ [edit player from dialog](/dist/edit-player-from-dialog.js): change which sprite is controlled by the player - ๐Ÿ  [edit room from dialog](/dist/edit-room-from-dialog.js): modify the content of a room from dialog -- ๐Ÿ”š [end-from-dialog](/dist/end-from-dialog.js): trigger an ending from dialog, including narration text +- ๐Ÿ”š [end-from-dialog](/dist/end-from-dialog.js): trigger an ending from dialog, including narration text (deprecated) - ๐Ÿšช [exit-from-dialog](/dist/exit-from-dialog.js): exit to another room from dialog, including conditionals - ๐Ÿ›ฐ [external-game-data](/dist/external-game-data.js): separate Bitsy game data from your (modded) HTML for easier development - ๐ŸŒ [favicon-from-sprite](/dist/favicon-from-sprite.js): generate a browser favicon (tab icon) from a Bitsy sprite, including animation! @@ -54,7 +53,6 @@ Last tested against Bitsy 7.12 - ๐Ÿ”€ [logic-operators-extended](/dist/logic-operators-extended.js): adds conditional logic operators - ๐Ÿ“œ [long dialog](/dist/long-dialog.js): put more words onscreen - ๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ง [multi-sprite avatar](/dist/multi-sprite-avatar.js): make the player big -- ๐Ÿ“Ž [noclip](/dist/noclip.js): walk through wall tiles, sprites, items, exits, and endings - ๐Ÿ”„ [online](/dist/online.js): multiplayer bitsy - โฌ› [opaque tiles](/dist/opaque-tiles.js): tiles which hide the player - ๐Ÿ“ƒ [paragraph-break](/dist/paragraph-break.js): Adds paragraph breaks to the dialogue parser @@ -62,16 +60,14 @@ Last tested against Bitsy 7.12 - โžก [push sprites](/dist/push-sprites.js): sokoban-style sprite pushing - ๐ŸŽญ [replace drawing](/dist/replace-drawing.js): add name-tags to replace drawings when the game is loading - ๐Ÿ’พ [save](/dist/save.js): save/load your game -- ๐Ÿƒ [smooth moves](/dist/smooth-moves.js): ease the player's movement - ๐Ÿ›‘ [solid items](/dist/solid-items.js): treat some items like sprites that can be placed multiple times -- ๐Ÿ’ƒ [sprite effects](/dist/sprite-effects.js): like text effects, but for sprites - โฑ๏ธ [stopwatch](/dist/stopwatch.js): time player actions - ๐Ÿ—ฃ [text-to-speech](/dist/text-to-speech.js): text-to-speech for bitsy dialog - ๐Ÿฐ [tracery processing](/dist/tracery-processing.js): process all dialog text with a tracery grammar - ๐ŸŽž [transitions](/dist/transitions.js): customizable WebGL transitions - ๐Ÿ”ณ [transparent background](/dist/transparent-background.js): makes the game have a transparent background - ๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ [transparent dialog](/dist/transparent-dialog.js): makes the dialog box have a transparent background -- ๐Ÿ [transparent sprites](/dist/transparent-sprites.js): makes all sprites have transparent backgrounds +- ๐Ÿ [transparent sprites](/dist/transparent-sprites.js): makes all sprites have transparent backgrounds (deprecated) - ๐Ÿ’ฑ [twine bitsy comms](/dist/twine-bitsy-comms.js): interprocess communication for twine and bitsy - โ„ [unique items](/dist/unique-items.js): items which, when picked up, remove all other instances of that item from the game @@ -157,6 +153,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) diff --git a/dist/avatar-by-room.js b/dist/avatar-by-room.js index 6c1c8c7c..fea51764 100644 --- a/dist/avatar-by-room.js +++ b/dist/avatar-by-room.js @@ -4,8 +4,8 @@ @summary change the avatar in certain rooms @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -177,8 +177,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -224,11 +224,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -245,8 +240,8 @@ var after = kitsy.after; @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -286,6 +281,7 @@ function getRoom(name) { // 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) { @@ -296,10 +292,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; diff --git a/dist/backdrops.js b/dist/backdrops.js index fdd0076a..c4f2e86f 100644 --- a/dist/backdrops.js +++ b/dist/backdrops.js @@ -4,8 +4,8 @@ @summary makes the game have a backdrop @license MIT @author Cephalopodunk & Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -55,7 +55,7 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); * @param searcher Regex to search and replace * @param replacer Replacer string/fn */ -function inject$1(searcher, replacer) { +function inject(searcher, replacer) { // find the relevant script tag var scriptTags = document.getElementsByTagName('script'); var scriptTag; @@ -122,7 +122,7 @@ function after$1(targetFuncName, afterFn) { } function applyInjects() { kitsy.queuedInjectScripts.forEach(function (injectScript) { - inject$1(injectScript.searcher, injectScript.replacer); + inject(injectScript.searcher, injectScript.replacer); }); } function applyHooks(root) { @@ -181,8 +181,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -228,18 +228,13 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; } /** @see kitsy.inject */ -var inject = kitsy.inject; +kitsy.inject; /** @see kitsy.before */ var before = kitsy.before; /** @see kitsy.after */ @@ -248,17 +243,24 @@ var after = kitsy.after; /** ๐Ÿ @file transparent sprites -@summary makes all sprites have transparent backgrounds +@summary makes all sprites have transparent backgrounds (deprecated) @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Makes all sprites have transparent backgrounds. i.e. tiles can be seen underneath the player, sprites, and items. +NOTE: This hack is no longer necessary as Bitsy 8.0 +supports transparent sprites directly in gamedata. +To flag a drawing as transparent in Bitsy, +add the following line underneath its data: + +BGC * + HOW TO USE: 1. Copy-paste this script into a script tag after the bitsy source 2. Edit hackOptions below as needed @@ -273,57 +275,15 @@ var hackOptions$2 = { }, }; -window.makeTransparent = false; -// flag what should be transparent -before('renderer.GetDrawingFrame', function (drawing, frameIndex) { - window.makeTransparent = hackOptions$2.isTransparent(drawing); -}); -// send -1 instead of background colour index if transparent -inject(/bitsyDrawPixel\(backgroundColor, x, y\)/, 'bitsyDrawPixel(window.makeTransparent ? -1 : backgroundColor, x, y)'); -// make sure transitions render using regular room logic -inject( - /(function createRoomPixelBuffer\(room\) {)/, - `$1 -var buffer = drawingBuffers[screenBufferId]; -var s = buffer.scale; -buffer.scale = 1; -drawRoom(room); -renderDrawingBuffer(screenBufferId, buffer); -const data = buffer.canvas.getContext('2d').getImageData(0, 0, buffer.width, buffer.height).data; -var pixelBuffer = []; -for (var y = 0; y < buffer.height; ++y) { -for (var x = 0; x < buffer.width; ++x) { - var idx = (y*buffer.width + x)*4; - var r = data[idx + 0]; - var g = data[idx + 1]; - var b = data[idx + 2]; - var p = getPal(getRoomPal(curRoom)).findIndex(i => r === i[0] && g === i[1] && b === i[2]); - pixelBuffer.push(tileColorStartIndex + p); -} -} -buffer.scale = s; -invalidateDrawingBuffer(buffer); -return pixelBuffer; -` -); -// make sure tiles are available when drawing rooms -inject(/(var tileBuffer = drawingBuffers\[tileId\];)/, 'hackForEditor_GetImageFromTileId(tileId); $1'); - -// overwrite transparent pixel -after('renderPixelInstruction', function (bufferId, buffer, paletteIndex, x, y) { - if (paletteIndex !== -1) return; - - if (buffer.imageData) { - for (var sy = 0; sy < buffer.scale; sy++) { - for (var sx = 0; sx < buffer.scale; sx++) { - var pixelIndex = (y * buffer.scale + sy) * buffer.width * buffer.scale * 4 + (x * buffer.scale + sx) * 4; - buffer.imageData.data[pixelIndex + 3] = 0; +before('renderer.SetDrawings', function () { + Object.values(bitsy.tile) + .concat(Object.values(bitsy.sprite)) + .concat(Object.values(bitsy.item)) + .forEach(drawing => { + if (hackOptions$2.isTransparent(drawing)) { + drawing.bgc = -bitsy.tileColorStartIndex; } - } - } else { - var bufferContext = buffer.canvas.getContext('2d'); - bufferContext.clearRect(x * buffer.scale, y * buffer.scale, buffer.scale, buffer.scale); - } + }); }); /** @@ -332,8 +292,8 @@ after('renderPixelInstruction', function (bufferId, buffer, paletteIndex, x, y) @summary makes the game have a transparent background @license MIT @author Cephalopodunk & Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -363,14 +323,9 @@ hackOptions$2.isTransparent = function (drawing) { return hackOptions$1.isTransparent(drawing); }; -before('renderGame', function () { - bitsy.ctx.clearRect(0, 0, bitsy.canvas.width, bitsy.canvas.height); -}); - -after('renderClearInstruction', function (bufferId, buffer, paletteIndex) { - if (bufferId !== bitsy.screenBufferId || paletteIndex !== bitsy.tileColorStartIndex) return; - var bufferContext = buffer.canvas.getContext('2d'); - bufferContext.clearRect(0, 0, buffer.canvas.width, buffer.canvas.height); +after('bitsy._graphics.clearCanvas', function () { + // eslint-disable-next-line no-underscore-dangle + bitsy.bitsy._graphics.getContext().clearRect(0, 0, bitsy.bitsy._graphics.getCanvas().width, bitsy.bitsy._graphics.getCanvas().height); }); diff --git a/dist/basic-sfx.js b/dist/basic-sfx.js index 77a59dc2..6128cebf 100644 --- a/dist/basic-sfx.js +++ b/dist/basic-sfx.js @@ -4,8 +4,8 @@ @summary "walk" and "talk" sound effect support @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -172,8 +172,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -219,11 +219,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -240,8 +235,8 @@ var after = kitsy.after; @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -266,7 +261,7 @@ function createAudio(id, options) { el.id = id; Object.assign(el, options); if (typeof src !== 'string') { - el.src = null; + el.removeAttribute('src'); src.forEach(function (s) { var sourceEl = document.createElement('source'); sourceEl.src = s; @@ -307,14 +302,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(); } diff --git a/dist/bitsymuse.js b/dist/bitsymuse.js index fd222200..61f1ffc0 100644 --- a/dist/bitsymuse.js +++ b/dist/bitsymuse.js @@ -4,8 +4,8 @@ @summary A variety of Bitsy sound and music handlers @license MIT @author David Mowatt -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -206,8 +206,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -253,11 +253,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -372,8 +367,8 @@ function addDualDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -398,7 +393,7 @@ function createAudio(id, options) { el.id = id; Object.assign(el, options); if (typeof src !== 'string') { - el.src = null; + el.removeAttribute('src'); src.forEach(function (s) { var sourceEl = document.createElement('source'); sourceEl.src = s; @@ -495,9 +490,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; } }); diff --git a/dist/canvas-replacement.js b/dist/canvas-replacement.js index 7228cbc0..ae1f4336 100644 --- a/dist/canvas-replacement.js +++ b/dist/canvas-replacement.js @@ -4,8 +4,8 @@ @summary WebGLazy bitsy integration (this one's mostly just for me) @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -203,8 +203,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -250,11 +250,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -281,7 +276,7 @@ after('startExportedGame', function () { } }); -after('update', function () { +after('bitsy._update', function () { if (hackOptions.update) { hackOptions.update(glazy); } diff --git a/dist/character-portraits-animated.js b/dist/character-portraits-animated.js index 0f213368..5d20751c 100644 --- a/dist/character-portraits-animated.js +++ b/dist/character-portraits-animated.js @@ -4,8 +4,8 @@ @summary high quality anime gifs @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -971,8 +971,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -1018,11 +1018,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -1089,8 +1084,8 @@ function addDialogTag(tag, fn) { @summary high quality anime jpegs (or pngs i guess) @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -1170,19 +1165,14 @@ addDialogTag('portrait', function (environment, parameters, onReturn) { }); // draw portrait on top of screen -after('renderDrawingBuffer', function (bufferId, buffer) { - if (bufferId !== bitsy.screenBufferId || (hackOptions$1.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$1.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$1.scale, bitsy.height * hackOptions$1.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 @@ -1282,7 +1272,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; } @@ -1308,7 +1302,11 @@ 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; }); diff --git a/dist/character-portraits.js b/dist/character-portraits.js index f6ccf49e..314a9484 100644 --- a/dist/character-portraits.js +++ b/dist/character-portraits.js @@ -4,8 +4,8 @@ @summary high quality anime jpegs (or pngs i guess) @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -200,8 +200,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -247,11 +247,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -342,19 +337,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 diff --git a/dist/close-on-ending.js b/dist/close-on-ending.js index b2b54b31..2bd20800 100644 --- a/dist/close-on-ending.js +++ b/dist/close-on-ending.js @@ -4,8 +4,8 @@ @summary Prevents from playing past an ending @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -163,8 +163,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -210,11 +210,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -229,21 +224,22 @@ var after = kitsy.after; +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(); } diff --git a/dist/corrupt.js b/dist/corrupt.js index 660069d7..6baceb11 100644 --- a/dist/corrupt.js +++ b/dist/corrupt.js @@ -4,8 +4,8 @@ @summary corrupts gamedata at runtime @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -60,46 +60,11 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ -/* -Helper used to replace code in a script tag based on a search regex -To inject code without erasing original string, using capturing groups; e.g. - inject(/(some string)/,'injected before $1 injected after') -*/ -function inject$1(searchRegex, replaceString) { - // find the relevant script tag - var scriptTags = document.getElementsByTagName('script'); - var scriptTag; - var code; - for (var i = 0; i < scriptTags.length; ++i) { - scriptTag = scriptTags[i]; - var matchesSearch = scriptTag.textContent.search(searchRegex) !== -1; - var isCurrentScript = scriptTag === document.currentScript; - if (matchesSearch && !isCurrentScript) { - code = scriptTag.textContent; - break; - } - } - - // error-handling - if (!code) { - throw new Error('Couldn\'t find "' + searchRegex + '" in script tags'); - } - - // modify the content - code = code.replace(searchRegex, replaceString); - - // replace the old script tag with a new one using our modified code - var newScriptTag = document.createElement('script'); - newScriptTag.textContent = code; - scriptTag.insertAdjacentElement('afterend', newScriptTag); - scriptTag.remove(); -} - /* Helper for getting image by name or id @@ -122,8 +87,8 @@ function getImage(name, map) { @file edit image at runtime @summary API for updating image data at runtime. @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Adds API for updating sprite, tile, and item data at runtime. @@ -142,16 +107,6 @@ e.g. the default player is: ] */ -// force cache to clear if edit image fns are used -inject$1( - /\/\/ TODO : reset render cache for this image/, - ` -Object.keys(drawingCache.render) - .filter(function (i) { return i.split('_').slice(0, -1).join('_') === drawingId; }) - .forEach(function(i) { drawingCache.render[i] = undefined; }) -` -); - /* Args: id: string id or name @@ -340,8 +295,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -387,11 +342,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -415,16 +365,19 @@ var after = kitsy.after; 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 }); } }); @@ -441,7 +394,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) { @@ -466,7 +419,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; } }); @@ -510,7 +463,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); diff --git a/dist/custom-exit-effects.js b/dist/custom-exit-effects.js index 6b373065..9b84b077 100644 --- a/dist/custom-exit-effects.js +++ b/dist/custom-exit-effects.js @@ -4,8 +4,8 @@ @summary make custom exit transition effects @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -199,8 +199,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -246,11 +246,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/custom-text-effect.js b/dist/custom-text-effect.js index 05204988..6775051d 100644 --- a/dist/custom-text-effect.js +++ b/dist/custom-text-effect.js @@ -4,8 +4,8 @@ @summary make {custom}text effects{custom} @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -26,14 +26,14 @@ HOW TO USE: TEXT EFFECT NOTES: Each effect looks like: key: function() { - this.DoEffect = function (char, time) { + this.doEffect = function (char, time) { // effect code } } The key is the text you'll write inside {} in bitsy to trigger the effect -`this.DoEffect` is called every frame for the characters the effect is applied to +`this.doEffect` is called every frame for the characters the effect is applied to The first argument is `char`, an individual character, which has the following properties: offset: offset from actual position in pixels. starts at {x:0, y:0} @@ -52,6 +52,8 @@ A few helpers are provided under `window.customTextEffects` for more complex eff - `editBitmapCopy`: copies the character bitmap and runs an edit function once The second argument is `time`, which is the time in milliseconds +The third argument is `parameters`, which are additional parameters +provided in the script (e.g. for the parametric clr effect) A number of example effects are included */ @@ -61,7 +63,7 @@ this.hacks = this.hacks || {}; var hackOptions = { 'my-effect': function () { // a horizontal wavy effect using the blue rbw colour - this.DoEffect = function (char, time) { + this.doEffect = function (char, time) { char.offset.x += 5 * Math.sin(time / 100 + char.col / 3); char.color = bitsy.rainbowColorStartIndex + 4; }; @@ -69,7 +71,7 @@ var hackOptions = { droop: function () { // causes text to droop down slowly over time // note that it's adding a custom property to the character if it doesn't already exist - this.DoEffect = function (char, time) { + this.doEffect = function (char, time) { char.start = char.start || time; char.offset.y += ((time - char.start) / 100) * Math.abs(Math.sin(char.col)); }; @@ -77,7 +79,7 @@ var hackOptions = { noise: function () { // renders noise on top of text // note that it's making a copy with `.slice()` since it's a dynamic bitmap change - this.DoEffect = function (char) { + this.doEffect = function (char) { char.bitmap = char.bitmap.slice(); for (var i = 0; i < char.bitmap.length; ++i) { char.bitmap[i] = Math.random() < 0.25 ? 1 : 0; @@ -87,7 +89,7 @@ var hackOptions = { strike: function () { // renders text with a strike-through // note that it's using `editBitmapCopy` since it's a static bitmap change - this.DoEffect = function (char) { + this.doEffect = function (char) { var font = window.fontManager.Get(window.fontName); var w = font.getWidth(); var h = font.getHeight(); @@ -102,7 +104,7 @@ var hackOptions = { // animated text scrambling // note that it's saving the original character with `saveOriginalChar` so `char.original` can be used // it's also using `setBitmap` to render a different character in the font - this.DoEffect = function (char, time) { + this.doEffect = function (char, time) { window.customTextEffects.saveOriginalChar(char); if (char.original.match(/\s|\0/)) { return; @@ -113,7 +115,7 @@ var hackOptions = { }, rot13: function () { // puts letters through the rot13 cipher (see www.rot13.com) - this.DoEffect = function (char) { + this.doEffect = function (char) { window.customTextEffects.saveOriginalChar(char); var bitmap = char.original .replace(/[a-z]/, function (c) { @@ -131,7 +133,7 @@ var hackOptions = { function posmod(a, b) { return ((a % b) + b) % b; } - this.DoEffect = function (char, time) { + this.doEffect = function (char, time) { window.customTextEffects.saveOriginalChar(char); var c = char.original[['toUpperCase', 'toLowerCase'][Math.round(posmod(time / 1000 - (char.col + char.row) / 2, 1))]](); window.customTextEffects.setBitmap(char, c); @@ -143,7 +145,7 @@ var hackOptions = { // multiple letters in order to figure out where words begin var lastSpace = 0; var lastCol = -Infinity; - this.DoEffect = function (char, time) { + this.doEffect = function (char, time) { window.customTextEffects.saveOriginalChar(char); if (char.original.match(/\s|\0/)) { return; @@ -160,7 +162,7 @@ var hackOptions = { // renders text with an italic slant // note that with higher steps, some characters will be cut off on the edges var steps = 2; - this.DoEffect = function (char) { + this.doEffect = function (char) { var font = window.fontManager.Get(window.fontName); var w = font.getWidth(); var h = font.getHeight(); @@ -178,7 +180,7 @@ var hackOptions = { // renders text with extra thickness // note that with higher weight, some characters will be cut off on the edges var weight = 2; - this.DoEffect = function (char) { + this.doEffect = function (char) { var font = window.fontManager.Get(window.fontName); var w = font.getWidth(); var h = font.getHeight(); @@ -199,7 +201,7 @@ var hackOptions = { }, u: function () { // renders text with an underline - this.DoEffect = function (char) { + this.doEffect = function (char) { var font = window.fontManager.Get(window.fontName); var w = font.getWidth(); var h = font.getHeight(); @@ -351,8 +353,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -398,11 +400,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -454,7 +451,7 @@ window.customTextEffects = { var functionMapCode = ''; var textEffectCode = ''; Object.entries(hackOptions).forEach(function (entry) { - functionMapCode += 'functionMap["' + entry[0] + '"] = function (environment, parameters, onReturn) {addOrRemoveTextEffect(environment, "' + entry[0] + '");onReturn(null);};'; + functionMapCode += 'functionMap["' + entry[0] + '"] = function (environment, parameters, onReturn) {toggleTextEffect(environment, "' + entry[0] + '");onReturn(null);};'; textEffectCode += 'TextEffects["' + entry[0] + '"] = new (' + entry[1].toString() + ')();'; }); diff --git a/dist/dialog-audio-vocal-synth.js b/dist/dialog-audio-vocal-synth.js index b9a8118f..b63411d5 100644 --- a/dist/dialog-audio-vocal-synth.js +++ b/dist/dialog-audio-vocal-synth.js @@ -4,8 +4,8 @@ @summary animal crossing-style audio powered by the pink trombone vocal synth @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -884,8 +884,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -931,11 +931,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -1002,8 +997,8 @@ function addDialogTag(tag, fn) { @summary animal crossing-style audio @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -1048,7 +1043,7 @@ var hackOptions$1 = { }; // save the character on dialog font characters so we can read it back post-render -inject(/(function DialogFontChar\(font, char, effectList\) {)/, '$1\nthis.char = char;'); +inject(/(function DialogFontChar\(font, char, effectList, effectParameterList\) {)/, '$1\nthis.char = char;'); // hook up letter function before('dialogBuffer.DoNextChar', function () { @@ -1059,8 +1054,8 @@ before('dialogBuffer.DoNextChar', function () { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -1078,7 +1073,7 @@ function clamp(value, min, max) { -var defaultVoice; +var defaultVoice = hackOptions.voices.default; var voice; // these are mostly guess-work based on playing around with the original pink trombone UI diff --git a/dist/dialog-audio.js b/dist/dialog-audio.js index 4f7cfaaf..b8fdac8a 100644 --- a/dist/dialog-audio.js +++ b/dist/dialog-audio.js @@ -4,8 +4,8 @@ @summary animal crossing-style audio @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -190,8 +190,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -237,11 +237,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -259,7 +254,7 @@ kitsy.after; // save the character on dialog font characters so we can read it back post-render -inject(/(function DialogFontChar\(font, char, effectList\) {)/, '$1\nthis.char = char;'); +inject(/(function DialogFontChar\(font, char, effectList, effectParameterList\) {)/, '$1\nthis.char = char;'); // hook up letter function before('dialogBuffer.DoNextChar', function () { diff --git a/dist/dialog-box-transition.js b/dist/dialog-box-transition.js index bb0d9f34..3f638e6b 100644 --- a/dist/dialog-box-transition.js +++ b/dist/dialog-box-transition.js @@ -4,8 +4,8 @@ @summary adds an easing transition animation to display the dialog box text @license MIT @author Delacannon -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -18,7 +18,19 @@ this.hacks = this.hacks || {}; (function (exports, bitsy) { 'use strict'; var hackOptions = { - easing: 0.025, // easing speed + // easing function applied to the transition + // the provided parameter is the time in 0-1, + // and the expected return value is a value in 0-1 + // that indicates how much to lerp between the + // screen edge and the final position + // + // the default is a quadratic ease out, + // see https://gist.github.com/gre/1650294 for more examples + ease: function (t) { + return t * (2 - t); + }, + // how long the transition lasts + duration: 500, }; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } @@ -34,7 +46,7 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); * @param searcher Regex to search and replace * @param replacer Replacer string/fn */ -function inject$1(searcher, replacer) { +function inject(searcher, replacer) { // find the relevant script tag var scriptTags = document.getElementsByTagName('script'); var scriptTag; @@ -90,18 +102,18 @@ function kitsyInject(searcher, replacer) { // Ex: before('load_game', function run() { alert('Loading!'); }); // before('show_text', function run(text) { return text.toUpperCase(); }); // before('show_text', function run(text, done) { done(text.toUpperCase()); }); -function before(targetFuncName, beforeFn) { +function before$1(targetFuncName, beforeFn) { kitsy.queuedBeforeScripts[targetFuncName] = kitsy.queuedBeforeScripts[targetFuncName] || []; kitsy.queuedBeforeScripts[targetFuncName].push(beforeFn); } // Ex: after('load_game', function run() { alert('Loaded!'); }); -function after(targetFuncName, afterFn) { +function after$1(targetFuncName, afterFn) { kitsy.queuedAfterScripts[targetFuncName] = kitsy.queuedAfterScripts[targetFuncName] || []; kitsy.queuedAfterScripts[targetFuncName].push(afterFn); } function applyInjects() { kitsy.queuedInjectScripts.forEach(function (injectScript) { - inject$1(injectScript.searcher, injectScript.replacer); + inject(injectScript.searcher, injectScript.replacer); }); } function applyHooks(root) { @@ -160,8 +172,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -169,8 +181,8 @@ var kitsy = (window.kitsy = window.kitsy || { queuedBeforeScripts: {}, queuedAfterScripts: {}, inject: kitsyInject, - before, - after, + before: before$1, + after: after$1, /** * Applies all queued `inject` calls. * @@ -207,74 +219,50 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; } /** @see kitsy.inject */ -var inject = kitsy.inject; +kitsy.inject; /** @see kitsy.before */ -kitsy.before; +var before = kitsy.before; /** @see kitsy.after */ -kitsy.after; +var after = kitsy.after; -var drawOverride = ` -if (isCentered) { - bitsyDrawBegin(0); - bitsyDrawTextbox(textboxInfo.left, ((height / 2) - (textboxInfo.height / 2))); - bitsyDrawEnd(); - this.onExit = ((height/2)-(textboxInfo.height/2)) === ((height/2)-(textboxInfo.height/2)) -} -else if (player().y < mapsize/2) { - easingDialog(textboxInfo, ${hackOptions.easing}, !this.onClose - ? height-textboxInfo.bottom-textboxInfo.height - : height+textboxInfo.height - ); - this.onExit = this.onClose && textboxInfo.y >= height; -} -else { - easingDialog(textboxInfo, ${hackOptions.easing}, !this.onClose - ? textboxInfo.top - : -textboxInfo.top-textboxInfo.height - ); - this.onExit = this.onClose && textboxInfo.y <= -textboxInfo.height; +function lerp(from, to, by) { + return from + (to - from) * by; } -return;`; -var functionEasing = ` - function easingDialog(tbox, easing, targetY) { - var vy = (targetY - tbox.y) * easing; - tbox.y += vy; - bitsyDrawBegin(0); - bitsyDrawTextbox(tbox.left, tbox.y); - bitsyDrawEnd(); - } - this.onClose = false; - this.onExit = false; -`; +var start; +var height = 0; -inject(/(this\.DrawTextbox\(\))/, '$1\nif(this.onExit && this.onClose){dialogBuffer.EndDialog()}'); -inject(/(\/\/end dialog mode\s+this\.EndDialog\(\))/m, 'dialogRenderer.onClose=true'); -inject(/(var DialogRenderer = function\(\) {)/, `$1${functionEasing}`); -inject(/(var textboxInfo = {)/, '$1y:0,'); -inject( - /(this\.Reset = function\(\) {)/, - `$1 this.onClose=false; - this.onExit=false; - textboxInfo.y = player().y < mapsize/2 ? height : -(textboxInfo.height);` -); +// always redraw the full room when sprites are moving +before('drawRoom', function (room, args) { + args.redrawAll = true; + return [room, args]; +}); -inject(/(this\.DrawTextbox = function\(\) {)/, `$1${drawOverride}`); +var edge = 0; +before('bitsy.textbox', function (visible, x, y, w, h) { + height = h || height; + edge = y < bitsy.height / 2 ? -height : bitsy.height; +}); +before('bitsy._graphics.drawImage', function (id, x, y) { + if (id !== bitsy.bitsy.TEXTBOX) return undefined; + if (!start) { + start = bitsy.prevTime; + } + return [id, x, lerp(edge, y, hackOptions.ease(Math.min(Math.max(0, (bitsy.prevTime - start) / hackOptions.duration), 1)))]; +}); +after('onExitDialog', function () { + start = undefined; +}); exports.hackOptions = hackOptions; diff --git a/dist/dialog-choices.js b/dist/dialog-choices.js index cb475107..cc51568e 100644 --- a/dist/dialog-choices.js +++ b/dist/dialog-choices.js @@ -4,8 +4,8 @@ @summary dialog choices @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -240,8 +240,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -287,11 +287,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -415,8 +410,8 @@ inject(/(this\.AddLinebreak = )/, 'this.AddParagraphBreak = function() { buffer. @summary Adds paragraph breaks to the dialogue parser @license WTFPL (do WTF you want) @author Sean S. LeBlanc, David Mowatt -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -459,8 +454,8 @@ addDialogTag('p', function (environment, parameters, onReturn) { @summary put more words onscreen @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -500,7 +495,7 @@ var hackOptions$1 = { kitsy.longDialogOptions = hackOptions$1; -// override textbox height +// override textbox height to be dynamic based on row count inject( /textboxInfo\.height = .+;/, `Object.defineProperty(textboxInfo, 'height', { @@ -509,14 +504,29 @@ inject( ); // export textbox info inject(/(var font = null;)/, 'this.textboxInfo = textboxInfo;$1'); -before('renderDrawingBuffer', function (bufferId, buffer) { - if (bufferId !== bitsy.textboxBufferId) return; - buffer.height = bitsy.dialogRenderer.textboxInfo.height / bitsy.dialogRenderer.textboxInfo.font_scale; -}); // rewrite hard-coded row limit inject(/(else if \(curRowIndex )== 0/g, '$1 < window.kitsy.longDialogOptions.maxRows - 1'); inject(/(if \(lastPage\.length) <= 1/, '$1 < window.kitsy.longDialogOptions.maxRows'); +// update textbox size +var ph; +function updateTextbox() { + var h = bitsy.dialogRenderer.textboxInfo.height; + if (h === ph) return; + ph = h; + var textScale = bitsy.bitsy.textMode() === bitsy.bitsy.TXT_LOREZ ? 1 : 2; + bitsy.bitsy.textbox(undefined, undefined, undefined, undefined, h * textScale); +} +before('dialogRenderer.Draw', updateTextbox); + +// reserve textbox memory on startup to avoid flickering +// when it expands dynamically +after('dialogRenderer.SetFont', function () { + // eslint-disable-next-line no-underscore-dangle + var t = bitsy.bitsy._dump()[bitsy.bitsy.TEXTBOX]; + t.length = Math.max(t.length, 256000); +}); + addDualDialogTag('textboxsize', function (environment, parameters) { if (!parameters[0]) { throw new Error('{textboxsize} was missing parameters! Usage: {textboxsize "minrows, maxrows"}'); @@ -527,6 +537,8 @@ addDualDialogTag('textboxsize', function (environment, parameters) { var max = parseInt(params[1], 10); hackOptions$1.minRows = min; hackOptions$1.maxRows = max; + + updateTextbox(); }); @@ -544,43 +556,27 @@ var dialogChoices = { if (!this.choicesActive) { return false; } - var pmoved = this.moved; - this.moved = bitsy.input.anyKeyDown() || bitsy.input.swipeUp() || bitsy.input.swipeDown() || bitsy.input.swipeRight(); var l = Math.max(this.choices.length, 1); // navigate - if (!pmoved && ((bitsy.input.anyKeyDown() && (bitsy.input.isKeyDown(bitsy.key.up) || bitsy.input.isKeyDown(bitsy.key.w))) || bitsy.input.swipeUp())) { + if (bitsy.bitsy.button(bitsy.bitsy.BTN_UP)) { this.choice -= 1; if (this.choice < 0) { this.choice += l; } return false; } - if (!pmoved && ((bitsy.input.anyKeyDown() && (bitsy.input.isKeyDown(bitsy.key.down) || bitsy.input.isKeyDown(bitsy.key.s))) || bitsy.input.swipeDown())) { + if (bitsy.bitsy.button(bitsy.bitsy.BTN_DOWN)) { this.choice = (this.choice + 1) % l; return false; } // select - if ( - !pmoved && - ((bitsy.input.anyKeyDown() && - (bitsy.input.isKeyDown(bitsy.key.right) || bitsy.input.isKeyDown(bitsy.key.d) || bitsy.input.isKeyDown(bitsy.key.enter) || bitsy.input.isKeyDown(bitsy.key.space))) || - bitsy.input.swipeRight()) - ) { + if (bitsy.bitsy.button(bitsy.bitsy.BTN_RIGHT)) { // evaluate choice this.choices[this.choice](); // reset this.choice = 0; this.choices = []; this.choicesActive = false; - // get back into the regular dialog flow - if (dialogBuffer.Continue()) { - dialogBuffer.Update(0); - // make sure to close dialog if there's nothing to say - // after the choice has been made - if (!dialogBuffer.CurCharCount()) { - dialogBuffer.EndDialog(); - } - } return true; } return false; @@ -616,9 +612,9 @@ else if(sequenceType === "choice") { ); inject( - /(var ShuffleNode = )/, + /(function ShuffleNode\(options\) {)/, ` -var ChoiceNode = function(options) { +function ChoiceNode(options) { Object.assign( this, new TreeRelationship() ); Object.assign( this, new SequenceBase() ); this.type = "choice"; @@ -644,6 +640,12 @@ var ChoiceNode = function(options) { children[i].Eval(environment, function(val) { if (i === children.length - 1) { environment.GetDialogBuffer().AddParagraphBreak(); + environment.GetDialogBuffer().AddScriptReturn(function () { + // end dialog if there's no content after the choice + if (environment.GetDialogBuffer().CurCharCount() <= 1) { + environment.GetDialogBuffer().EndDialog(); + } + }); } else { environment.GetDialogBuffer().AddLinebreak(); } @@ -654,9 +656,7 @@ var ChoiceNode = function(options) { } else { done(); - setTimeout(() => { - window.dialogChoices.choicesActive = true; - }); + window.dialogChoices.choicesActive = true; } } window.dialogChoices.choices = this.options.map(function(option){ @@ -685,7 +685,9 @@ inject( /(this\.DrawNextArrow = )/, ` this.DrawChoiceArrow = function() { - bitsyDrawBegin(1); + var text_scale = getTextScale(); + var textboxScaleW = textboxInfo.width * text_scale; + var textboxScaleH = textboxInfo.height * text_scale; var rows = ${hackOptions.cursor}; var top = (${hackOptions.transform.y} + window.dialogChoices.choice * (textboxInfo.padding_vert + relativeFontHeight())) * text_scale; var left = ${hackOptions.transform.x}*text_scale; @@ -696,18 +698,19 @@ this.DrawChoiceArrow = function() { //scaling nonsense for (var sy = 0; sy < text_scale; sy++) { for (var sx = 0; sx < text_scale; sx++) { - bitsyDrawPixel(textArrowIndex, left + (x * text_scale) + sx, top + (y * text_scale) + sy); + var px = left + (x * text_scale) + sx; + var py = top + (y * text_scale) + sy; + bitsy.set(bitsy.TEXTBOX, (py * textboxScaleW) + px, textArrowIndex); } } } } } - bitsyDrawEnd(); }; $1` ); inject( - /(this\.DrawTextbox\(\);)/, + /(if \(buffer.CanContinue\(\) && shouldDrawArrow\) {)/, ` if (window.dialogChoices.choicesActive) { this.DrawChoiceArrow(); @@ -717,13 +720,7 @@ $1` // interaction // (overrides the dialog skip/page flip) -inject( - /(if\(\s*dialogBuffer\.IsActive\(\)\s*\) {)/, - `$1 -if(window.dialogChoices.handleInput(dialogBuffer)) { - return; -} else ` -); +inject(/(dialogBuffer.CanContinue)/, `(!window.dialogChoices.choicesActive || window.dialogChoices.handleInput(dialogBuffer)) && $1`); inject( /(this\.CanContinue = function\(\) {)/, `$1 @@ -733,6 +730,11 @@ if(window.dialogChoices.choicesActive){ ` ); +// force redrawing textbox to avoid flickering issues +inject(/shouldClearTextbox = false;/, ''); +inject(/char.redraw = false;/, ''); +inject(/shouldDrawArrow = false;/, ''); + exports.hackOptions = hackOptions; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/dist/dialog-jump.js b/dist/dialog-jump.js index dc5e404b..86b0dd04 100644 --- a/dist/dialog-jump.js +++ b/dist/dialog-jump.js @@ -4,8 +4,8 @@ @summary jump from one dialog entry to another @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -174,8 +174,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -221,11 +221,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/dialog-pause.js b/dist/dialog-pause.js index d6b2ca9a..9207ed5e 100644 --- a/dist/dialog-pause.js +++ b/dist/dialog-pause.js @@ -4,8 +4,8 @@ @summary add pauses in between printing text @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -160,8 +160,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -207,11 +207,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/dialog-prompt.js b/dist/dialog-prompt.js index 7b9d5ee4..1afcf9ff 100644 --- a/dist/dialog-prompt.js +++ b/dist/dialog-prompt.js @@ -4,8 +4,8 @@ @summary prompt the user for text input in dialog @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -197,8 +197,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -244,11 +244,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -322,8 +317,8 @@ inject(/(this\.AddLinebreak = )/, 'this.AddParagraphBreak = function() { buffer. @summary Adds paragraph breaks to the dialogue parser @license WTFPL (do WTF you want) @author Sean S. LeBlanc, David Mowatt -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -431,19 +426,13 @@ addDialogTag('prompt', function (environment, parameters, onReturn) { var defaultValue = params[1] || ''; // prevent bitsy from handling input - var key = bitsy.key; var isPlayerEmbeddedInEditor = bitsy.isPlayerEmbeddedInEditor; - var anyKeyPressed = bitsy.input.anyKeyPressed; - var isTapReleased = bitsy.input.isTapReleased; + var isAnyButtonDown = bitsy.isAnyButtonDown; var CanContinue = environment.GetDialogBuffer().CanContinue; - bitsy.key = {}; - bitsy.input.anyKeyPressed = - bitsy.input.isTapReleased = - environment.GetDialogBuffer().CanContinue = - function () { - return false; - }; bitsy.isPlayerEmbeddedInEditor = true; + bitsy.isAnyButtonDown = environment.GetDialogBuffer().CanContinue = function () { + return false; + }; promptInput.value = defaultValue; promptInput.focus(); @@ -460,10 +449,8 @@ addDialogTag('prompt', function (environment, parameters, onReturn) { promptInput.blur(); // allow bitsy to start handling input again - bitsy.key = key; bitsy.isPlayerEmbeddedInEditor = isPlayerEmbeddedInEditor; - bitsy.input.anyKeyPressed = anyKeyPressed; - bitsy.input.isTapReleased = isTapReleased; + bitsy.isAnyButtonDown = isAnyButtonDown; environment.GetDialogBuffer().CanContinue = CanContinue; onReturn(null); @@ -478,6 +465,11 @@ addDialogTag('prompt', function (environment, parameters, onReturn) { // expose a setter/getter for private buffer in DialogBuffer class inject(/(this\.CurPage =)/, 'this.GetBuffer = function(){ return buffer; };this.SetBuffer = function(b){ buffer = b; };\n$1'); +// force redrawing textbox to allow interactive preview +inject(/shouldClearTextbox = false;/, ''); +inject(/char.redraw = false;/, ''); +inject(/shouldDrawArrow = false;/, ''); + exports.hackOptions = hackOptions; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/dist/direction-in-dialog.js b/dist/direction-in-dialog.js index e3bd3fb1..db662cd2 100644 --- a/dist/direction-in-dialog.js +++ b/dist/direction-in-dialog.js @@ -4,8 +4,8 @@ @summary provides a variable with player direction @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -166,8 +166,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -213,11 +213,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/directional-avatar.js b/dist/directional-avatar.js index d3e56f07..5c74a8e4 100644 --- a/dist/directional-avatar.js +++ b/dist/directional-avatar.js @@ -4,8 +4,8 @@ @summary flips the player's sprite based on directional movement @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -41,46 +41,11 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ -/* -Helper used to replace code in a script tag based on a search regex -To inject code without erasing original string, using capturing groups; e.g. - inject(/(some string)/,'injected before $1 injected after') -*/ -function inject$1(searchRegex, replaceString) { - // find the relevant script tag - var scriptTags = document.getElementsByTagName('script'); - var scriptTag; - var code; - for (var i = 0; i < scriptTags.length; ++i) { - scriptTag = scriptTags[i]; - var matchesSearch = scriptTag.textContent.search(searchRegex) !== -1; - var isCurrentScript = scriptTag === document.currentScript; - if (matchesSearch && !isCurrentScript) { - code = scriptTag.textContent; - break; - } - } - - // error-handling - if (!code) { - throw new Error('Couldn\'t find "' + searchRegex + '" in script tags'); - } - - // modify the content - code = code.replace(searchRegex, replaceString); - - // replace the old script tag with a new one using our modified code - var newScriptTag = document.createElement('script'); - newScriptTag.textContent = code; - scriptTag.insertAdjacentElement('afterend', newScriptTag); - scriptTag.remove(); -} - /* Helper for getting image by name or id @@ -103,8 +68,8 @@ function getImage(name, map) { @file edit image at runtime @summary API for updating image data at runtime. @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Adds API for updating sprite, tile, and item data at runtime. @@ -123,16 +88,6 @@ e.g. the default player is: ] */ -// force cache to clear if edit image fns are used -inject$1( - /\/\/ TODO : reset render cache for this image/, - ` -Object.keys(drawingCache.render) - .filter(function (i) { return i.split('_').slice(0, -1).join('_') === drawingId; }) - .forEach(function(i) { drawingCache.render[i] = undefined; }) -` -); - /* Args: id: string id or name @@ -235,7 +190,7 @@ function kitsyInject(searcher, replacer) { // Ex: before('load_game', function run() { alert('Loading!'); }); // before('show_text', function run(text) { return text.toUpperCase(); }); // before('show_text', function run(text, done) { done(text.toUpperCase()); }); -function before$1(targetFuncName, beforeFn) { +function before(targetFuncName, beforeFn) { kitsy.queuedBeforeScripts[targetFuncName] = kitsy.queuedBeforeScripts[targetFuncName] || []; kitsy.queuedBeforeScripts[targetFuncName].push(beforeFn); } @@ -305,8 +260,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -314,7 +269,7 @@ var kitsy = (window.kitsy = window.kitsy || { queuedBeforeScripts: {}, queuedAfterScripts: {}, inject: kitsyInject, - before: before$1, + before, after: after$1, /** * Applies all queued `inject` calls. @@ -352,11 +307,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -365,7 +315,7 @@ if (!hooked) { /** @see kitsy.inject */ kitsy.inject; /** @see kitsy.before */ -var before = kitsy.before; +kitsy.before; /** @see kitsy.after */ var after = kitsy.after; @@ -451,12 +401,12 @@ after('updateInput', function () { vflip = vflip && allowed.verticalFlipAllowed; hflip = hflip && allowed.horizontalFlipAllowed; }); -before('drawRoom', function () { +after('updateInput', function () { for (var i = 0; i < bitsy.player().animation.frameCount; ++i) { setSpriteData(bitsy.playerId, i, transformSpriteData(getSpriteData(bitsy.playerId, i), vflip, hflip)); } }); -after('drawRoom', function () { +after('bitsy._update', function () { for (var i = 0; i < bitsy.player().animation.frameCount; ++i) { setSpriteData(bitsy.playerId, i, transformSpriteData(getSpriteData(bitsy.playerId, i), vflip, hflip)); } diff --git a/dist/dynamic-background.js b/dist/dynamic-background.js index 028df3f6..338f191f 100644 --- a/dist/dynamic-background.js +++ b/dist/dynamic-background.js @@ -4,8 +4,8 @@ @summary HTML background matching bitsy background @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -170,8 +170,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -217,11 +217,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -238,8 +233,8 @@ var after = kitsy.after; @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -261,13 +256,13 @@ function getRoom(name) { // and updates the background to match function updateBg() { // get the palette colour - var c = hackOptions.byRoom[bitsy.curRoom]; + var c = hackOptions.byRoom[bitsy.state.room]; if (c === undefined) { c = hackOptions.default; } // if the palette changed, update background - var bg = 'rgb(' + bitsy.getPal(bitsy.curPal())[c].join(',') + ')'; + var bg = 'rgb(' + bitsy.getPal(bitsy.state.pal)[c].join(',') + ')'; if (document.body.style.background !== bg) { document.body.style.background = bg; } @@ -286,7 +281,7 @@ after('load_game', function () { // wrap every function which involves changing the palette after('movePlayer', updateBg); -after('parseWorld', updateBg); +after('loadWorldFromGameData', updateBg); after('movePlayerThroughExit', updateBg); exports.hackOptions = hackOptions; diff --git a/dist/edit-dialog-from-dialog.js b/dist/edit-dialog-from-dialog.js index b937a70f..d5477db4 100644 --- a/dist/edit-dialog-from-dialog.js +++ b/dist/edit-dialog-from-dialog.js @@ -4,8 +4,8 @@ @summary edit dialog from dialog (yes really) @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -169,8 +169,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -216,11 +216,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -297,8 +292,8 @@ function addDeferredDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ diff --git a/dist/edit-image-from-dialog.js b/dist/edit-image-from-dialog.js index f45f1466..9e6ba4ab 100644 --- a/dist/edit-image-from-dialog.js +++ b/dist/edit-image-from-dialog.js @@ -4,8 +4,8 @@ @summary edit sprites, items, and tiles from dialog @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -67,46 +67,11 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ -/* -Helper used to replace code in a script tag based on a search regex -To inject code without erasing original string, using capturing groups; e.g. - inject(/(some string)/,'injected before $1 injected after') -*/ -function inject$2(searchRegex, replaceString) { - // find the relevant script tag - var scriptTags = document.getElementsByTagName('script'); - var scriptTag; - var code; - for (var i = 0; i < scriptTags.length; ++i) { - scriptTag = scriptTags[i]; - var matchesSearch = scriptTag.textContent.search(searchRegex) !== -1; - var isCurrentScript = scriptTag === document.currentScript; - if (matchesSearch && !isCurrentScript) { - code = scriptTag.textContent; - break; - } - } - - // error-handling - if (!code) { - throw new Error('Couldn\'t find "' + searchRegex + '" in script tags'); - } - - // modify the content - code = code.replace(searchRegex, replaceString); - - // replace the old script tag with a new one using our modified code - var newScriptTag = document.createElement('script'); - newScriptTag.textContent = code; - scriptTag.insertAdjacentElement('afterend', newScriptTag); - scriptTag.remove(); -} - /* Helper for getting image by name or id @@ -129,8 +94,8 @@ function getImage(name, map) { @file edit image at runtime @summary API for updating image data at runtime. @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Adds API for updating sprite, tile, and item data at runtime. @@ -149,16 +114,6 @@ e.g. the default player is: ] */ -// force cache to clear if edit image fns are used -inject$2( - /\/\/ TODO : reset render cache for this image/, - ` -Object.keys(drawingCache.render) - .filter(function (i) { return i.split('_').slice(0, -1).join('_') === drawingId; }) - .forEach(function(i) { drawingCache.render[i] = undefined; }) -` -); - /* Args: id: string id or name @@ -323,8 +278,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -370,11 +325,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -537,6 +487,7 @@ function editImage(environment, parameters) { for (i = 0; i < srcObj.animation.frameCount; ++i) { setImageData(tgtId, i, mapObj, getImageData(srcId, i, mapObj)); } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function editPalette(environment, parameters) { @@ -567,6 +518,7 @@ function editPalette(environment, parameters) { // set palette tgtObj.col = palObj; + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } // hook up the dialog tags diff --git a/dist/edit-player-from-dialog.js b/dist/edit-player-from-dialog.js index 96b445d0..d7b89ad5 100644 --- a/dist/edit-player-from-dialog.js +++ b/dist/edit-player-from-dialog.js @@ -4,8 +4,8 @@ @summary change which sprite is controlled by the player @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -28,6 +28,8 @@ NOTE: - Inventory (i.e. item counts) is per-sprite, not shared. If you want to simulate "shared" inventory, include standard dialog variables on your items that increment when picked up +- If you only want to change the avatar to visually match another sprite, + you should use the built-in `AVA` dialog command instead of this hack */ (function (bitsy) { 'use strict'; @@ -171,8 +173,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -218,11 +220,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -337,8 +334,8 @@ function addDualDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -371,8 +368,15 @@ addDualDialogTag('player', function (environment, parameters) { if (!target.room) { throw new Error('Could not change player: sprite "' + targetId + '" not placed in a room'); } + var original = bitsy.player(); + original.type = 'SPR'; bitsy.playerId = targetId; - bitsy.curRoom = target.room; + bitsy.state.ava = target.drw; + bitsy.state.room = target.room; + bitsy.playerPrevX = target.x; + bitsy.playerPrevY = target.y; + target.type = 'AVA'; + bitsy.drawRoom(bitsy.room[target.room], { redrawAll: true }); }); })(window); diff --git a/dist/edit-room-from-dialog.js b/dist/edit-room-from-dialog.js index 72337409..3aa2bb03 100644 --- a/dist/edit-room-from-dialog.js +++ b/dist/edit-room-from-dialog.js @@ -4,8 +4,8 @@ @summary modify the content of a room from dialog @license MIT @author Dana Holdampf -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -290,8 +290,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -337,11 +337,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -456,8 +451,8 @@ function addDualDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -619,7 +614,7 @@ function drawAt(mapId, sourceId, xPos, yPos, roomId) { } // Trim and sanitize Room ID parameter, and set to current room if omitted - roomId = (roomId || bitsy.curRoom).toString().trim(); + roomId = (roomId || bitsy.state.room).toString().trim(); if (!bitsy.room[roomId]) { console.log("CAN'T DRAW. ROOM ID (" + roomId + ') NOT FOUND.'); return; @@ -653,6 +648,7 @@ function drawAt(mapId, sourceId, xPos, yPos, roomId) { } break; } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function drawBoxAt(mapId, sourceId, x1, y1, x2, y2, roomId) { @@ -673,6 +669,7 @@ function drawBoxAt(mapId, sourceId, x1, y1, x2, y2, roomId) { drawAt(mapId, sourceId, xPos, yPos, roomId); } } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function eraseAt(mapId, targetId, xPos, yPos, roomId) { @@ -694,7 +691,7 @@ function eraseAt(mapId, targetId, xPos, yPos, roomId) { } // Trim and sanitize Room ID parameter, and set to current room if omitted - roomId = (roomId || bitsy.curRoom).toString().trim(); + roomId = (roomId || bitsy.state.room).toString().trim(); if (!bitsy.room[roomId]) { console.log("CAN'T DRAW. ROOM ID (" + roomId + ') NOT FOUND.'); return; @@ -735,6 +732,7 @@ function eraseAt(mapId, targetId, xPos, yPos, roomId) { } } } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function eraseBoxAt(mapId, targetId, x1, y1, x2, y2, roomId) { @@ -755,6 +753,7 @@ function eraseBoxAt(mapId, targetId, x1, y1, x2, y2, roomId) { eraseAt(mapId, targetId, xPos, yPos, roomId); } } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function replaceAt(targetMapId, targetId, newMapId, newId, xPos, yPos, roomId) { @@ -792,7 +791,7 @@ function replaceAt(targetMapId, targetId, newMapId, newId, xPos, yPos, roomId) { } // Trim and sanitize Room ID parameter, and set to current room if omitted - roomId = (roomId || bitsy.curRoom).toString().trim(); + roomId = (roomId || bitsy.state.room).toString().trim(); if (!bitsy.room[roomId]) { console.log("CAN'T REPLACE. ROOM ID (" + roomId + ') NOT FOUND.'); return; @@ -842,6 +841,7 @@ function replaceAt(targetMapId, targetId, newMapId, newId, xPos, yPos, roomId) { } } } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function replaceBoxAt(targetMapId, targetId, newMapId, newId, x1, y1, x2, y2, roomId) { @@ -862,6 +862,7 @@ function replaceBoxAt(targetMapId, targetId, newMapId, newId, x1, y1, x2, y2, ro replaceAt(targetMapId, targetId, newMapId, newId, xPos, yPos, roomId); } } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function copyAt(mapId, targetId, copyXPos, copyYPos, copyRoomId, pasteXPos, pasteYPos, pasteRoomId) { @@ -884,7 +885,7 @@ function copyAt(mapId, targetId, copyXPos, copyYPos, copyRoomId, pasteXPos, past } // Trim and sanitize Target ID parameter, and use any if not provided - copyRoomId = (copyRoomId || bitsy.curRoom).toString().trim(); + copyRoomId = (copyRoomId || bitsy.state.room).toString().trim(); if (!bitsy.room[copyRoomId]) { console.log("CAN'T COPY. ROOM ID (" + copyRoomId + ') NOT FOUND.'); return; @@ -903,7 +904,7 @@ function copyAt(mapId, targetId, copyXPos, copyYPos, copyRoomId, pasteXPos, past return; } - pasteRoomId = (pasteRoomId || bitsy.curRoom).toString().trim(); + pasteRoomId = (pasteRoomId || bitsy.state.room).toString().trim(); if (!bitsy.room[pasteRoomId]) { console.log("CAN'T PASTE. ROOM ID (" + pasteRoomId + ') NOT FOUND.'); return; @@ -946,6 +947,7 @@ function copyAt(mapId, targetId, copyXPos, copyYPos, copyRoomId, pasteXPos, past } } } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function copyBoxAt(mapId, targetId, x1, y1, x2, y2, copyRoomId, pasteXPos, pasteYPos, pasteRoomId) { @@ -961,7 +963,7 @@ function copyBoxAt(mapId, targetId, x1, y1, x2, y2, copyRoomId, pasteXPos, paste // Trim and sanitize Target ID parameter, and use any if not provided targetId = (targetId || 'ANY').toString().trim(); - copyRoomId = (copyRoomId || bitsy.curRoom).toString().trim(); + copyRoomId = (copyRoomId || bitsy.state.room).toString().trim(); if (!bitsy.room[copyRoomId]) { console.log("CAN'T COPY. ROOM ID (" + copyRoomId + ') NOT FOUND.'); return; @@ -980,7 +982,7 @@ function copyBoxAt(mapId, targetId, x1, y1, x2, y2, copyRoomId, pasteXPos, paste return; } - pasteRoomId = (pasteRoomId || bitsy.curRoom).toString().trim(); + pasteRoomId = (pasteRoomId || bitsy.state.room).toString().trim(); if (!bitsy.room[pasteRoomId]) { console.log("CAN'T PASTE. ROOM ID (" + pasteRoomId + ') NOT FOUND.'); return; @@ -1069,6 +1071,7 @@ function copyBoxAt(mapId, targetId, x1, y1, x2, y2, copyRoomId, pasteXPos, paste copy.forEach(function (copyEntry) { drawAt(copyEntry.map, copyEntry.id, copyEntry.x, copyEntry.y, pasteRoomId); }); + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } })(window); diff --git a/dist/end-from-dialog.js b/dist/end-from-dialog.js index 8b5bf758..0c7f362a 100644 --- a/dist/end-from-dialog.js +++ b/dist/end-from-dialog.js @@ -1,11 +1,11 @@ /** ๐Ÿ”š @file end-from-dialog -@summary trigger an ending from dialog, including narration text +@summary trigger an ending from dialog, including narration text (deprecated) @license WTFPL (do WTF you want) @author @mildmojo -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -194,8 +194,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -241,11 +241,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/exit-from-dialog.js b/dist/exit-from-dialog.js index 26a07925..6e8865e7 100644 --- a/dist/exit-from-dialog.js +++ b/dist/exit-from-dialog.js @@ -4,8 +4,8 @@ @summary exit to another room from dialog, including conditionals @license WTFPL (do WTF you want) @author @mildmojo -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -194,8 +194,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -241,11 +241,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -360,8 +355,8 @@ function addDualDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ diff --git a/dist/external-game-data.js b/dist/external-game-data.js index a988065b..43985457 100644 --- a/dist/external-game-data.js +++ b/dist/external-game-data.js @@ -4,8 +4,8 @@ @summary separate Bitsy game data from your (modded) HTML for easier development @license WTFPL (do WTF you want) @author @mildmojo -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -182,8 +182,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -229,11 +229,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/favicon-from-sprite.js b/dist/favicon-from-sprite.js index 8ee65e0c..81be50ad 100644 --- a/dist/favicon-from-sprite.js +++ b/dist/favicon-from-sprite.js @@ -4,8 +4,8 @@ @summary generate a browser favicon (tab icon) from a Bitsy sprite, including animation! @license WTFPL (do WTF you want) @author @mildmojo -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -170,8 +170,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -217,11 +217,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -238,8 +233,8 @@ var after = kitsy.after; @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ diff --git a/dist/follower.js b/dist/follower.js index c2d53669..11362a65 100644 --- a/dist/follower.js +++ b/dist/follower.js @@ -4,8 +4,8 @@ @summary make sprites follow the player @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -193,8 +193,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -240,11 +240,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -359,8 +354,8 @@ function addDualDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -412,12 +407,16 @@ function takeStep() { return; } walking = true; - setTimeout(() => { + if (hackOptions.delay) { + setTimeout(() => { + shouldWalk = true; + }, hackOptions.delay); + } else { shouldWalk = true; - }, hackOptions.delay); + } } -after('startExportedGame', function () { +after('loadWorldFromGameData', function () { hackOptions.followers.forEach(setFollower); // remove + add player to sprite list to force rendering them on top of followers @@ -428,12 +427,14 @@ after('startExportedGame', function () { let px; let py; -before('update', function () { +before('bitsy._update', function () { + var player = bitsy.player(); + if (!player) return; px = bitsy.player().x; py = bitsy.player().y; }); let movedFollower = false; -after('update', function () { +after('bitsy._update', function () { if (shouldWalk) { shouldWalk = false; let takeAnother = false; @@ -450,6 +451,7 @@ after('update', function () { takeAnother = true; } }); + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); if (takeAnother) { takeStep(); } @@ -594,6 +596,7 @@ addDualDialogTag('followerSync', function () { follower.y = player.y; paths[follower.id].length = 0; }); + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); }); exports.followers = followers; diff --git a/dist/gamepad-input.js b/dist/gamepad-input.js index ff762ac6..beecf754 100644 --- a/dist/gamepad-input.js +++ b/dist/gamepad-input.js @@ -4,8 +4,8 @@ @summary HTML5 gamepad support @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -489,8 +489,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -536,11 +536,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -556,7 +551,6 @@ var after = kitsy.after; var gamepads = new Gamepads(); -var empty = function () {}; var move = function (dpad, face, axis, axis2, axispast, axisdir, key) { // keydown @@ -567,29 +561,32 @@ var move = function (dpad, face, axis, axis2, axispast, axisdir, key) { gamepads.axisJustPast(axis2, axispast, axisdir) || (bitsy.playerHoldToMoveTimer <= 0 && (gamepads.isDown(dpad) || gamepads.isDown(face) || gamepads.axisPast(axis, axispast, axisdir))) ) { - bitsy.curPlayerDirection = bitsy.Direction.None; - bitsy.input.onkeydown({ - keyCode: key, - preventDefault: empty, - }); + // eslint-disable-next-line no-underscore-dangle + bitsy.bitsy._poke(bitsy.bitsy._buttonBlock, key, 1); } // keyup if (gamepads.isJustUp(dpad) || gamepads.isJustUp(face) || gamepads.axisJustPast(axis, axispast, -axisdir) || gamepads.axisJustPast(axis2, axispast, -axisdir)) { - bitsy.input.onkeyup({ - keyCode: key, - preventDefault: empty, - }); + // eslint-disable-next-line no-underscore-dangle + bitsy.bitsy._poke(bitsy.bitsy._buttonBlock, key, 0); } }; -before('update', function () { - move(Buttons.DPAD_LEFT, Buttons.X, Axes.LSTICK_H, Axes.RSTICK_H, -0.5, -1, bitsy.key.left); - move(Buttons.DPAD_RIGHT, Buttons.B, Axes.LSTICK_H, Axes.RSTICK_H, 0.5, 1, bitsy.key.right); - move(Buttons.DPAD_UP, Buttons.Y, Axes.LSTICK_V, Axes.RSTICK_V, -0.5, -1, bitsy.key.up); - move(Buttons.DPAD_DOWN, Buttons.A, Axes.LSTICK_V, Axes.RSTICK_V, 0.5, 1, bitsy.key.down); +before('updateInput', function () { + move(Buttons.DPAD_LEFT, Buttons.X, Axes.LSTICK_H, Axes.RSTICK_H, -0.5, -1, bitsy.bitsy.BTN_LEFT); + move(Buttons.DPAD_RIGHT, Buttons.B, Axes.LSTICK_H, Axes.RSTICK_H, 0.5, 1, bitsy.bitsy.BTN_RIGHT); + move(Buttons.DPAD_UP, Buttons.Y, Axes.LSTICK_V, Axes.RSTICK_V, -0.5, -1, bitsy.bitsy.BTN_UP); + move(Buttons.DPAD_DOWN, Buttons.A, Axes.LSTICK_V, Axes.RSTICK_V, 0.5, 1, bitsy.bitsy.BTN_DOWN); + if (gamepads.isJustDown(Buttons.START) || gamepads.isJustDown(Buttons.BACK)) { + // eslint-disable-next-line no-underscore-dangle + bitsy.bitsy._poke(bitsy.bitsy._buttonBlock, bitsy.bitsy.BTN_MENU, 1); + } + if (gamepads.isJustUp(Buttons.START) || gamepads.isJustUp(Buttons.BACK)) { + // eslint-disable-next-line no-underscore-dangle + bitsy.bitsy._poke(bitsy.bitsy._buttonBlock, bitsy.bitsy.BTN_MENU, 0); + } }); -after('update', function () { +after('bitsy._update', function () { gamepads.update(); }); diff --git a/dist/gravity.js b/dist/gravity.js index 1198d44b..26aa913d 100644 --- a/dist/gravity.js +++ b/dist/gravity.js @@ -4,8 +4,8 @@ @summary Pseudo-platforming/gravity/physics @license MIT @author Cole Sea -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -122,46 +122,11 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ -/* -Helper used to replace code in a script tag based on a search regex -To inject code without erasing original string, using capturing groups; e.g. - inject(/(some string)/,'injected before $1 injected after') -*/ -function inject$2(searchRegex, replaceString) { - // find the relevant script tag - var scriptTags = document.getElementsByTagName('script'); - var scriptTag; - var code; - for (var i = 0; i < scriptTags.length; ++i) { - scriptTag = scriptTags[i]; - var matchesSearch = scriptTag.textContent.search(searchRegex) !== -1; - var isCurrentScript = scriptTag === document.currentScript; - if (matchesSearch && !isCurrentScript) { - code = scriptTag.textContent; - break; - } - } - - // error-handling - if (!code) { - throw new Error('Couldn\'t find "' + searchRegex + '" in script tags'); - } - - // modify the content - code = code.replace(searchRegex, replaceString); - - // replace the old script tag with a new one using our modified code - var newScriptTag = document.createElement('script'); - newScriptTag.textContent = code; - scriptTag.insertAdjacentElement('afterend', newScriptTag); - scriptTag.remove(); -} - /* Helper for getting image by name or id @@ -184,8 +149,8 @@ function getImage(name, map) { @file edit image at runtime @summary API for updating image data at runtime. @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Adds API for updating sprite, tile, and item data at runtime. @@ -204,16 +169,6 @@ e.g. the default player is: ] */ -// force cache to clear if edit image fns are used -inject$2( - /\/\/ TODO : reset render cache for this image/, - ` -Object.keys(drawingCache.render) - .filter(function (i) { return i.split('_').slice(0, -1).join('_') === drawingId; }) - .forEach(function(i) { drawingCache.render[i] = undefined; }) -` -); - /* Args: id: string id or name @@ -386,8 +341,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -433,11 +388,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -665,14 +615,16 @@ var offsets = { 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) { if (!active) return; @@ -685,7 +637,6 @@ after('update', function () { before('movePlayer', function () { if (!active) return; - var player = bitsy.player(); wasStandingOnSomething = isSolid(gravityDir, player.x, player.y); @@ -714,7 +665,6 @@ before('movePlayer', function () { window.advanceGravity = function () { if (!active) return; - var player = bitsy.player(); // player input something, but could not move. // force them up if they are doing that @@ -732,7 +682,6 @@ window.advanceGravity = function () { }; window.movePlayerWithGravity = function (dir, axis, amt) { - var player = bitsy.player(); if (!active) { // if the hack is not active, just move the player in the direction they pressed player[axis] += amt; @@ -847,11 +796,11 @@ function isTileClimbable(x, y) { return tile && hackOptions.isClimbable(tile); } -function isOnStandableTile(player) { +function isOnStandableTile(p) { if (fallCounter > 1) { return false; } - var coords = [player.x, player.y]; + var coords = [p.x, p.y]; var offset = offsets[gravityDir]; // like [0, -1] for y -= 1 coords[0] += offset[0]; coords[1] += offset[1]; @@ -866,8 +815,8 @@ function canMoveHorizontallyWhileFalling() { return !fallCounter || (lastMoveMapped === 'down' && withinMaxRatio); } -function reallyMovePlayer(player, dir) { - if (isSolid(dir, player.x, player.y)) { +function reallyMovePlayer(p, dir) { + if (isSolid(dir, p.x, p.y)) { // can't move into solid thing...so...chill? // should maybe trigger sprites here? return; @@ -876,19 +825,19 @@ function reallyMovePlayer(player, dir) { // why doesn't isSolid catch the out of bounds? stuff? isWall should as well? weird... switch (dir) { case 'up': - if (player.y > 0) player.y -= 1; + if (p.y > 0) p.y -= 1; break; case 'down': - if (player.y < bitsy.mapsize - 1) player.y += 1; + if (p.y < bitsy.mapsize - 1) p.y += 1; break; case 'left': - if (player.x > 0) player.x -= 1; + if (p.x > 0) p.x -= 1; break; case 'right': - if (player.x < bitsy.mapsize - 1) player.x += 1; + if (p.x < bitsy.mapsize - 1) p.x += 1; break; default: - console.warn('gravity: invalid move', player.x, player.y, dir); + console.warn('gravity: invalid move', p.x, p.y, dir); } } diff --git a/dist/itsy-bitsy.js b/dist/itsy-bitsy.js index a80ba3f1..e7328823 100644 --- a/dist/itsy-bitsy.js +++ b/dist/itsy-bitsy.js @@ -4,8 +4,8 @@ @summary for when bitsy's not small enough @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -101,12 +101,12 @@ function kitsyInject(searcher, replacer) { // Ex: before('load_game', function run() { alert('Loading!'); }); // before('show_text', function run(text) { return text.toUpperCase(); }); // before('show_text', function run(text, done) { done(text.toUpperCase()); }); -function before(targetFuncName, beforeFn) { +function before$1(targetFuncName, beforeFn) { kitsy.queuedBeforeScripts[targetFuncName] = kitsy.queuedBeforeScripts[targetFuncName] || []; kitsy.queuedBeforeScripts[targetFuncName].push(beforeFn); } // Ex: after('load_game', function run() { alert('Loaded!'); }); -function after(targetFuncName, afterFn) { +function after$1(targetFuncName, afterFn) { kitsy.queuedAfterScripts[targetFuncName] = kitsy.queuedAfterScripts[targetFuncName] || []; kitsy.queuedAfterScripts[targetFuncName].push(afterFn); } @@ -171,8 +171,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -180,8 +180,8 @@ var kitsy = (window.kitsy = window.kitsy || { queuedBeforeScripts: {}, queuedAfterScripts: {}, inject: kitsyInject, - before, - after, + before: before$1, + after: after$1, /** * Applies all queued `inject` calls. * @@ -218,11 +218,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -231,31 +226,35 @@ if (!hooked) { /** @see kitsy.inject */ var inject = kitsy.inject; /** @see kitsy.before */ -kitsy.before; +var before = kitsy.before; /** @see kitsy.after */ -kitsy.after; - +var after = kitsy.after; -inject(/4(; \/\/this is stupid but necessary)/, '1$1'); // rewrite canvas scale -inject(/(mapsize =) 16/, '$1 8'); // rewrite mapsize -// rewrite text scale -inject(/(var textScale =) 2/, '$1 1'); -inject(/2(; \/\/using a different scaling factor for text feels like cheating\.\.\. but it looks better)/, '1$1'); // rewrite text scale +before('startExportedGame', function () { + bitsy.scale = 1; + bitsy.textScale = 1; + bitsy.mapsize = 8; + bitsy.width = bitsy.mapsize * bitsy.tilesize; + bitsy.height = bitsy.mapsize * bitsy.tilesize; + bitsy.bitsy.MAP_SIZE = bitsy.mapsize; + bitsy.bitsy.VIDEO_SIZE = bitsy.width; + // eslint-disable-next-line no-underscore-dangle + bitsy.bitsy._graphics.setScale(1); +}); +after('bitsy.textMode', function () { + return bitsy.bitsy.TXT_LOREZ; +}); // rewrite textbox info -inject( - /(var textboxInfo = {)[^]*?(};)/, - '$1' + ['img : null,', 'width : 62,', 'height : 64,', 'top : 1,', 'left : 1,', 'bottom : 1,', 'font_scale : 1,', 'padding_vert : 2,', 'arrow_height : 6'].join('\n') + '$2' -); -inject(/(top = \()4/, '$1 1'); -inject(/(left = \()4/, '$1 1'); +inject(/(var textboxInfo = {)[^]*?(};)/, '$1 width : 62, height : 64, top : 1, left : 1, bottom : 1, padding_vert : 2, padding_horz : 0, arrow_height : 6 $2'); +inject(/(top = \()4/g, '$1 1'); +inject(/(left = \()4/g, '$1 1'); inject(/(relativeFontHeight\(\) \*) 2/, '$1 ' + hackOptions.rows); // rewrite textbox height -inject(/(pixelsPerRow =) 192/, '$1 62'); // rewrite hard-coded textbox wrap width inject(/(else if \(curRowIndex )== 0/g, '$1< ' + (hackOptions.rows - 1)); // rewrite hard-coded row limit // inject pixelated rendering style diff --git a/dist/javascript-dialog.js b/dist/javascript-dialog.js index 2cc2a253..26857df5 100644 --- a/dist/javascript-dialog.js +++ b/dist/javascript-dialog.js @@ -4,8 +4,8 @@ @summary execute arbitrary javascript from dialog @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -196,8 +196,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -243,11 +243,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/logic-operators-extended.js b/dist/logic-operators-extended.js index a833dc6b..f89dbf22 100644 --- a/dist/logic-operators-extended.js +++ b/dist/logic-operators-extended.js @@ -3,8 +3,8 @@ @file logic-operators-extended @summary adds conditional logic operators @author @mildmojo -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -168,8 +168,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -215,11 +215,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/long-dialog.js b/dist/long-dialog.js index 3b62436d..48c52f09 100644 --- a/dist/long-dialog.js +++ b/dist/long-dialog.js @@ -4,8 +4,8 @@ @summary put more words onscreen @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -184,8 +184,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -231,11 +231,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -359,8 +354,8 @@ inject(/(this\.AddLinebreak = )/, 'this.AddParagraphBreak = function() { buffer. @summary Adds paragraph breaks to the dialogue parser @license WTFPL (do WTF you want) @author Sean S. LeBlanc, David Mowatt -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -403,7 +398,7 @@ addDialogTag('p', function (environment, parameters, onReturn) { kitsy.longDialogOptions = hackOptions; -// override textbox height +// override textbox height to be dynamic based on row count inject( /textboxInfo\.height = .+;/, `Object.defineProperty(textboxInfo, 'height', { @@ -412,14 +407,29 @@ inject( ); // export textbox info inject(/(var font = null;)/, 'this.textboxInfo = textboxInfo;$1'); -before('renderDrawingBuffer', function (bufferId, buffer) { - if (bufferId !== bitsy.textboxBufferId) return; - buffer.height = bitsy.dialogRenderer.textboxInfo.height / bitsy.dialogRenderer.textboxInfo.font_scale; -}); // rewrite hard-coded row limit inject(/(else if \(curRowIndex )== 0/g, '$1 < window.kitsy.longDialogOptions.maxRows - 1'); inject(/(if \(lastPage\.length) <= 1/, '$1 < window.kitsy.longDialogOptions.maxRows'); +// update textbox size +var ph; +function updateTextbox() { + var h = bitsy.dialogRenderer.textboxInfo.height; + if (h === ph) return; + ph = h; + var textScale = bitsy.bitsy.textMode() === bitsy.bitsy.TXT_LOREZ ? 1 : 2; + bitsy.bitsy.textbox(undefined, undefined, undefined, undefined, h * textScale); +} +before('dialogRenderer.Draw', updateTextbox); + +// reserve textbox memory on startup to avoid flickering +// when it expands dynamically +after('dialogRenderer.SetFont', function () { + // eslint-disable-next-line no-underscore-dangle + var t = bitsy.bitsy._dump()[bitsy.bitsy.TEXTBOX]; + t.length = Math.max(t.length, 256000); +}); + addDualDialogTag('textboxsize', function (environment, parameters) { if (!parameters[0]) { throw new Error('{textboxsize} was missing parameters! Usage: {textboxsize "minrows, maxrows"}'); @@ -430,6 +440,8 @@ addDualDialogTag('textboxsize', function (environment, parameters) { var max = parseInt(params[1], 10); hackOptions.minRows = min; hackOptions.maxRows = max; + + updateTextbox(); }); exports.hackOptions = hackOptions; diff --git a/dist/multi-sprite-avatar.js b/dist/multi-sprite-avatar.js index 15e1ec6d..bdb9a983 100644 --- a/dist/multi-sprite-avatar.js +++ b/dist/multi-sprite-avatar.js @@ -4,8 +4,8 @@ @summary make the player big @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -25,7 +25,7 @@ Usage: Notes: - will probably break any other hacks involving moving other sprites around (they'll probably use the player's modified collision) -- the original avatar sprite isn't changed, but will be covered by a piece at x:0,y:0 +- the original avatar sprite isn't changed, and will cover a piece placed at x:0,y:0 - make sure not to include the original avatar sprite in the pieces list (this will cause the syncing to remove the player from the game) HOW TO USE: @@ -201,8 +201,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -248,11 +248,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -367,8 +362,8 @@ function addDualDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -505,6 +500,12 @@ function filterPieces(id) { return id; } +// always redraw the full room when sprites are moving +before('drawRoom', function (room, args) { + args.redrawAll = true; + return [room, args]; +}); + after('startExportedGame', function () { for (var i = 0; i < repeats.length; ++i) { var r = repeats[i]; diff --git a/dist/online.js b/dist/online.js index 2db3a109..0f56294d 100644 --- a/dist/online.js +++ b/dist/online.js @@ -4,8 +4,8 @@ @summary multiplayer bitsy @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Provides the groundwork for running a small online multiplayer bitsy game. @@ -56,7 +56,7 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); * @param searcher Regex to search and replace * @param replacer Replacer string/fn */ -function inject$2(searcher, replacer) { +function inject$1(searcher, replacer) { // find the relevant script tag var scriptTags = document.getElementsByTagName('script'); var scriptTag; @@ -123,7 +123,7 @@ function after$1(targetFuncName, afterFn) { } function applyInjects() { kitsy.queuedInjectScripts.forEach(function (injectScript) { - inject$2(injectScript.searcher, injectScript.replacer); + inject$1(injectScript.searcher, injectScript.replacer); }); } function applyHooks(root) { @@ -182,8 +182,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -229,18 +229,13 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; } /** @see kitsy.inject */ -var inject$1 = kitsy.inject; +var inject = kitsy.inject; /** @see kitsy.before */ var before = kitsy.before; /** @see kitsy.after */ @@ -273,7 +268,7 @@ function addDialogFunction(tag, fn) { } function injectDialogTag(tag, code) { - inject$1(/(var functionMap = \{\};[^]*?)(this.HasFunction)/m, '$1\nfunctionMap["' + tag + '"] = ' + code + ';\n$2'); + inject(/(var functionMap = \{\};[^]*?)(this.HasFunction)/m, '$1\nfunctionMap["' + tag + '"] = ' + code + ';\n$2'); } /** @@ -348,46 +343,11 @@ function addDualDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ -/* -Helper used to replace code in a script tag based on a search regex -To inject code without erasing original string, using capturing groups; e.g. - inject(/(some string)/,'injected before $1 injected after') -*/ -function inject(searchRegex, replaceString) { - // find the relevant script tag - var scriptTags = document.getElementsByTagName('script'); - var scriptTag; - var code; - for (var i = 0; i < scriptTags.length; ++i) { - scriptTag = scriptTags[i]; - var matchesSearch = scriptTag.textContent.search(searchRegex) !== -1; - var isCurrentScript = scriptTag === document.currentScript; - if (matchesSearch && !isCurrentScript) { - code = scriptTag.textContent; - break; - } - } - - // error-handling - if (!code) { - throw new Error('Couldn\'t find "' + searchRegex + '" in script tags'); - } - - // modify the content - code = code.replace(searchRegex, replaceString); - - // replace the old script tag with a new one using our modified code - var newScriptTag = document.createElement('script'); - newScriptTag.textContent = code; - scriptTag.insertAdjacentElement('afterend', newScriptTag); - scriptTag.remove(); -} - /* Helper for getting image by name or id @@ -412,8 +372,8 @@ function getImage(name, map) { @summary edit dialog from dialog (yes really) @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -479,8 +439,8 @@ addDeferredDialogTag('dialog', editDialog); @file edit image at runtime @summary API for updating image data at runtime. @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Adds API for updating sprite, tile, and item data at runtime. @@ -499,16 +459,6 @@ e.g. the default player is: ] */ -// force cache to clear if edit image fns are used -inject( - /\/\/ TODO : reset render cache for this image/, - ` -Object.keys(drawingCache.render) - .filter(function (i) { return i.split('_').slice(0, -1).join('_') === drawingId; }) - .forEach(function(i) { drawingCache.render[i] = undefined; }) -` -); - /* Args: id: string id or name @@ -548,8 +498,8 @@ function setSpriteData(id, frame, newData) { @summary edit sprites, items, and tiles from dialog @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -651,6 +601,7 @@ function editImage(environment, parameters) { for (i = 0; i < srcObj.animation.frameCount; ++i) { setImageData(tgtId, i, mapObj, getImageData(srcId, i, mapObj)); } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function editPalette(environment, parameters) { @@ -681,6 +632,7 @@ function editPalette(environment, parameters) { // set palette tgtObj.col = palObj; + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } // hook up the dialog tags @@ -693,8 +645,8 @@ addDualDialogTag('imagePal', editPalette); @summary execute arbitrary javascript from dialog @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -783,6 +735,7 @@ function onData(event) { spr.x = data.x; spr.y = data.y; spr.room = data.room; + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } else { // got a move from an unknown player, // so ask them who they are @@ -805,6 +758,7 @@ function onData(event) { isAnimated: data.data.length > 1, }, col: data.col, + bgc: data.bgc, dlg: longname, drw: longname, id: event.from, @@ -821,6 +775,7 @@ function onData(event) { for (var frame = 0; frame < data.data.length; ++frame) { setSpriteData(event.from, frame, data.data[frame]); } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); break; } } @@ -890,6 +845,7 @@ function getSpriteUpdate() { room: p.room, dlg: bitsy.dialog[p.dlg], col: p.col, + bgc: p.bgc, }; } diff --git a/dist/opaque-tiles.js b/dist/opaque-tiles.js index efeb23c6..d031f671 100644 --- a/dist/opaque-tiles.js +++ b/dist/opaque-tiles.js @@ -4,8 +4,8 @@ @summary tiles which hide the player @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -99,7 +99,7 @@ function kitsyInject(searcher, replacer) { // Ex: before('load_game', function run() { alert('Loading!'); }); // before('show_text', function run(text) { return text.toUpperCase(); }); // before('show_text', function run(text, done) { done(text.toUpperCase()); }); -function before$1(targetFuncName, beforeFn) { +function before(targetFuncName, beforeFn) { kitsy.queuedBeforeScripts[targetFuncName] = kitsy.queuedBeforeScripts[targetFuncName] || []; kitsy.queuedBeforeScripts[targetFuncName].push(beforeFn); } @@ -169,8 +169,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -178,7 +178,7 @@ var kitsy = (window.kitsy = window.kitsy || { queuedBeforeScripts: {}, queuedAfterScripts: {}, inject: kitsyInject, - before: before$1, + before, after: after$1, /** * Applies all queued `inject` calls. @@ -216,11 +216,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -229,7 +224,7 @@ if (!hooked) { /** @see kitsy.inject */ var inject = kitsy.inject; /** @see kitsy.before */ -var before = kitsy.before; +kitsy.before; /** @see kitsy.after */ var after = kitsy.after; @@ -238,31 +233,39 @@ var after = kitsy.after; // track whether opaque -var opaque = false; +bitsy.opaque = false; after('movePlayer', function () { // check for changes var player = bitsy.player(); var tile = bitsy.tile[bitsy.getTile(player.x, player.y)]; if (!tile) { - opaque = false; + bitsy.opaque = false; return; } - opaque = hackOptions.tileIsOpaque(tile); + bitsy.opaque = hackOptions.tileIsOpaque(tile); }); -// prevent player from drawing on top of opaque tiles -var room; -before('drawRoom', function () { - var player = bitsy.player(); - room = player.room; - player.room = opaque ? null : room; +// create a new map layer that renders underneath tiles +after('startExportedGame', function () { + // eslint-disable-next-line no-underscore-dangle + bitsy.bitsy.MAP0 = bitsy.bitsy._addTileMapLayer(); + // eslint-disable-next-line no-underscore-dangle + bitsy.bitsy._getTileMapLayers().unshift(bitsy.bitsy._getTileMapLayers().pop()); +}); +after('clearRoom', function () { + bitsy.bitsy.fill(bitsy.bitsy.MAP0, 0); }); -after('drawRoom', function () { - bitsy.player().room = room; +after('startNarrating', function () { + bitsy.bitsy.fill(bitsy.bitsy.MAP0, 0); }); -// draw player underneath opaque tile -inject(/^(\t\/\/draw tiles)/m, 'drawTile(getSpriteFrame(player(), frameIndex), player().x, player().y);\n$1'); +// always redraw all, never redraw avatar or animated only +inject(/(var redrawAll = ).*;/, '$1true;'); +inject(/(var redrawAnimated = ).*;/, '$1false;'); +inject(/(var redrawAvatar = ).*;/, '$1false;'); +inject(/(\/\/ draw tiles)/m, 'bitsy.fill(bitsy.MAP0, 0); window.opaque && setTile(bitsy.MAP0, player().x, player().y, getSpriteFrame(player(), frameIndex));\n$1'); +// don't draw player over tiles/sprites when opaque +inject(/if \(\(redrawAll \|\| redrawAnimated/, 'if (!window.opaque && (redrawAll || redrawAnimated'); exports.hackOptions = hackOptions; diff --git a/dist/paragraph-break.js b/dist/paragraph-break.js index 32aa8c8c..790e8f25 100644 --- a/dist/paragraph-break.js +++ b/dist/paragraph-break.js @@ -4,8 +4,8 @@ @summary Adds paragraph breaks to the dialogue parser @license WTFPL (do WTF you want) @author Sean S. LeBlanc, David Mowatt -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -176,8 +176,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -223,11 +223,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/permanent-items.js b/dist/permanent-items.js index b32cd8dc..bf000287 100644 --- a/dist/permanent-items.js +++ b/dist/permanent-items.js @@ -4,8 +4,8 @@ @summary prevent some items from being picked up @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -40,7 +40,7 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); * @param searcher Regex to search and replace * @param replacer Replacer string/fn */ -function inject(searcher, replacer) { +function inject$1(searcher, replacer) { // find the relevant script tag var scriptTags = document.getElementsByTagName('script'); var scriptTag; @@ -107,7 +107,7 @@ function after(targetFuncName, afterFn) { } function applyInjects() { kitsy.queuedInjectScripts.forEach(function (injectScript) { - inject(injectScript.searcher, injectScript.replacer); + inject$1(injectScript.searcher, injectScript.replacer); }); } function applyHooks(root) { @@ -166,8 +166,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -213,18 +213,13 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; } /** @see kitsy.inject */ -kitsy.inject; +var inject = kitsy.inject; /** @see kitsy.before */ var before = kitsy.before; /** @see kitsy.after */ @@ -237,7 +232,7 @@ kitsy.after; var room; var oldItems; before('movePlayer', function () { - room = bitsy.room[bitsy.curRoom]; + room = bitsy.room[bitsy.state.room]; oldItems = room.items.slice(); }); before('startItemDialog', function (itemId, dialogCallback) { @@ -245,7 +240,7 @@ before('startItemDialog', function (itemId, dialogCallback) { if (!hackOptions.itemIsPermanent(bitsy.item[itemId])) { return undefined; } - room = bitsy.room[bitsy.curRoom]; + room = bitsy.room[bitsy.state.room]; oldItems = room.items.slice(); return [ itemId, @@ -281,6 +276,9 @@ before('startItemDialog', function (itemId, dialogCallback) { ]; }); +// always redraw all or items won't be visible +inject(/(var redrawAll = ).*;/, '$1true;'); + exports.hackOptions = hackOptions; Object.defineProperty(exports, '__esModule', { value: true }); diff --git a/dist/push-sprites.js b/dist/push-sprites.js index f4863dcd..1980c4e2 100644 --- a/dist/push-sprites.js +++ b/dist/push-sprites.js @@ -4,8 +4,8 @@ @summary sokoban-style sprite pushing @license MIT @author jan0sc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -198,46 +198,11 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ -/* -Helper used to replace code in a script tag based on a search regex -To inject code without erasing original string, using capturing groups; e.g. - inject(/(some string)/,'injected before $1 injected after') -*/ -function inject$1(searchRegex, replaceString) { - // find the relevant script tag - var scriptTags = document.getElementsByTagName('script'); - var scriptTag; - var code; - for (var i = 0; i < scriptTags.length; ++i) { - scriptTag = scriptTags[i]; - var matchesSearch = scriptTag.textContent.search(searchRegex) !== -1; - var isCurrentScript = scriptTag === document.currentScript; - if (matchesSearch && !isCurrentScript) { - code = scriptTag.textContent; - break; - } - } - - // error-handling - if (!code) { - throw new Error('Couldn\'t find "' + searchRegex + '" in script tags'); - } - - // modify the content - code = code.replace(searchRegex, replaceString); - - // replace the old script tag with a new one using our modified code - var newScriptTag = document.createElement('script'); - newScriptTag.textContent = code; - scriptTag.insertAdjacentElement('afterend', newScriptTag); - scriptTag.remove(); -} - /* Helper for getting image by name or id @@ -260,8 +225,8 @@ function getImage(name, map) { @file edit image at runtime @summary API for updating image data at runtime. @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Adds API for updating sprite, tile, and item data at runtime. @@ -280,16 +245,6 @@ e.g. the default player is: ] */ -// force cache to clear if edit image fns are used -inject$1( - /\/\/ TODO : reset render cache for this image/, - ` -Object.keys(drawingCache.render) - .filter(function (i) { return i.split('_').slice(0, -1).join('_') === drawingId; }) - .forEach(function(i) { drawingCache.render[i] = undefined; }) -` -); - /* Args: id: string id or name @@ -462,8 +417,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -509,11 +464,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -648,6 +598,7 @@ function pushSprite(spr, direction) { s.y = newy; }); checkExit(spr, direction); + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); return true; } return false; @@ -758,9 +709,9 @@ function checkTargets() { } } } - targetsLookup[bitsy.curRoom] = targetsLookup[bitsy.curRoom] || []; - targetsLookup[bitsy.curRoom][bitsy.player().x] = targetsLookup[bitsy.curRoom][bitsy.player().x] || []; - targetsLookup[bitsy.curRoom][bitsy.player().x][bitsy.player().y] = bitsy.playerId; + targetsLookup[bitsy.state.room] = targetsLookup[bitsy.state.room] || []; + targetsLookup[bitsy.state.room][bitsy.player().x] = targetsLookup[bitsy.state.room][bitsy.player().x] || []; + targetsLookup[bitsy.state.room][bitsy.player().x][bitsy.player().y] = bitsy.playerId; for (k in hackOptions.conditions) { if (Object.prototype.hasOwnProperty.call(hackOptions.conditions, k)) { diff --git a/dist/replace-drawing.js b/dist/replace-drawing.js index 6b30538d..cfdf92f7 100644 --- a/dist/replace-drawing.js +++ b/dist/replace-drawing.js @@ -4,8 +4,8 @@ @summary add name-tags to replace drawings when the game is loading @license MIT @author Elkie Nova -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -177,8 +177,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -224,11 +224,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -243,7 +238,7 @@ var after = kitsy.after; -after('parseWorld', function () { +after('renderer.SetDrawings', function () { [].concat(Object.values(bitsy.item), Object.values(bitsy.tile), Object.values(bitsy.sprite)).forEach(function (drawing) { // replace drawings marked with the #draw(TYPE,id) tag var name = drawing.name || ''; diff --git a/dist/save.js b/dist/save.js index 593c232b..4596d13c 100644 --- a/dist/save.js +++ b/dist/save.js @@ -4,8 +4,8 @@ @summary save/load your game @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -195,8 +195,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -242,11 +242,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -361,8 +356,8 @@ function addDualDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ @@ -408,7 +403,7 @@ function inject(searchRegex, replaceString) { function save() { var snapshot = {}; if (hackOptions.position) { - snapshot.room = bitsy.curRoom; + snapshot.room = bitsy.state.room; snapshot.x = bitsy.player().x; snapshot.y = bitsy.player().y; } @@ -440,11 +435,11 @@ function load() { if (hackOptions.position) { if (snapshot.room) { - bitsy.curRoom = bitsy.player().room = snapshot.room; + bitsy.state.room = bitsy.player().room = snapshot.room; } if (snapshot.x && snapshot.y) { - bitsy.player().x = snapshot.x; - bitsy.player().y = snapshot.y; + bitsy.playerPrevX = bitsy.player().x = snapshot.x; + bitsy.playerPrevY = bitsy.player().y = snapshot.y; } } if (hackOptions.items) { @@ -466,6 +461,7 @@ function load() { bitsy.saveHack.sequenceIndices = snapshot.sequenceIndices; bitsy.saveHack.shuffles = snapshot.shuffles; } + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } function clear() { @@ -505,7 +501,7 @@ optionsShuffled = window.saveHack.loadShuffle(this) || optionsShuffled; window.saveHack.saveShuffle(this, optionsShuffled); options[index]` ); -inject(/(\/\/ bitsyLog\(".+" \+ index\);)/g, '$1\nvar i = window.saveHack.loadSeqIdx(this);index = i === undefined ? index : i;'); +inject(/(\/\/ bitsy\.log\(".+" \+ index\);)/g, '$1\nvar i = window.saveHack.loadSeqIdx(this);index = i === undefined ? index : i;'); // save index on changes inject(/(index = next;)/g, '$1window.saveHack.saveSeqIdx(this, index);'); inject(/(\tindex = 0;)/g, '$1window.saveHack.saveSeqIdx(this, index);'); @@ -543,14 +539,22 @@ before('startExportedGame', function () { } }); +// override title if loading +var replaceTitle; +before('renderer.SetDrawings', function () { + if (replaceTitle !== undefined) { + bitsy.setTitle(replaceTitle); + } +}); + // hook up dialog functions function dialogLoad(environment, parameters) { + replaceTitle = parameters[0] || ''; var loadOnStart = hackOptions.loadOnStart; hackOptions.loadOnStart = true; bitsy.reset_cur_game(); + bitsy.load_game(bitsy.bitsy.getGameData(), bitsy.bitsy.getFontData()); hackOptions.loadOnStart = loadOnStart; - bitsy.dialogBuffer.EndDialog(); - bitsy.startNarrating(parameters[0] || ''); } addDualDialogTag('save', save); addDualDialogTag('load', dialogLoad); diff --git a/dist/solid-items.js b/dist/solid-items.js index 8d081843..d96a7cb4 100644 --- a/dist/solid-items.js +++ b/dist/solid-items.js @@ -4,8 +4,8 @@ @summary treat some items like sprites that can be placed multiple times @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -167,8 +167,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -214,11 +214,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -244,7 +239,7 @@ before('movePlayer', function () { y = bitsy.player().y; }); before('startItemDialog', function (itemId, dialogCallback) { - room = bitsy.room[bitsy.curRoom]; + room = bitsy.room[bitsy.state.room]; oldItems = room.items.slice(); // something changed if (!hackOptions.itemIsSolid(bitsy.item[itemId])) { diff --git a/dist/stopwatch.js b/dist/stopwatch.js index 0d307f09..09349a57 100644 --- a/dist/stopwatch.js +++ b/dist/stopwatch.js @@ -4,8 +4,8 @@ @summary time player actions @license MIT @author Lenny Magner -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -202,8 +202,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -249,11 +249,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -368,8 +363,8 @@ function addDualDialogTag(tag, fn) { @file utils @summary miscellaneous bitsy utilities @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ diff --git a/dist/text-to-speech.js b/dist/text-to-speech.js index e2fbd35e..d6b3b7cf 100644 --- a/dist/text-to-speech.js +++ b/dist/text-to-speech.js @@ -4,8 +4,8 @@ @summary text-to-speech for bitsy dialog @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -192,8 +192,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -239,11 +239,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -445,7 +440,7 @@ after('dialogBuffer.EndDialog', function () { }); // save the character on dialog font characters so we can read it back post-render -inject(/(function DialogFontChar\(font, char, effectList\) {)/, '$1\nthis.char = char;'); +inject(/(function DialogFontChar\(font, char, effectList, effectParameterList\) {)/, '$1\nthis.char = char;'); // queue speaking based on whether we have finished rendering text var spoke = false; diff --git a/dist/tracery-processing.js b/dist/tracery-processing.js index d53dc46f..54949772 100644 --- a/dist/tracery-processing.js +++ b/dist/tracery-processing.js @@ -4,8 +4,8 @@ @summary process all dialog text with a tracery grammar @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -1036,8 +1036,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -1083,11 +1083,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; diff --git a/dist/transitions.js b/dist/transitions.js index 448324ca..fe2bb801 100644 --- a/dist/transitions.js +++ b/dist/transitions.js @@ -4,8 +4,8 @@ @summary customizable WebGL transitions @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -68,7 +68,7 @@ var hackOptions = { // return true to indicate a transition; false otherwise // example implementation is transition on room change checkTransition: function () { - var r = bitsy.curRoom; + var r = bitsy.state.room; if (this.room !== r) { // room changed between frames this.room = r; @@ -223,8 +223,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -270,11 +270,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -293,8 +288,8 @@ var after = kitsy.after; @summary WebGLazy bitsy integration (this one's mostly just for me) @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -359,7 +354,7 @@ after('startExportedGame', function () { } }); -after('update', function () { +after('bitsy._update', function () { if (hackOptions$1.update) { hackOptions$1.update(glazy); } diff --git a/dist/transparent-background.js b/dist/transparent-background.js index 7561ea68..177cce4b 100644 --- a/dist/transparent-background.js +++ b/dist/transparent-background.js @@ -4,8 +4,8 @@ @summary makes the game have a transparent background @license MIT @author Cephalopodunk & Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -45,7 +45,7 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); * @param searcher Regex to search and replace * @param replacer Replacer string/fn */ -function inject$1(searcher, replacer) { +function inject(searcher, replacer) { // find the relevant script tag var scriptTags = document.getElementsByTagName('script'); var scriptTag; @@ -112,7 +112,7 @@ function after$1(targetFuncName, afterFn) { } function applyInjects() { kitsy.queuedInjectScripts.forEach(function (injectScript) { - inject$1(injectScript.searcher, injectScript.replacer); + inject(injectScript.searcher, injectScript.replacer); }); } function applyHooks(root) { @@ -171,8 +171,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -218,18 +218,13 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; } /** @see kitsy.inject */ -var inject = kitsy.inject; +kitsy.inject; /** @see kitsy.before */ var before = kitsy.before; /** @see kitsy.after */ @@ -238,17 +233,24 @@ var after = kitsy.after; /** ๐Ÿ @file transparent sprites -@summary makes all sprites have transparent backgrounds +@summary makes all sprites have transparent backgrounds (deprecated) @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Makes all sprites have transparent backgrounds. i.e. tiles can be seen underneath the player, sprites, and items. +NOTE: This hack is no longer necessary as Bitsy 8.0 +supports transparent sprites directly in gamedata. +To flag a drawing as transparent in Bitsy, +add the following line underneath its data: + +BGC * + HOW TO USE: 1. Copy-paste this script into a script tag after the bitsy source 2. Edit hackOptions below as needed @@ -263,57 +265,15 @@ var hackOptions$1 = { }, }; -window.makeTransparent = false; -// flag what should be transparent -before('renderer.GetDrawingFrame', function (drawing, frameIndex) { - window.makeTransparent = hackOptions$1.isTransparent(drawing); -}); -// send -1 instead of background colour index if transparent -inject(/bitsyDrawPixel\(backgroundColor, x, y\)/, 'bitsyDrawPixel(window.makeTransparent ? -1 : backgroundColor, x, y)'); -// make sure transitions render using regular room logic -inject( - /(function createRoomPixelBuffer\(room\) {)/, - `$1 -var buffer = drawingBuffers[screenBufferId]; -var s = buffer.scale; -buffer.scale = 1; -drawRoom(room); -renderDrawingBuffer(screenBufferId, buffer); -const data = buffer.canvas.getContext('2d').getImageData(0, 0, buffer.width, buffer.height).data; -var pixelBuffer = []; -for (var y = 0; y < buffer.height; ++y) { -for (var x = 0; x < buffer.width; ++x) { - var idx = (y*buffer.width + x)*4; - var r = data[idx + 0]; - var g = data[idx + 1]; - var b = data[idx + 2]; - var p = getPal(getRoomPal(curRoom)).findIndex(i => r === i[0] && g === i[1] && b === i[2]); - pixelBuffer.push(tileColorStartIndex + p); -} -} -buffer.scale = s; -invalidateDrawingBuffer(buffer); -return pixelBuffer; -` -); -// make sure tiles are available when drawing rooms -inject(/(var tileBuffer = drawingBuffers\[tileId\];)/, 'hackForEditor_GetImageFromTileId(tileId); $1'); - -// overwrite transparent pixel -after('renderPixelInstruction', function (bufferId, buffer, paletteIndex, x, y) { - if (paletteIndex !== -1) return; - - if (buffer.imageData) { - for (var sy = 0; sy < buffer.scale; sy++) { - for (var sx = 0; sx < buffer.scale; sx++) { - var pixelIndex = (y * buffer.scale + sy) * buffer.width * buffer.scale * 4 + (x * buffer.scale + sx) * 4; - buffer.imageData.data[pixelIndex + 3] = 0; +before('renderer.SetDrawings', function () { + Object.values(bitsy.tile) + .concat(Object.values(bitsy.sprite)) + .concat(Object.values(bitsy.item)) + .forEach(drawing => { + if (hackOptions$1.isTransparent(drawing)) { + drawing.bgc = -bitsy.tileColorStartIndex; } - } - } else { - var bufferContext = buffer.canvas.getContext('2d'); - bufferContext.clearRect(x * buffer.scale, y * buffer.scale, buffer.scale, buffer.scale); - } + }); }); @@ -325,14 +285,9 @@ hackOptions$1.isTransparent = function (drawing) { return hackOptions.isTransparent(drawing); }; -before('renderGame', function () { - bitsy.ctx.clearRect(0, 0, bitsy.canvas.width, bitsy.canvas.height); -}); - -after('renderClearInstruction', function (bufferId, buffer, paletteIndex) { - if (bufferId !== bitsy.screenBufferId || paletteIndex !== bitsy.tileColorStartIndex) return; - var bufferContext = buffer.canvas.getContext('2d'); - bufferContext.clearRect(0, 0, buffer.canvas.width, buffer.canvas.height); +after('bitsy._graphics.clearCanvas', function () { + // eslint-disable-next-line no-underscore-dangle + bitsy.bitsy._graphics.getContext().clearRect(0, 0, bitsy.bitsy._graphics.getCanvas().width, bitsy.bitsy._graphics.getCanvas().height); }); exports.hackOptions = hackOptions; diff --git a/dist/transparent-dialog.js b/dist/transparent-dialog.js index b579b677..ffbe7443 100644 --- a/dist/transparent-dialog.js +++ b/dist/transparent-dialog.js @@ -4,8 +4,8 @@ @summary makes the dialog box have a transparent background @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -156,8 +156,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -203,11 +203,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -222,10 +217,8 @@ var after = kitsy.after; -after('renderClearInstruction', function (bufferId, buffer, paletteIndex) { - if (bufferId !== bitsy.textboxBufferId || paletteIndex !== bitsy.textBackgroundIndex) return; - var bufferContext = buffer.canvas.getContext('2d'); - bufferContext.clearRect(0, 0, buffer.canvas.width, buffer.canvas.height); +after('dialogRenderer.ClearTextbox', function () { + bitsy.bitsy.fill(bitsy.bitsy.TEXTBOX, 0); }); })(window); diff --git a/dist/transparent-sprites.js b/dist/transparent-sprites.js index fad38c8e..fbf6c048 100644 --- a/dist/transparent-sprites.js +++ b/dist/transparent-sprites.js @@ -1,17 +1,24 @@ /** ๐Ÿ @file transparent sprites -@summary makes all sprites have transparent backgrounds +@summary makes all sprites have transparent backgrounds (deprecated) @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description Makes all sprites have transparent backgrounds. i.e. tiles can be seen underneath the player, sprites, and items. +NOTE: This hack is no longer necessary as Bitsy 8.0 +supports transparent sprites directly in gamedata. +To flag a drawing as transparent in Bitsy, +add the following line underneath its data: + +BGC * + HOW TO USE: 1. Copy-paste this script into a script tag after the bitsy source 2. Edit hackOptions below as needed @@ -41,7 +48,7 @@ bitsy = bitsy || /*#__PURE__*/_interopDefaultLegacy(bitsy); * @param searcher Regex to search and replace * @param replacer Replacer string/fn */ -function inject$1(searcher, replacer) { +function inject(searcher, replacer) { // find the relevant script tag var scriptTags = document.getElementsByTagName('script'); var scriptTag; @@ -102,13 +109,13 @@ function before$1(targetFuncName, beforeFn) { kitsy.queuedBeforeScripts[targetFuncName].push(beforeFn); } // Ex: after('load_game', function run() { alert('Loaded!'); }); -function after$1(targetFuncName, afterFn) { +function after(targetFuncName, afterFn) { kitsy.queuedAfterScripts[targetFuncName] = kitsy.queuedAfterScripts[targetFuncName] || []; kitsy.queuedAfterScripts[targetFuncName].push(afterFn); } function applyInjects() { kitsy.queuedInjectScripts.forEach(function (injectScript) { - inject$1(injectScript.searcher, injectScript.replacer); + inject(injectScript.searcher, injectScript.replacer); }); } function applyHooks(root) { @@ -167,8 +174,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -177,7 +184,7 @@ var kitsy = (window.kitsy = window.kitsy || { queuedAfterScripts: {}, inject: kitsyInject, before: before$1, - after: after$1, + after, /** * Applies all queued `inject` calls. * @@ -214,78 +221,31 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; } /** @see kitsy.inject */ -var inject = kitsy.inject; +kitsy.inject; /** @see kitsy.before */ var before = kitsy.before; /** @see kitsy.after */ -var after = kitsy.after; - +kitsy.after; -window.makeTransparent = false; -// flag what should be transparent -before('renderer.GetDrawingFrame', function (drawing, frameIndex) { - window.makeTransparent = hackOptions.isTransparent(drawing); -}); -// send -1 instead of background colour index if transparent -inject(/bitsyDrawPixel\(backgroundColor, x, y\)/, 'bitsyDrawPixel(window.makeTransparent ? -1 : backgroundColor, x, y)'); -// make sure transitions render using regular room logic -inject( - /(function createRoomPixelBuffer\(room\) {)/, - `$1 -var buffer = drawingBuffers[screenBufferId]; -var s = buffer.scale; -buffer.scale = 1; -drawRoom(room); -renderDrawingBuffer(screenBufferId, buffer); -const data = buffer.canvas.getContext('2d').getImageData(0, 0, buffer.width, buffer.height).data; -var pixelBuffer = []; -for (var y = 0; y < buffer.height; ++y) { -for (var x = 0; x < buffer.width; ++x) { - var idx = (y*buffer.width + x)*4; - var r = data[idx + 0]; - var g = data[idx + 1]; - var b = data[idx + 2]; - var p = getPal(getRoomPal(curRoom)).findIndex(i => r === i[0] && g === i[1] && b === i[2]); - pixelBuffer.push(tileColorStartIndex + p); -} -} -buffer.scale = s; -invalidateDrawingBuffer(buffer); -return pixelBuffer; -` -); -// make sure tiles are available when drawing rooms -inject(/(var tileBuffer = drawingBuffers\[tileId\];)/, 'hackForEditor_GetImageFromTileId(tileId); $1'); - -// overwrite transparent pixel -after('renderPixelInstruction', function (bufferId, buffer, paletteIndex, x, y) { - if (paletteIndex !== -1) return; - if (buffer.imageData) { - for (var sy = 0; sy < buffer.scale; sy++) { - for (var sx = 0; sx < buffer.scale; sx++) { - var pixelIndex = (y * buffer.scale + sy) * buffer.width * buffer.scale * 4 + (x * buffer.scale + sx) * 4; - buffer.imageData.data[pixelIndex + 3] = 0; +before('renderer.SetDrawings', function () { + Object.values(bitsy.tile) + .concat(Object.values(bitsy.sprite)) + .concat(Object.values(bitsy.item)) + .forEach(drawing => { + if (hackOptions.isTransparent(drawing)) { + drawing.bgc = -bitsy.tileColorStartIndex; } - } - } else { - var bufferContext = buffer.canvas.getContext('2d'); - bufferContext.clearRect(x * buffer.scale, y * buffer.scale, buffer.scale, buffer.scale); - } + }); }); exports.hackOptions = hackOptions; diff --git a/dist/twine-bitsy-comms.js b/dist/twine-bitsy-comms.js index 6e37af4d..13cfc517 100644 --- a/dist/twine-bitsy-comms.js +++ b/dist/twine-bitsy-comms.js @@ -4,8 +4,8 @@ @summary interprocess communication for twine and bitsy @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -238,8 +238,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -285,11 +285,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -447,7 +442,7 @@ after('onInventoryChanged', function (id) { // say when bitsy has started // and initialize variables -after('startExportedGame', function () { +after('load_game', function () { bitsy.scriptInterpreter.GetVariableNames().forEach(function (name) { sendVariable(hackOptions.variableNameOut(name), bitsy.scriptInterpreter.GetVariable(name)); }); diff --git a/dist/unique-items.js b/dist/unique-items.js index b4155b31..e4cda613 100644 --- a/dist/unique-items.js +++ b/dist/unique-items.js @@ -4,8 +4,8 @@ @summary items which, when picked up, remove all other instances of that item from the game @license MIT @author Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 @description @@ -167,8 +167,8 @@ function applyHook(root, functionName) { @summary Monkey-patching toolkit to make it easier and cleaner to run code before and after functions or to inject new code into script tags @license WTFPL (do WTF you want) @author Original by mildmojo; modified by Sean S. LeBlanc -@version 20.2.5 -@requires Bitsy 7.12 +@version 21.0.0 +@requires Bitsy 8.0 */ var kitsy = (window.kitsy = window.kitsy || { @@ -214,11 +214,6 @@ if (!hooked) { // Hook everything kitsy.applyHooks(); - // reset callbacks using hacked functions - bitsy.bitsyOnUpdate(bitsy.update); - bitsy.bitsyOnQuit(bitsy.stopGame); - bitsy.bitsyOnLoad(bitsy.load_game); - // Start the game bitsy.startExportedGame.apply(this, arguments); }; @@ -242,6 +237,7 @@ after('onInventoryChanged', function (id) { return i.id !== id; }); }); + bitsy.drawRoom(bitsy.room[bitsy.state.room], { redrawAll: true }); } }); diff --git a/package-lock.json b/package-lock.json index 883214cd..73a8c2f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@bitsy/hecks", - "version": "20.2.5", + "version": "21.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@bitsy/hecks", - "version": "20.2.5", + "version": "21.0.0", "license": "MIT (individual hacks have their own license specified)", "dependencies": { "@seansleblanc/pink-trombone": "^1.0.1", diff --git a/package.json b/package.json index 25fed96d..a11cdff4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "hacks" ], "main": "index.mjs", - "version": "20.2.5", + "version": "21.0.0", "bitsyVersion": "8.0", "scripts": { "build": "rollup -c",