MZ A few questions about shadow pen

I wanted to make compatible qMovement to use the tile shadows that shadow pen draw as collisions so i have a few questions:
How is shadow pen defined? how could i call that function from another plugin?
I had a look at the core scripts (_readMapData and _addShadow methods of Tilemap, rmmz_core.js) and it looks like shadow bits for tile (x, y) can be fetched like this:

$gameMap.data()[(4 * $gameMap.height() + y) * $gameMap.width() + x]
(It's 4 because that's the shadow layer index.) This is a 4-bit number, i.e. 0000~1111 in binary, or 0~15 in decimal. Each bit corresponds to a quarter tile: it's 1 iff there's a shadow in that quadrant. The bits are ordered as follows:

0 1 2 3
I had a look at the core scripts (_readMapData and _addShadow methods of Tilemap, rmmz_core.js) and it looks like shadow bits for tile (x, y) can be fetched like this:

$gameMap.data()[(4 * $gameMap.height() + y) * $gameMap.width() + x]

(It's 4 because that's the shadow layer index.) This is a 4-bit number, i.e. 0000~1111 in binary, or 0~15 in decimal. Each bit corresponds to a quarter tile: it's 1 iff there's a shadow in that quadrant. The bits are ordered as follows:

0 1 2 3

Thanks a lot for your very explained answer, but please do not close the post yet new doubts may arise about it 😉
I'm still following a 10 hour javascript course (to start) so I'm still quite a noob at this, but I think with some patience I'll be able to implement it
I had a look at the core scripts (_readMapData and _addShadow methods of Tilemap, rmmz_core.js) and it looks like shadow bits for tile (x, y) can be fetched like this:

$gameMap.data()[(4 * $gameMap.height() + y) * $gameMap.width() + x]

(It's 4 because that's the shadow layer index.) This is a 4-bit number, i.e. 0000~1111 in binary, or 0~15 in decimal. Each bit corresponds to a quarter tile: it's 1 iff there's a shadow in that quadrant. The bits are ordered as follows:

0 1 2 3

Do you think it would be very difficult to implement quarters collision to qmovement using shadow pencil? I think it could make parallax mapping a lot easier, even more with the latest update that allows you to draw rectangles pressing shift
I have no experience with Quxios's stuff, but I had a quick look at the code for QMovement and QM+CollisionMap (link to QPlugins page) and they seem to use a single bitmap for collisions?

I imagine you could create a new bitmap on map load, draw rectangles on it where the shadows are, then assign it as the collision map. E.g. (untested!):
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc QMovement - for maps without a collision map, use shadow pen instead.
 * @url https://forums.rpgmakerweb.com/index.php?threads/151860/
 * @help Free to use and/or modify for any project, no credit required.
 */
void (alias => {

  const makeShadowCollisions = function(map) {
    // get values
    const data    = map.data();
    const width   = map.width();
    const height  = map.height();
    const tWidth  = map.tileWidth();
    const tHeight = map.tileHeight();
    const sWidth  = tWidth / 2;
    const sHeight = tHeight / 2;
    const cPass   = $gamePlayer.passableColors()[0];
    const cBlock  = QMovement.collision;
    // make a new bitmap
    const bmp     = new Bitmap(width * tWidth, height * tHeight);
    bmp.fillAll(cPass);
    // for every map tile...
    for (let x = width; x--;)
      for (let y = height; y--;)
        // and every shadow quadrant...
        for (let n = 4; n--;)
          // check if this shadow is set...
          if (data[(4 * height + y) * width + x] & (1 << n))
            // if so, draw rect
            bmp.fillRect(
              (x + x + n % 2) * sWidth,
              (y + y + Math.floor(n / 2)) * sHeight,
              sWidth,
              sHeight,
              cBlock
            );
    return bmp;
  };

  // Patch - add shadow pen collisions if no collision map defined
  Game_Map.prototype.loadCollisionmap = function(collisionMap) {
    alias.apply(this, arguments);
    if (!this._hasCM)
      ColliderManager.collisionMap.bitmap = makeShadowCollisions(this);
  };

  // Override - don't add visible shadows to tilemap.
  Tilemap.prototype._addShadow = function() {};

})(Game_Map.prototype.loadCollisionmap);
[Edit: corrected fillRect coordinates, they should be in px.]
[Edit 2: set the bitmap directly rather than use setCollisionMap (latter loads from file).]
Thank you so much for taking the time to watch it!
For some reason it keeps asking me for a picture


1665321357776.png
Oh, I see! Try replacing this line:
JavaScript:
ColliderManager.setCollisionMap(makeShadowCollisions(this));
...with this:
JavaScript:
ColliderManager.collisionMap.bitmap = makeShadowCollisions(this);
(I'll edit that into my previous post.)
Oh, I see! Try replacing this line:
JavaScript:
ColliderManager.setCollisionMap(makeShadowCollisions(this));
...with this:
JavaScript:
ColliderManager.collisionMap.bitmap = makeShadowCollisions(this);
(I'll edit that into my previous post.)
Aight, now the debugger qMovement has built in seems to interprete them as colliders
which is a great advance
1665326799154.png
ezgif.com-gif-maker.gif

But the player doesnt seem to interprete them
Aight, now the debugger qMovement has built in seems to interprete them as colliders
which is a great advance
View attachment 242331View attachment 242332
But the player doesnt seem to interprete them
Aight, got it working just had to change a few lines, seems like colliders weren't set.
Thanks a lot Caethyril, you inspire me to continue learning js!
ezgif.com-gif-maker.gif
1665368707225.png
Thread closed

Next time, please do not make multiple threads for the same question.

Original thread: https://forums.rpgmakerweb.com/threads/a-few-questions-about-shadow-pen.151860/