Guest User

XP Water Autotiles Plugin

a guest
Mar 13th, 2021
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // XPWaterTiles.js
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @target MZ
  7.  * @plugindesc Simple plugin to enable 4-frame water animation by sacrificing
  8.  * the waterfall autotile.
  9.  * @url catballgames.com
  10.  * @help Add the <XPTILES> notetag to any map's note section where you want to
  11.  * use XP-style 4-frame water autotiles.
  12.  */
  13.  
  14. var CatballG = CatballG || {};
  15. CatballG.XPWaterTiles = CatballG.XPWaterTiles || {};
  16. CatballG.XPWaterTiles.version = 1.0;
  17.  
  18. CatballG.XPWaterTiles.parseMapNoteTags = function() {
  19.     let noteMatch = /<(?:XPTILES)>/i;
  20.     let noteData = $dataMap.note.split(/[\r\n]+/);
  21.     console.log(noteData);
  22.     let noteLength = noteData.length;
  23.  
  24.     for (let i = 0; i < noteLength; i++) {
  25.         let line = noteData[i];
  26.         if (line.match(noteMatch)) {
  27.             return true;
  28.         }
  29.     }
  30.     return false;
  31. };
  32.  
  33. Tilemap.prototype._addAutotile = function(layer, tileId, dx, dy) {
  34.     const kind = Tilemap.getAutotileKind(tileId);
  35.     const shape = Tilemap.getAutotileShape(tileId);
  36.     const tx = kind % 8;
  37.     const ty = Math.floor(kind / 8);
  38.     let setNumber = 0;
  39.     let bx = 0;
  40.     let by = 0;
  41.     let autotileTable = Tilemap.FLOOR_AUTOTILE_TABLE;
  42.     let isTable = false;
  43.     let hasXPTiles = CatballG.XPWaterTiles.parseMapNoteTags();
  44.  
  45.     if (Tilemap.isTileA1(tileId)) {
  46.         let waterSurfaceIndex = [];
  47.         if (hasXPTiles) {
  48.             waterSurfaceIndex = [0, 1, 2, 3][this.animationFrame % 4];
  49.         } else {
  50.             waterSurfaceIndex = [0, 1, 2, 1][this.animationFrame % 4];
  51.         }
  52.         setNumber = 0;
  53.         if (kind === 0) {
  54.             bx = waterSurfaceIndex * 2;
  55.             by = 0;
  56.         } else if (kind === 1) {
  57.             bx = waterSurfaceIndex * 2;
  58.             by = 3;
  59.         } else if (kind === 2) {
  60.             bx = 6;
  61.             by = 0;
  62.         } else if (kind === 3) {
  63.             bx = 6;
  64.             by = 3;
  65.         } else {
  66.             bx = Math.floor(tx / 4) * 8;
  67.             by = ty * 6 + (Math.floor(tx / 2) % 2) * 3;
  68.             if (kind % 2 === 0) {
  69.                 bx += waterSurfaceIndex * 2;
  70.             } else {
  71.                 bx += 6;
  72.                 autotileTable = Tilemap.WATERFALL_AUTOTILE_TABLE;
  73.                 by += this.animationFrame % 3;
  74.             }
  75.         }
  76.     } else if (Tilemap.isTileA2(tileId)) {
  77.         setNumber = 1;
  78.         bx = tx * 2;
  79.         by = (ty - 2) * 3;
  80.         isTable = this._isTableTile(tileId);
  81.     } else if (Tilemap.isTileA3(tileId)) {
  82.         setNumber = 2;
  83.         bx = tx * 2;
  84.         by = (ty - 6) * 2;
  85.         autotileTable = Tilemap.WALL_AUTOTILE_TABLE;
  86.     } else if (Tilemap.isTileA4(tileId)) {
  87.         setNumber = 3;
  88.         bx = tx * 2;
  89.         by = Math.floor((ty - 10) * 2.5 + (ty % 2 === 1 ? 0.5 : 0));
  90.         if (ty % 2 === 1) {
  91.             autotileTable = Tilemap.WALL_AUTOTILE_TABLE;
  92.         }
  93.     }
  94.  
  95.     const table = autotileTable[shape];
  96.     const w1 = this._tileWidth / 2;
  97.     const h1 = this._tileHeight / 2;
  98.     for (let i = 0; i < 4; i++) {
  99.         const qsx = table[i][0];
  100.         const qsy = table[i][1];
  101.         const sx1 = (bx * 2 + qsx) * w1;
  102.         const sy1 = (by * 2 + qsy) * h1;
  103.         const dx1 = dx + (i % 2) * w1;
  104.         const dy1 = dy + Math.floor(i / 2) * h1;
  105.         if (isTable && (qsy === 1 || qsy === 5)) {
  106.             const qsx2 = qsy === 1 ? (4 - qsx) % 4 : qsx;
  107.             const qsy2 = 3;
  108.             const sx2 = (bx * 2 + qsx2) * w1;
  109.             const sy2 = (by * 2 + qsy2) * h1;
  110.             layer.addRect(setNumber, sx2, sy2, dx1, dy1, w1, h1);
  111.             layer.addRect(setNumber, sx1, sy1, dx1, dy1 + h1 / 2, w1, h1 / 2);
  112.         } else {
  113.             layer.addRect(setNumber, sx1, sy1, dx1, dy1, w1, h1);
  114.         }
  115.     }
  116. };
Advertisement
Add Comment
Please, Sign In to add comment