Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // XPWaterTiles.js
- //=============================================================================
- /*:
- * @target MZ
- * @plugindesc Simple plugin to enable 4-frame water animation by sacrificing
- * the waterfall autotile.
- * @url catballgames.com
- * @help Add the <XPTILES> notetag to any map's note section where you want to
- * use XP-style 4-frame water autotiles.
- */
- var CatballG = CatballG || {};
- CatballG.XPWaterTiles = CatballG.XPWaterTiles || {};
- CatballG.XPWaterTiles.version = 1.0;
- CatballG.XPWaterTiles.parseMapNoteTags = function() {
- let noteMatch = /<(?:XPTILES)>/i;
- let noteData = $dataMap.note.split(/[\r\n]+/);
- console.log(noteData);
- let noteLength = noteData.length;
- for (let i = 0; i < noteLength; i++) {
- let line = noteData[i];
- if (line.match(noteMatch)) {
- return true;
- }
- }
- return false;
- };
- Tilemap.prototype._addAutotile = function(layer, tileId, dx, dy) {
- const kind = Tilemap.getAutotileKind(tileId);
- const shape = Tilemap.getAutotileShape(tileId);
- const tx = kind % 8;
- const ty = Math.floor(kind / 8);
- let setNumber = 0;
- let bx = 0;
- let by = 0;
- let autotileTable = Tilemap.FLOOR_AUTOTILE_TABLE;
- let isTable = false;
- let hasXPTiles = CatballG.XPWaterTiles.parseMapNoteTags();
- if (Tilemap.isTileA1(tileId)) {
- let waterSurfaceIndex = [];
- if (hasXPTiles) {
- waterSurfaceIndex = [0, 1, 2, 3][this.animationFrame % 4];
- } else {
- waterSurfaceIndex = [0, 1, 2, 1][this.animationFrame % 4];
- }
- setNumber = 0;
- if (kind === 0) {
- bx = waterSurfaceIndex * 2;
- by = 0;
- } else if (kind === 1) {
- bx = waterSurfaceIndex * 2;
- by = 3;
- } else if (kind === 2) {
- bx = 6;
- by = 0;
- } else if (kind === 3) {
- bx = 6;
- by = 3;
- } else {
- bx = Math.floor(tx / 4) * 8;
- by = ty * 6 + (Math.floor(tx / 2) % 2) * 3;
- if (kind % 2 === 0) {
- bx += waterSurfaceIndex * 2;
- } else {
- bx += 6;
- autotileTable = Tilemap.WATERFALL_AUTOTILE_TABLE;
- by += this.animationFrame % 3;
- }
- }
- } else if (Tilemap.isTileA2(tileId)) {
- setNumber = 1;
- bx = tx * 2;
- by = (ty - 2) * 3;
- isTable = this._isTableTile(tileId);
- } else if (Tilemap.isTileA3(tileId)) {
- setNumber = 2;
- bx = tx * 2;
- by = (ty - 6) * 2;
- autotileTable = Tilemap.WALL_AUTOTILE_TABLE;
- } else if (Tilemap.isTileA4(tileId)) {
- setNumber = 3;
- bx = tx * 2;
- by = Math.floor((ty - 10) * 2.5 + (ty % 2 === 1 ? 0.5 : 0));
- if (ty % 2 === 1) {
- autotileTable = Tilemap.WALL_AUTOTILE_TABLE;
- }
- }
- const table = autotileTable[shape];
- const w1 = this._tileWidth / 2;
- const h1 = this._tileHeight / 2;
- for (let i = 0; i < 4; i++) {
- const qsx = table[i][0];
- const qsy = table[i][1];
- const sx1 = (bx * 2 + qsx) * w1;
- const sy1 = (by * 2 + qsy) * h1;
- const dx1 = dx + (i % 2) * w1;
- const dy1 = dy + Math.floor(i / 2) * h1;
- if (isTable && (qsy === 1 || qsy === 5)) {
- const qsx2 = qsy === 1 ? (4 - qsx) % 4 : qsx;
- const qsy2 = 3;
- const sx2 = (bx * 2 + qsx2) * w1;
- const sy2 = (by * 2 + qsy2) * h1;
- layer.addRect(setNumber, sx2, sy2, dx1, dy1, w1, h1);
- layer.addRect(setNumber, sx1, sy1, dx1, dy1 + h1 / 2, w1, h1 / 2);
- } else {
- layer.addRect(setNumber, sx1, sy1, dx1, dy1, w1, h1);
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment