|
| 1 | +/* |
| 2 | +Draw roof layers over a room that hides interiors until the player enters them. |
| 3 | +
|
| 4 | +HOW TO USE: |
| 5 | +1. Import plugin in bipsi |
| 6 | +2. In a desired room, create an event tagged "room-overlay" |
| 7 | +3. Add to that event a "location" field called "room-overlay" for each desired layer, pointing to the room to draw over this one. |
| 8 | +4. In the rooms to be overlaid, set walls in any place where the layer should be hidden if the player is standing there. |
| 9 | +*/ |
| 10 | + |
| 11 | +wrap.after(BipsiPlayback.prototype, "addLayersToScene", async function(scene, dest, frame) { |
| 12 | + if (this.ended) |
| 13 | + return; |
| 14 | + |
| 15 | + const avatar = getEventById(this.data, this.avatarId); |
| 16 | + const room = roomFromEvent(this.data, avatar); |
| 17 | + |
| 18 | + const overlay = room.events.find((event) => IS_TAGGED(event, "room-overlay")); |
| 19 | + |
| 20 | + if (!overlay) |
| 21 | + return; |
| 22 | + |
| 23 | + const locations = FIELDS(overlay, "room-overlay", "location"); |
| 24 | + const tileToFrame = makeTileToFrameMap(this.data.tiles, frame); |
| 25 | + |
| 26 | + function upscaler(func) { |
| 27 | + return () => { |
| 28 | + fillRendering2D(TEMP_ROOM); |
| 29 | + func(); |
| 30 | + dest.drawImage(TEMP_ROOM.canvas, 0, 0, 256, 256); |
| 31 | + }; |
| 32 | + } |
| 33 | + |
| 34 | + for (const location of locations) { |
| 35 | + const room = getRoomById(this.data, location.room); |
| 36 | + const palette = getPaletteById(this.data, room.palette); |
| 37 | + const tileset = this.stateManager.resources.get(this.data.tileset); |
| 38 | + |
| 39 | + const [fx, fy] = avatar.position; |
| 40 | + const solid = cellIsSolid(room, fx, fy); |
| 41 | + |
| 42 | + if (solid) |
| 43 | + continue; |
| 44 | + |
| 45 | + scene.push({ layer: 2.5, func: upscaler(() => drawTilemapLayer(TEMP_ROOM, tileset, tileToFrame, palette, room)) }); |
| 46 | + } |
| 47 | +}); |
0 commit comments