Notes to Self: Little tweaks, mostly chrono engine

Discussion in 'JS Plugin Releases (RMMV)' started by Restart, Aug 14, 2019.

  1. Restart

    Restart Veteran Veteran

    Messages:
    200
    Likes Received:
    128
    First Language:
    English
    Primarily Uses:
    RMMV
    Every now and then I'm using a plugin and it doesn't work quite the way I want it to, so I put in a little tweak to do what I want. Sometimes it's a bugfix, sometimes it's just changing things to be easier for me to work with. Since I'm not the only person using these plugins, I figured I'd put up a thread for these so other people can try them if they want.

    I'll be sporadically updating this whenever I have something I think other people might find useful.

    These are not optimized or cleaned up in any way, so it's almost certain there are better ways to do all of these things.

    Terms of Use: Do whatever you like.

    YEP_X_ExtDoodadPack1: Switching Doodads 'on' puts them at the beginning of their animation cycle.
    Yanfly's extended doodad plugin with switches is great to use, but when you switch an animated doodad on, it's at essentially random part of its animation cycle. That's because the doodads are silently going through each frame while transparent.

    I wanted animated doodads to be at the start of their animation cycle when switched on. This tweak does that by resetting the frame to 0 whenever the plugin refreshes a hidden doodad.
    Code:
    //from YEP_X_ExtDoodadPack1
    //
    Sprite_Doodad.prototype.updateCustomEDP1Z = function() {
      if ($gameTemp._modeGFD) return;
      // Party
      var length = this.partyHave.length;
      for (var i = 0; i < length; ++i) {
        var actorId = this.partyHave[i];
        if (!$gameParty._actors.contains(actorId)) {
          this.opacity = 0;
         this._index = 0;//reset the animation state so long as opacity is off, thus allowing for us to play doodad animations once.
          return;
        }
      }
      var length = this.partyMiss.length;
      for (var i = 0; i < length; ++i) {
        var actorId = this.partyMiss[i];
        if ($gameParty._actors.contains(actorId)) {
          this.opacity = 0;
         this._index = 0;//reset the animation state so long as opacity is off, thus allowing for us to play doodad animations once.
          return;
        }
      }
      // Switches
      var length = this.switchOn.length;
      for (var i = 0; i < length; ++i) {
        var switchId = this.switchOn[i];
        if (!$gameSwitches.value(switchId)) {
          this.opacity = 0;
         this._index = 0;//reset the animation state so long as opacity is off, thus allowing for us to play doodad animations once.
          return;
        }
      }
      var length = this.switchOff.length;
      for (var i = 0; i < length; ++i) {
        var switchId = this.switchOff[i];
        if ($gameSwitches.value(switchId)) {
          this.opacity = 0;
         this._index = 0;//reset the animation state so long as opacity is off, thus allowing for us to play doodad animations once.
          return;
        }
      }
    };


    MOG_ChronoEngine Item Core Compatibilty
    Chrono Engine is not compatible with yanfly's item core by default. This fixes that.
    Code:
    var _mog_toolSys_gmap_setup = Game_Map.prototype.setup;
    Game_Map.prototype.setup = function(mapId) {
       //console.log("Game_Map.prototype.setup");
       _mog_toolSys_gmap_setup.call(this,mapId);
       this._treasureEvents = [];
       this._battlersOnScreen = [];
       this._enemiesOnScreen = [];
       this._actorsOnScreen = [];
       $gameSystem._toolsOnMap = [];
       $gameTemp.clearToolCursor();
       //console.log($gameSystem._toolsData);// with itemcore, this always returns an empty array []
       //without itemcore, it returns 'null', then an the proper item  list, so clearly _toolsdata isn't getting set right
       //I assume the 'null' gets overridden by one of yanfly's blanket definitions, and since I can't find that
       // I'm just testing to see if the list is empty.  If it is, grab the tools again
       // it seems to work!
       //if (!$gameSystem._toolsData) {this.dataMapToolClear()};
       if (!$gameSystem._toolsData) {this.dataMapToolClear()
           }else{ if ($gameSystem._toolsData.length == 0) {this.dataMapToolClear()};
           }
       for (var i = 0; i < $gameParty.members().length; i++) {
           var actor = $gameParty.members()[i];
           actor.clearActing();
           $gameSystem._toolHookshotSprite = [null,null,0];
       };
    };

    MOG_ActorHud Meter Angle Fix
    Mog's actorhud converts from radians to degrees twice by default, which means if you set an angled bar the background
    won't be at the same angle as the filled bar. This typo is in all the different meters, but once you see the hp meter fix you can change whatever other ones you want.
    Code:
    //==============================
    // * Create HP Meter
    //==============================
    Actor_Hud.prototype.create_hp_meter = function() {
       if (String(Moghunter.ahud_hp_meter_visible) != "true") {return};
       this.removeChild(this._hp_meter_blue);
       this.removeChild(this._hp_meter_red);
       if (!this._battler) {return};
       this._hp_meter_red = new Sprite(this._hp_meter_img);
       this._hp_meter_red.x = this._pos_x + Moghunter.ahud_hp_meter_pos_x;
       this._hp_meter_red.y = this._pos_y + Moghunter.ahud_hp_meter_pos_y;
       this._hp_meter_red.rotation = Moghunter.ahud_hp_meter_rotation * Math.PI / 180;
       this._hp_meter_red.setFrame(0,0,0,0);
       this.addChild(this._hp_meter_red);    
       this._hp_meter_blue = new Sprite(this._hp_meter_img);
       this._hp_meter_blue.x = this._hp_meter_red.x;
       this._hp_meter_blue.y = this._hp_meter_red.y;
       this._hp_meter_blue.rotation = this._hp_meter_red.rotation; //this was incorrectly converting to radians twice
       this._hp_meter_blue.setFrame(0,0,0,0);
       this.addChild(this._hp_meter_blue);
       this._hp_old_ani[0] = this._battler.hp - 1;
       if (String(Moghunter.ahud_hp_meter_flow) === "true") {this._hp_flow[0] = true;
           this._hp_flow[2] = this._hp_meter_img.width / 3;
           this._hp_flow[3] = this._hp_flow[2] * 2;
           this._hp_flow[1] = Math.floor(Math.random() * this._hp_flow[2]);
       };
    };


    MOG_CharacterPoses+Mog_ChronoEngine Rotation Around Center + Set Sprite Rotations
    By default in rpgmaker, sprite rotation is around the base of a sprite. That's bad if you're rotating projectiles, since you end up with your hitbox being displaced off from where the sprite actually is.

    This function uses trig to identify where the sprite needs to be displaced so that it's rotated around the hitbox. (This requires that you center your sprite using mog's displacement tools to start with).
    [​IMG]

    Above: My Version (approximate hitbox in blue)
    Below: Default version

    In addition, I have added a few functions for rotating character sprites smoothly. Set a target angle and a rotation rate, and it will update each frame until it reaches the target angle.

    If you don't set a target angle, it will rotate at that speed forever.

    You can also set it to go in whichever direction is closer, ignoring the sign on the angle speed.

    Code:
    
     
    Game_CharacterBase.prototype.setTargetAngle = function(targetAngle) {
       var ag = targetAngle * Math.PI / 180;
        this._user.targetAngle = [ag,targetAngle];
    };
    
    Game_CharacterBase.prototype.setRotationRate = function(rotationSpeed) {
       var ag = rotationSpeed * Math.PI / 180;
        this._user.rotationSpeed = [ag,rotationSpeed];
    };
    
    Game_CharacterBase.prototype.setRotationFlexible = function() {
       //flag to say we can go clockwise OR counterclockwise, whichever is closer
        this._user.rotationFlexible= true;
    };
    
    Game_CharacterBase.prototype.clearRotationRate = function() {
       this._user.targetAngle =null;
        this._user.rotationSpeed = null;
       this._user.rotationFlexible= false;
    
    };
    
    
    
    Sprite_Character.prototype.updateCharPosesPosition = function() {
       //My x-offset does NOT move to the left for left-pointing poses and right for right-pointing.
       //it just shifts to the right if it's positive, and to the left if it's negative.
       //This is different than how mog does it, but this is how I prefer it.
    
       var ex = this._character._frames.x;
       var ey = this._character._frames.y;
     
       /* this.x += ex;
       this.y += ey; */
    
       ag=0;
       angle=0;
    
       thisHasRotationUser=false;
       thisHasRotationChar=false;
       //technically this isn't the 'correct' way of checking to see
       //if we have this trait, but there shouldn't be any edge cases that matter
       //since if rotation has a value but it resolves as 'false' we don't want to
       //rotate after all
       if (this._character._user.rotation)
       {
           thisHasRotationChar=true;
           [ag,angle] = this._character._user.rotation;
       } else {
           if (this._user.rotation)
           {
               console.log(this._user)
               thisHasRotationUser=true;
               [ag,angle] = this._user.rotation;
           }
       }
    
       if (thisHasRotationChar || thisHasRotationUser)
       {
           var isSpinning=false;
           var hasTargetAngle=false;
           if(thisHasRotationChar)
           {
               if (this._character._user.rotationSpeed)
               {
                   [agSpeed,angleSpeed] = this._character._user.rotationSpeed;
                   isSpinning=true;
               }
               if (this._character._user.targetAngle)
               {
                   [agTarget,angleTarget] = this._character._user.targetAngle;
                   hasTargetAngle=true;
               }
               if (isSpinning){
                   if(hasTargetAngle){
                       //if our target angle is within a single step, snap to it.
                       if(Math.abs(((((angleTarget+360) % 360)-((angle+360) % 360))/angleSpeed))<1){
                           this._character.setAngle(angleTarget);
                       }else{
                           //if we are allowed to go in either direction, pick the shorter distance
                           if(this._character._user.rotationFlexible)
                           {
                               if (((((angleTarget+360) % 360)-((angle+360) % 360) +360) % 360)>180)
                                   this._character.setAngle(angle-Math.abs(angleSpeed));
                               else
                                   this._character.setAngle(angle+Math.abs(angleSpeed));
                           }else{
                               this._character.setAngle(angle+angleSpeed);
                           }
                       }
                   }else{
                       //if we don't have a target angle, but do have a rotation speed, keep spinning without limit!
                       this._character.setAngle(angle+angleSpeed);
                   }
               }
           }else if(thisHasRotationUser){
               if (this._user.rotationSpeed)
               {
                   [agSpeed,angleSpeed] = this._user.rotationSpeed;
                   isSpinning=true;
               }
               if (this._user.targetAngle)
               {
                   [agTarget,angleTarget] = this._user.targetAngle;
                   hasTargetAngle=true;
               }
               if (isSpinning){
                   if(hasTargetAngle){
                       //if our target angle is within a single step, snap to it.
                       if(Math.abs(((((angleTarget+360) % 360)-((angle+360) % 360))/angleSpeed))<1){
                           this.setAngle(angleTarget);
                       }else{
                           if(this._user.rotationFlexible)
                           {
                               if (((((angleTarget+360) % 360)-((angle+360) % 360) +360) % 360)>180)
                                   this.setAngle(angle-Math.abs(angleSpeed));
                               else
                                   this.setAngle(angle+Math.abs(angleSpeed));
                           }else{
                               this.setAngle(angle+angleSpeed);
                           }
                       }
                   }else{
                       //if we don't have a target angle, but do have a rotation speed, keep spinning without limit!
                       this.setAngle(angle+angleSpeed);
                   }
               }
           }
    
        
           //update ag and angle
           if (this._character._user.rotation)
           {
               [ag,angle] = this._character._user.rotation;
           } else {
               if (this._user.rotation)
               {
                   [ag,angle] = this._user.rotation;
               }
           }
       }
       if (ag==0)
       {
       this.x += ex;
       this.y += ey;
       }else{
       //I have altered this code to
       //rotate events around the displacement point by default,
       //instead of the base of the sprite
     
       //technically this rotation is only off by a pixel or two, but w/e, close enough.
       baselength=Math.sqrt(ex*ex + ey*ey);
     
       if (ey == 0){
       baseag=Math.PI/2;
       }else{
       baseag=Math.atan(ex/ey);
       }
    
       this.x += ex*Math.cos(ag-baseag) - ey * Math.sin(ag-baseag);
       this.y += -ex*Math.sin(ag-baseag) + ey * Math.cos(ag-baseag);
    
       }
     
    };
     
    Last edited: Aug 14, 2019
    #1
  2. Restart

    Restart Veteran Veteran

    Messages:
    200
    Likes Received:
    128
    First Language:
    English
    Primarily Uses:
    RMMV
    Here's a JSX file I made for use as a photoshop macro. This takes in a single image that points to the right, and rotates it appropriately to create a 1-frame-wide sheet. I use it mostly for bullets.

    If you combine with irfanview's Options->Extract Image tiles to slice up a spritesheet, and Image->create Panorama Image to reassemble, you can fairly quickly go through an animated sheet.

    Code:
    doc = app.activeDocument;  
    //var creatureName = prompt("What is the file called?", "", "Enter filename");
    
        // strip the extension off
    var fileNameNoExtension = doc.name;
    fileNameNoExtension = fileNameNoExtension.split( "." );
    if ( fileNameNoExtension.length > 1 ) {
       fileNameNoExtension.length--;
    }
    fileNameNoExtension = fileNameNoExtension.join(".");
    creatureName=fileNameNoExtension;
    
    var originalImage = app.activeDocument.activeLayer;
    
    var savedRuler= app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var w = app.activeDocument.width;
    var h = app.activeDocument.height;
    doc.resizeImage(UnitValue(w*2,"px"),UnitValue(h*2,"px"),null,ResampleMethod.NEARESTNEIGHBOR);
    w = app.activeDocument.width;
    h = app.activeDocument.height;
    //add a fringe of 1 pixel on each side to avoid bleeding
    if(w>h) app.activeDocument.resizeCanvas (w+2, w+2, AnchorPosition.MIDDLECENTER);
    if(w<h) app.activeDocument.resizeCanvas (h+2, h+2, AnchorPosition.MIDDLECENTER);
    w = app.activeDocument.width;
    h = app.activeDocument.height;
    app.activeDocument.resizeCanvas (w, h*4, AnchorPosition.TOPCENTER);
    
    var downView = originalImage.duplicate();
    downView.rotate(90,AnchorPosition.MIDDLECENTER)
    if(downView.bounds[0]%2==1) downView.translate(1,0)
    if(downView.bounds[1]%2==1) downView.translate(0,-1)
    if(downView.bounds[1]<0) downView.translate(0,2)
    
    originalImage.translate(0,h)
    
    var leftView = originalImage.duplicate();
    originalImage.resize(-100,100)
    leftView.translate(0,h)
    if(leftView.bounds[0]%2==1) leftView.translate(-1,0)
    if(leftView.bounds[1]%2==1) leftView.translate(0,1)
    
    
    var upView = originalImage.duplicate();
    upView.translate(0,2*h)
    upView.resize(-100,100)
    upView.rotate(-90,AnchorPosition.MIDDLECENTER)
    upView.translate(1,-1)
    if(upView.bounds[0]%2==1) upView.translate(-1,0)
    if(upView.bounds[1]%2==1) upView.translate(0,1)
       
    if(originalImage.bounds[0]%2==1) originalImage.translate(1,0)
    if(originalImage.bounds[1]%2==1) originalImage.translate(0,1)
    
    //resize back down, now that we've dodged photoshop's stupidity with rotating odd-pixel-sized images
    w = app.activeDocument.width;
    h = app.activeDocument.height;
    doc.resizeImage(UnitValue(w/2,"px"),UnitValue(h/2,"px"),null,ResampleMethod.NEARESTNEIGHBOR);
    
    var pngFile = File("C:/Users/YOURUSERNAME/Documents/ConvertedRMMV/" +"$B_" + creatureName + "(f1).png");
    pngSaveOptions = new PNGSaveOptions();
    doc.saveAs(pngFile, pngSaveOptions, true, Extension.LOWERCASE);
    
    app.preferences.rulerUnits = savedRuler;
     
    #2

Share This Page