reta232

Layered Actors 0_2_0

Apr 26th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Reta = Reta || {};
  2.  
  3. //=============================================================================
  4.  /*:
  5.  * @plugindesc Allows for creators to make custom actors on the fly
  6.  * @author Reta
  7.  *
  8.  * @param Bitmap1
  9.  * @default TV_Body_p01,0,0,0,0
  10.  *
  11.  * @param Bitmap2
  12.  * @default TV_AccB_p05,0,0,0,0
  13.  *
  14.  * @param Bitmap3
  15.  * @default TV_Clothing1_p04,0,0,0,0
  16.  *
  17.  * @param Bitmap4
  18.  * @default TV_Clothing1_p04,0,0,0,0
  19.  *
  20.  * @param Bitmap5
  21.  * @default TV_FrontHair1_p12,0,0,0,0
  22.  *
  23.  * @param Bitmap6
  24.  * @default TV_RearHair1_p01,0,0,0,0
  25.  *
  26.  * @param Bitmap7
  27.  * @default TV_RearHair2_p01,0,0,0,0
  28.  *
  29.  * @param Actor1
  30.  * @default 1
  31.  *
  32.  * @param Actor2
  33.  * @default 2
  34.  *
  35.  * @param Actor3
  36.  * @default 3
  37.  *
  38.  * @param Actor4
  39.  * @default 4
  40.  * @help
  41.  */
  42. //=============================================================================
  43.  
  44. //=============================================================================
  45. // Parameter Variables
  46. //=============================================================================
  47.  
  48. (function(){
  49.  
  50. Reta.Param = Reta.Param || {};
  51.  
  52. Reta.parameters = PluginManager.parameters('CustomActors');
  53.  
  54. Reta.Param.Bitmap = [];
  55.                        
  56. Reta.Param.actorId = [Reta.parameters['Actor1'] , Reta.parameters['Actor2'] , Reta.parameters['Actor3'] , Reta.parameters['Actor4']];    
  57.  
  58. Reta.Param.init = function (){
  59.         var temp = String(Reta.parameters['Bitmap1']).split(',');
  60.         this.Bitmap[0] = [ temp[0], temp.slice(1)];
  61.        
  62.         temp = String(Reta.parameters['Bitmap7']).split(',');
  63.         this.Bitmap[1] = [ temp[0], temp.slice(1)];
  64.        
  65.         temp = String(Reta.parameters['Bitmap3']).split(',');
  66.         this.Bitmap[2] = [ temp[0], temp.slice(1)];
  67.        
  68.         temp = String(Reta.parameters['Bitmap6']).split(',');
  69.         this.Bitmap[3] = [ temp[0], temp.slice(1)];
  70.        
  71.         temp = String(Reta.parameters['Bitmap5']).split(',');
  72.         this.Bitmap[4] = [ temp[0], temp.slice(1)];
  73.        
  74.         temp = String(Reta.parameters['Bitmap2']).split(',');
  75.         this.Bitmap[5] = [ temp[0], temp.slice(1)];
  76.        
  77.  
  78. };
  79.  
  80. function clone (existingArray) {
  81.    var newObj = (existingArray instanceof Array) ? [] : {};
  82.    for (i in existingArray) {
  83.       if (i == 'clone') continue;
  84.       if (existingArray[i] && existingArray[i] instanceof Array) {
  85.          newObj[i] = clone(existingArray[i]);
  86.       } else {
  87.          newObj[i] = existingArray[i]
  88.       }
  89.    }
  90.    return newObj;
  91. }
  92.  
  93. function deepClone(arr) {
  94.   var len = arr.length;
  95.   var newArr = new Array(len);
  96.   for (var i=0; i<len; i++) {
  97.     if (Array.isArray(arr[i])) {
  98.       newArr[i] = deepClone(arr[i]);
  99.     }
  100.     else {
  101.       newArr[i] = arr[i];
  102.     }
  103.   }
  104.   return newArr;
  105. }
  106.  
  107. Reta.Param.init();
  108.  
  109. ImageData.prototype.clone = function(){
  110.     var contextBMP = new Bitmap(this.width, this.height);
  111.     var context = contextBMP.context;
  112.     var cloneData = context.createImageData(this.width, this.height);
  113.     console.log(this);
  114.     for(var i = 0; i < this.data.length; i+=4)
  115.     {
  116.         cloneData.data[i+0]=this.data[i+0];
  117.         cloneData.data[i+1]=this.data[i+1];
  118.         cloneData.data[i+2]=this.data[i+2];
  119.         cloneData.data[i+3]=this.data[i+3];
  120.     }
  121.     //cloneData.data = deepClone(this.data);
  122.     return cloneData;
  123. }
  124.  
  125. Reta.Param.setDirectory = function(){
  126.    
  127.     for(i = 0; i < this.Bitmap.length; i++)
  128.     {
  129.         this.Bitmap[i][0] = "custom/" + this.Bitmap[i][0];
  130.     }
  131.    
  132. };
  133. Reta.Param.setDirectory();
  134.  
  135. var _getAllFilesFromFolder = function(dir) {
  136.  
  137.     var filesystem = require("fs");
  138.     var results = [];
  139.  
  140.     filesystem.readdirSync(dir).forEach(function(file) {
  141.  
  142.         var curFS = dir+'/'+file;
  143.         var stat = filesystem.statSync(curFS);
  144.  
  145.         if (stat && stat.isDirectory()) {
  146.             results = results.concat(_getAllFilesFromFolder(curFS))
  147.         } else results.push(curFS);
  148.  
  149.     });
  150.  
  151.     return results;
  152.  
  153. };
  154. Reta.Param.Dir = _getAllFilesFromFolder("www/img/custom");
  155.  
  156. Array.prototype.pixelSort = function (pixel, max){
  157.     for(var j = 0; j < pixel.length; j+=4){
  158.         if(pixel[3+j] > 0){
  159.             var temp = pixel.subarray(j,3+j);
  160.             var test = false;
  161.            
  162.             for(var i = 0; i < this.length; i++)
  163.             {
  164.                 if(this[i][0] === temp[0]
  165.                 && this[i][1] === temp[1]
  166.                 && this[i][2] === temp[2]){
  167.                     test = true;
  168.                     break;
  169.                 }
  170.             }
  171.             //console.log(test);
  172.             if(test === false){
  173.                 //console.log("found one");
  174.                 this[this.length] = temp;
  175.                 if(this.length >= max) return true;
  176.             }
  177.         }
  178.     }
  179. }
  180.    
  181.  
  182.  
  183. //=============================================================================
  184. // Image Manager
  185. //=============================================================================
  186.  
  187. Reta.Sprite_Proto_initialize = Sprite.prototype.initialize;
  188. Sprite.prototype.initialize = function(bitmap) {
  189.     Reta.Sprite_Proto_initialize.call(this, bitmap);
  190.     this._isComposite = false;
  191. }
  192.  
  193. Reta.ImageManager_isBigCharacter = function(filename)
  194. {
  195.     if(filename instanceof Array)
  196.     {
  197.         //console.log("Array Reta.ImageManager_isBigCharacter");
  198.         return true;
  199.     }
  200.     else
  201.     {
  202.         return ImageManager.isBigCharacter(filename);
  203.     }
  204. };
  205.  
  206. Reta.ImageManager_isObjectCharacter = function(filename) {
  207.     if(filename instanceof Array)
  208.     {
  209.         var sign = filename[0][0].match(/^[\!\$]+/);
  210.         return sign && sign[0].contains('!');
  211.     }
  212.     else
  213.     {
  214.         return ImageManager.isObjectCharacter(filename);
  215.     }
  216. };
  217.  
  218. //=============================================================================
  219. // Sprite Character
  220. //=============================================================================
  221.  
  222. Sprite_Character.prototype.initMembers = function() {
  223.     this.anchor.x = 0.5;
  224.     this.anchor.y = 1;
  225.     this._character = null;
  226.     this._balloonDuration = 0;
  227.     this._tilesetId = 0;
  228.     this._upperBody = null;
  229.     this._lowerBody = null;
  230.     this._layers = [null];
  231. };
  232.  
  233. Sprite_Character.prototype.setCharacterBitmap = function() {
  234.     //if(!this.random)this.random = Math.floor(Math.random()*20000);
  235.     if(this._character instanceof Game_Follower || this._character instanceof Game_Player)
  236.     {
  237.         console.log(true);
  238.         if(this._character.actor()._characterBitmap instanceof Bitmap)
  239.         {
  240.            
  241.             this.bitmap = this._character.actor()._characterBitmap;
  242.             this.bitmap._setDirty;
  243.             this._isBigCharacter = true;
  244.         }
  245.     }
  246.     else
  247.     {
  248.         this.bitmap = ImageManager.loadCharacter(this._characterName);
  249.         this._isBigCharacter = Reta.ImageManager_isBigCharacter(this._characterName);
  250.     }
  251.    
  252. };
  253.  
  254. //Reta.Sprite_Character_Proto_updateBitmap = Sprite_Character.prototype.updateBitmap;
  255. Sprite_Character.prototype.updateBitmap = function() {
  256.     if(this._characterName instanceof Array)
  257.     {
  258.         //console.log("Array Reta.Sprite_Character_Proto_updateBitmap ");
  259.         if (this.isImageChanged())
  260.         {
  261.             this._tilesetId = $gameMap.tilesetId();
  262.             this._tileId = this._character.tileId();
  263.             //this._characterName.every(function(element, index) { element = this._character.characterName()[index] } )
  264.             console.log("Changed Image");
  265.             console.log(this._characterName);
  266.             console.log(this._character.characterName().slice());
  267.             this._characterName = this._character.characterName().slice();
  268.             this._characterIndex = this._character.characterIndex();
  269.             if (this._tileId > 0) {
  270.                 this.setTileBitmap();
  271.             } else {
  272.                 this.setCharacterBitmap();
  273.             }
  274.         }
  275.     }
  276.     else{
  277.     //Reta.Sprite_Character_Proto_updateBitmap.call(this);
  278.     if (this.isImageChanged())
  279.         {
  280.             this._tilesetId = $gameMap.tilesetId();
  281.             this._tileId = this._character.tileId();
  282.             //this._characterName.every(function(element, index) { element = this._character.characterName()[index] } )
  283.             this._characterName = this._character.characterName();
  284.             this._characterIndex = this._character.characterIndex();
  285.             if (this._tileId > 0) {
  286.                 this.setTileBitmap();
  287.             } else {
  288.                 this.setCharacterBitmap();
  289.             }
  290.         }
  291.     }
  292. };
  293.  
  294. //Reta.Sprite_Character_Proto_isImageChanged = Sprite_Character.prototype.isImageChanged;
  295. Sprite_Character.prototype.isImageChanged = function() {
  296.     if(this._characterName instanceof Array)
  297.     {
  298.         //console.log("Array Reta.Sprite_Character_Proto_isImageChanged ");
  299.         //console.log(this._characterName.every(function(element, index) { return element === this._character.characterName()[index] } ));
  300.         return (this._tilesetId !== $gameMap.tilesetId() ||
  301.                 this._tileId !== this._character.tileId() ||
  302.                 //this._characterName.every(function(element, index) { return element === this._character.characterName()[index] } ) ||
  303.                 this._characterName[0][0] !== this._character.characterName()[0][0] ||
  304.                 this._characterIndex !== this._character.characterIndex());
  305.     }
  306.     else{
  307.         //Reta.Sprite_Character_Proto_isImageChanged.call(this);
  308.         return (this._tilesetId !== $gameMap.tilesetId() ||
  309.                 this._tileId !== this._character.tileId() ||
  310.                 this._characterName !== this._character.characterName() ||
  311.                 this._characterIndex !== this._character.characterIndex());
  312.     }
  313. };
  314.  
  315. Sprite_Character.prototype.createLayeredSprites = function(number) {
  316.     if (!this._layers[number]) {
  317.         this._layers[number] = new Sprite();
  318.         this._layers[number].anchor.x = this.anchor.x;
  319.         this._layers[number].anchor.y = this.anchor.y;
  320.         this._layers[number]._character = this._character;
  321.         this._layers[number]._characterIndex = this._characterIndex;
  322.         //this._layers[number].
  323.         this.addChild(this._layers[number]);
  324.     }
  325. };
  326.  
  327. Sprite_Character.prototype.updateCharacterFrame = function() {
  328.     var pw = this.patternWidth();
  329.     var ph = this.patternHeight();
  330.     var sx = (this.characterBlockX() + this.characterPatternX()) * pw;
  331.     var sy = (this.characterBlockY() + this.characterPatternY()) * ph;
  332.     //console.log("Update Frame");
  333.     this.updateHalfBodySprites();
  334.    
  335.     if (this._bushDepth > 0) {
  336.         var d = this._bushDepth;
  337.         this._upperBody.setFrame(sx, sy, pw, ph - d);
  338.         this._lowerBody.setFrame(sx, sy + ph - d, pw, d);
  339.         this.setFrame(sx, sy, 0, ph);
  340.        
  341.         for(i = 0; i < this._layers.length; i++)
  342.         {
  343.             this.createLayeredSprites(i);
  344.             if(this._layers[i] == null)
  345.             {
  346.                 break;
  347.             }
  348.             else
  349.                 //console.log("Update Frame child Bush");
  350.                 this._layers[i].setFrame(sx, sy, 0, ph);
  351.         }
  352.     } else {
  353.         this.setFrame(sx, sy, pw, ph);
  354.         for(i = 0; i < this._layers.length; i++)
  355.         {
  356.             this.createLayeredSprites(i);
  357.             if(this._layers[i] == null)
  358.             {
  359.                 break;
  360.             }
  361.             else
  362.             {
  363.                 //console.log("Update Frame child");
  364.                 this._layers[i].setFrame(sx, sy, pw, ph);
  365.             }
  366.         }
  367.     }
  368. };
  369.  
  370.  
  371. //=============================================================================
  372. // Game Character
  373. //=============================================================================
  374.  
  375. Reta.Game_CharacterBase_Proto_initMembers = Game_CharacterBase.prototype.initMembers;
  376. Game_CharacterBase.prototype.initMembers = function()
  377. {
  378.     //console.log("Array Reta.Game_Character_Proto_initMembers ");
  379.     Reta.Game_CharacterBase_Proto_initMembers.call(this);
  380.     this._defaultCharacterName = '';
  381. };
  382.  
  383. //Reta.Game_CharacterBase_Proto_characterName = Game_CharacterBase.prototype.characterName;
  384. Game_CharacterBase.prototype.characterName = function() {
  385.     if(this._characterName instanceof Array)
  386.     {
  387.         //console.log("Array Reta.GCBcN ");
  388.         return this._characterName.slice();
  389.     }
  390.     else
  391.     {
  392.         return this._characterName;
  393.     }
  394. };
  395.  
  396. //Reta.Game_CharacterBase_Proto_setImage = Game_CharacterBase.prototype.setImage;
  397. Game_CharacterBase.prototype.setImage = function(characterName, characterIndex) {
  398.     if(characterName instanceof Array)
  399.     {
  400.         //console.log("Array Reta.GCBsI ");
  401.         this._tileId = 0;
  402.         this._characterName = characterName.slice();
  403.         this._characterIndex = characterIndex;
  404.     //  console.log(this._characterName[0][0]);
  405.         this._isObjectCharacter = Reta.ImageManager_isObjectCharacter(characterName);
  406.     }
  407.     else
  408.     {
  409.         //Reta.Game_CharacterBase_Proto_setImage.call(this, characterName, characterIndex);
  410.     //  console.log("Array Reta.GCBsI ");
  411.         this._tileId = 0;
  412.         this._characterName = characterName;
  413.         this._characterIndex = characterIndex;
  414.         this._isObjectCharacter = Reta.ImageManager_isObjectCharacter(characterName);
  415.     }
  416. };
  417.  
  418. //=============================================================================
  419. // Game Actor
  420. //=============================================================================
  421.  
  422. Reta.Game_Actor_Proto_initMembers = Game_Actor.prototype.initMembers;
  423. Game_Actor.prototype.initMembers = function() {
  424.     Reta.Game_Actor_Proto_initMembers.call(this);
  425.     this._magic = 'undefined';
  426.     this._characterBitmap = {};
  427.     this._faceBitmap = {};
  428.     this._battlerBitmap = {};
  429.     this._characterArray = [];
  430. }
  431.  
  432. Reta.Game_Actor_Proto_Setup = Game_Actor.prototype.setup;
  433. Game_Actor.prototype.setup = function (actorId)
  434. {
  435.     Reta.Game_Actor_Proto_Setup.call(this, actorId);
  436.     //this._isComposite = false;
  437.     this._magic = 'undefined';
  438.     for( i = 0; i < Reta.Param.actorId.length ; i++)
  439.     {
  440.         if($dataActors[Number(Reta.Param.actorId[i])] == this.actor())
  441.         {
  442.         //  console.log("Before Set Image" + i);
  443.             this._characterArray = deepClone(Reta.Param.Bitmap);
  444.            
  445.             for(j = 0; j < this._characterArray[5][1].length; j++)
  446.             {
  447.                 this._characterArray[5][1][j] = Math.floor(Math.random() * 69);
  448.             }
  449.             //this.setCharacterImage(this._imageArray, 0);
  450.         //  console.log(this._imageArray);
  451.             //this._isComposite = true;
  452.         }
  453.     }
  454.     console.log(this._characterArray);
  455.     this.setBitmaps();
  456. };
  457.  
  458. Game_Actor.prototype.setBitmaps = function(){
  459.     if(this._characterArray instanceof Array && this._characterArray != [])
  460.     {
  461.         var tempmap = ImageManager.loadCharacter(this._characterArray[0][0]);
  462.         this._characterBitmap = new Bitmap(tempmap.width, tempmap.height);
  463.         tempmap.addLoadListener(function(){
  464.             this._characterBitmap.blt(tempmap, 0, 0, tempmap.width, tempmap.height,0,0);
  465.             for(var i = 1; i < this._characterArray.length; i++)
  466.             {
  467.                 var characterRGB = this._characterArray[i][1];
  468.                 var bitmap = ImageManager.loadCharacter(this._characterArray[i][0]);
  469.                 var overlay = new Bitmap(bitmap.width, bitmap.height);
  470.                 var sub = ImageManager.loadCharacter(this._characterArray[i][0] + '_c');
  471.                 bitmap.addLoadListener(function(){
  472.                     overlay.blt(bitmap, 0, 0, overlay.width, overlay.height, 0,0)
  473.                     for (var j = 0; j < characterRGB.length; j++)
  474.                     {
  475.                         if(characterRGB[j] < 70 && characterRGB[j] >= 0){
  476.                             overlay.setGradient(characterRGB[j],j,sub);
  477.                         }
  478.                     }
  479.                     this._characterBitmap.blt(overlay, 0, 0, bitmap.width, bitmap.height,0 ,0);
  480.                    
  481.                 }.bind(this, characterRGB));
  482.             }
  483.         }.bind(this));
  484.        
  485.     }
  486. };
  487.  
  488. //Reta.Game_Actor_Proto_characterName = Game_Actor.prototype.characterName;
  489. Game_Actor.prototype.characterName = function() {
  490.     if(this._characterName instanceof Array)
  491.     {   //console.log("Array Reta.GAcN ");
  492.         return this._characterName.slice();
  493.     }
  494.     else
  495.         return this._characterName;
  496. };
  497.  
  498. //Reta.Game_Actor_Proto_initImages = Game_Actor.prototype.initImages;
  499. Game_Actor.prototype.initImages = function() {
  500.     var actor = this.actor();
  501.     if(actor.characterName instanceof Array)
  502.     {
  503.     //  console.log("Array Reta.GAiI ");
  504.         console.log("INIT IMAGES");
  505.         console.log(this._characterName);
  506.         this._characterName = actor.characterName.slice();
  507.         console.log(this._characterName);
  508.     }
  509.     else
  510.     {
  511.         this._characterName = actor.characterName;
  512.     }
  513.     this._characterIndex = actor.characterIndex;
  514.     this._faceName = actor.faceName;
  515.     this._faceIndex = actor.faceIndex;
  516.     this._battlerName = actor.battlerName;
  517. };
  518.  
  519.  
  520. //Reta.Game_Actor_Proto_setCharacterImage = Game_Actor.prototype.setCharacterImage;
  521. Game_Actor.prototype.setCharacterImage = function(characterName, characterIndex) {
  522.     if(characterName instanceof Array)
  523.     {
  524.     //  console.log("Array Reta.GAcI ");
  525.         console.log("SET CHARACTER IMAGE");
  526.         console.log(this._characterName);
  527.         this._defaultCharacterName = this.characterName;
  528.         this._characterName = characterName.slice();
  529.         this._characterIndex = characterIndex;
  530.         console.log(this._characterName);
  531.     }
  532.     else{
  533.         //Reta.Game_Actor_Proto_setCharacterImage.call(this, characterName, characterIndex);
  534.         this._characterName = characterName;
  535.         this._characterIndex = characterIndex;
  536.     }
  537. };
  538.  
  539. Game_Player.prototype.actor = function(){
  540.     return $gameParty.leader();
  541. };
  542.  
  543. //=============================================================================
  544. // Bitmap
  545. //=============================================================================
  546.  
  547. Reta.Bitmap_Proto_Init = Bitmap.prototype.initialize;
  548. Bitmap.prototype.initialize = function(width, height)
  549. {
  550.     Reta.Bitmap_Proto_Init.call(this, width, height);
  551. };
  552.  
  553. Bitmap.prototype.setAlphaColor = function(alpha)
  554. {
  555.         var context = this._context;
  556.         var imageData = context.getImageData(0, 0, this.width, this.height);
  557.         var pixels = imageData.data;
  558.         for (var i = 0; i < pixels.length; i += 4)
  559.         {
  560.             if(pixels[i + 3] > 0) pixels[i + 3] = alpha;
  561.         }
  562.         context.putImageData(imageData, 0, 0);
  563. };
  564. //70*4-1
  565. Bitmap.prototype.setGradient = function(number, subNumber, sub){
  566.    
  567.     var gradient = ImageManager.loadCharacter('custom/gradients');
  568.     //var sub = ImageManager.loadCharacter(characterName + "_c");
  569.     if(number < 0 || number > 69) {
  570.     //  console.log("Invalid Gradient");
  571.         return;
  572.     }
  573.    
  574.     function rgbToHsl(r, g, b)
  575.     {
  576.         var cmin = Math.min(r, g, b);
  577.         var cmax = Math.max(r, g, b);
  578.         var h = 0;
  579.         var s = 0;
  580.         var l = (cmin + cmax) / 2;
  581.         var delta = cmax - cmin;
  582.  
  583.         if (delta > 0) {
  584.             if (r === cmax) {
  585.                 h = 60 * (((g - b) / delta + 6) % 6);
  586.             } else if (g === cmax) {
  587.                 h = 60 * ((b - r) / delta + 2);
  588.             } else {
  589.                 h = 60 * ((r - g) / delta + 4);
  590.             }
  591.             s = delta / (255 - Math.abs(2 * l - 255));
  592.         }
  593.         return [h, s, l];
  594.     }
  595.  
  596.     function hslToRgb(h, s, l)
  597.     {
  598.         var c = (255 - Math.abs(2 * l - 255)) * s;
  599.         var x = c * (1 - Math.abs((h / 60) % 2 - 1));
  600.         var m = l - c / 2;
  601.         var cm = c + m;
  602.         var xm = x + m;
  603.  
  604.         if (h < 60) {
  605.             return [cm, xm, m];
  606.         } else if (h < 120) {
  607.             return [xm, cm, m];
  608.         } else if (h < 180) {
  609.             return [m, cm, xm];
  610.         } else if (h < 240) {
  611.             return [m, xm, cm];
  612.         } else if (h < 300) {
  613.             return [xm, m, cm];
  614.         } else {
  615.             return [cm, m, xm];
  616.         }
  617.     }
  618.        
  619.    
  620.  
  621.     sub.addLoadListener(function(){
  622.         gradient.addLoadListener(function(){
  623.  
  624.        
  625.    
  626.         var context = this._context;
  627.         var imageData = context.getImageData(0, 0, this.width, this.height);
  628.         var pixels = imageData.data;
  629.        
  630.         var gradientContext = gradient._context;
  631.         var gradientImageData = gradientContext.getImageData(0, 0, 256, 280);
  632.         var gradientPixels = gradientImageData.data;
  633.         var gradientRow = (256/*Gradient Width*/ * number * 4/*Single Gradient Height*/);
  634.        
  635.         var subContext = sub._context;
  636.         var subImageData = subContext.getImageData(0, 0, this.width, this.height);
  637.         var subPixels = subImageData.data;
  638.         var subColor = [];
  639.        
  640.         //console.log("sub Color Test = " + subColor.pixelSort(subPixels.subarray(), subNumber+1));
  641.         subColor.pixelSort(subPixels.subarray(), subNumber+1);
  642.         //console.log(subColor);
  643.         if(subColor === undefined || subColor[0] === undefined) return;
  644.         while(subColor[subNumber] === undefined) {
  645.             subNumber--;
  646.             if(subNumber < 0) return;
  647.         }
  648.         for (var i = 0; i < pixels.length; i += 4) {
  649.             if(subPixels[i + 0] == subColor[subNumber][0] && subPixels[i + 1] == subColor[subNumber][1] && subPixels[i + 2] == subColor[subNumber][2])
  650.             {
  651.                 var hsl = rgbToHsl(pixels[i + 0], pixels[i + 1], pixels[i + 2]);
  652.                 //console.log(hsl);
  653.                 var code = 255-Math.floor(hsl[2]);
  654.                 pixels[i + 0] = gradientPixels[((gradientRow + code)*4) + 0];
  655.                 pixels[i + 1] = gradientPixels[((gradientRow + code)*4) + 1];
  656.                 pixels[i + 2] = gradientPixels[((gradientRow + code)*4) + 2];
  657.                 //console.log([pixels[i+0],pixels[i+1],pixels[i+2]]);
  658.             }
  659.         }
  660.         context.putImageData(imageData, 0, 0);
  661.         this._setDirty();
  662.     }.bind(this))}.bind(this))
  663.    
  664. }
  665.  
  666.  
  667. Bitmap.prototype.reload = function() {
  668.     var bitmap = new Bitmap();
  669.     bitmap._image = new Image();
  670.     bitmap._image.src = this._url;
  671.     bitmap._image.onload = Bitmap.prototype._onLoad.bind(bitmap);
  672.     bitmap._image.onerror = Bitmap.prototype._onError.bind(bitmap);
  673.     bitmap._url = this._url;
  674.     bitmap._isLoading = true;
  675.     return bitmap;
  676. };
  677.  
  678. //=============================================================================
  679. // Data Manager
  680. //=============================================================================
  681.  
  682.  
  683. Reta.DataManager_loadAllSavefileImages = function() {
  684.     var globalInfo = DataManager.loadGlobalInfo();
  685.     if (globalInfo) {
  686.         for (var i = 1; i < globalInfo.length; i++) {
  687.             if (DataManager.isThisGameFile(i)) {
  688.                 var info = globalInfo[i];
  689.                 this.DataManager_loadSavefileImages(info);
  690.             }
  691.         }
  692.     }
  693. };
  694.  
  695. Reta.DataManager_loadSavefileImages = function(info) {
  696.     if (info.characters) {
  697.         for (var i = 0; i < info.characters.length; i++) {
  698.             if(info.characters[i][0] instanceof Array)
  699.             {
  700.                 for(j = 0; j < info.characters[i][0].length; j++)
  701.                 {
  702.                     ImageManager.loadCharacter(info.characters[i][0][j][0]);
  703.                 }
  704.             } else {
  705.                 ImageManager.loadCharacter(info.characters[i][0]);
  706.             }
  707.         }
  708.     }
  709.     if (info.faces) {
  710.         for (var j = 0; j < info.faces.length; j++) {
  711.             ImageManager.loadFace(info.faces[j][0]);
  712.         }
  713.     }
  714. };
  715.  
  716. //=============================================================================
  717. // Scene File
  718. //=============================================================================
  719.  
  720. Scene_File.prototype.create = function() {
  721.     Scene_MenuBase.prototype.create.call(this);
  722.     Reta.DataManager_loadAllSavefileImages();
  723.     this.createHelpWindow();
  724.     this.createListWindow();
  725. };
  726.  
  727.  
  728. //=============================================================================
  729. // Window Base
  730. //=============================================================================
  731.  
  732. Window_Base.prototype.initialize = function(x, y, width, height) {
  733.     Window.prototype.initialize.call(this);
  734.     this.loadWindowskin();
  735.     this.move(x, y, width, height);
  736.     this.updatePadding();
  737.     this.updateBackOpacity();
  738.     this.updateTone();
  739.     this.createContents();
  740.     this._layers = [];
  741.     this._opening = false;
  742.     this._closing = false;
  743.     this._dimmerSprite = null;
  744. };
  745.  
  746. Reta.Window_Base_Proto_drawCharacter = Window_Base.prototype.drawCharacter;
  747. Window_Base.prototype.drawCharacter = function(characterName, characterIndex, x, y) {
  748.     if(characterName instanceof Array)
  749.     {
  750.        
  751.             var number = 0;
  752.             for(i = 0; i < characterName.length; i++)
  753.             {
  754.                 var bitmap = ImageManager.loadCharacter(characterName[i][0]);
  755.                 var overlay = new Bitmap(bitmap.width, bitmap.height);
  756.                 var storemap = new Bitmap(bitmap.width, bitmap.height);
  757.                 var characterRGB = characterName[i][1].slice();
  758.                 var characterNameCur = characterName[i][0];
  759.                 var big = Reta.ImageManager_isBigCharacter(characterName);
  760.                 var pw = bitmap.width / (big ? 3 : 12);
  761.                 var ph = bitmap.height / (big ? 4 : 8);
  762.                 var n = characterIndex;
  763.                 var sx = (n % 4 * 3 + 1) * pw;
  764.                 var sy = (Math.floor(n / 4) * 4) * ph;
  765.  
  766.                
  767.                 bitmap.addLoadListener(function(){
  768.                    
  769.                     overlay.blt(bitmap, 0,0, overlay.width, overlay.height, 0,0);
  770.                     //console.log(overlay._url);
  771.                     var sub = ImageManager.loadCharacter(characterNameCur + "_c");
  772.                    
  773.                     for (var i = 0; i < characterRGB.length; i++)
  774.                     {
  775.                         if(characterRGB[i] < 70 && characterRGB[i] >= 0){
  776.                             overlay.setGradient(characterRGB[i],i,sub);
  777.                         }
  778.                     }
  779.                     this.contents.blt(overlay, sx, sy, pw, ph, x - pw / 2, y - ph);
  780.                     storemap.blt(overlay, 0, 0, bitmap.width, bitmap.height,0, 0);
  781.                     number++;
  782.                     if(number >= characterName.length){
  783.                         var context = storemap._context;
  784.                         var imageData = context.getImageData(0, 0, storemap.width, storemap.height);
  785.                         characterName[0] = characterNameCur;
  786.                         characterName[1] = imageData.data.subarray();
  787.                     }
  788.                    
  789.                 }.bind(this));
  790.             }
  791.        
  792.     }
  793.     else
  794.     {
  795.         Reta.Window_Base_Proto_drawCharacter.call(this, characterName, characterIndex, x, y);
  796.        
  797.     }
  798.    
  799. };
  800.  
  801. Window_Base.prototype.drawLayeredCharacter = function(number, width, height){
  802.     if (!this._layers[number])
  803.     {
  804.         this._layers[number] = new Bitmap(this.contentsWidth(), this.contentsHeight());
  805.         //this._layers[number].a
  806.         this.addChild(this._layers[number]);
  807.     }
  808. }
  809.  
  810. Reta.DataManager_saveGameWithoutRescue = DataManager.saveGameWithoutRescue;
  811. DataManager.saveGameWithoutRescue = function(savefileId) {
  812.     var temp = [];
  813.     for(var i = 0; i < $gameActors._data.length; i++){
  814.         if($gameActors._data[i])
  815.         {
  816.             temp[i] = $gameActors._data[i]._characterBitmap;
  817.             $gameActors._data[i]._characterBitmap = {};
  818.         }
  819.     }
  820.     var returnValue = Reta.DataManager_saveGameWithoutRescue.call(this, savefileId);
  821.     for(var i = 0; i < $gameActors._data.length; i++){
  822.         if($gameActors._data[i])
  823.         {
  824.             $gameActors._data[i]._characterBitmap = temp[i];
  825.         }
  826.     }
  827.     return returnValue;
  828. };
  829.  
  830. Window_SavefileList.prototype.drawContents = function(info, rect, valid) {
  831.     console.log(info);
  832.     var bottom = rect.y + rect.height;
  833.     if (rect.width >= 420) {
  834.         this.drawGameTitle(info, rect.x + 192, rect.y, rect.width - 192);
  835.         if (valid) {
  836.             this.drawPartyCharacters(info, rect.x + 220, bottom - 4);
  837.         }
  838.     }
  839.     var lineHeight = this.lineHeight();
  840.     var y2 = bottom - lineHeight;
  841.     if (y2 >= lineHeight) {
  842.         this.drawPlaytime(info, rect.x, y2, rect.width);
  843.     }
  844. };
  845.  
  846. })();
Add Comment
Please, Sign In to add comment