11/*
2- Animal Crossing: New Leaf Save Editor v20170203
2+ Animal Crossing: New Leaf Save Editor v20170220
33 by Marc Robledo 2015-2017
44
55 A lot of thanks to:
@@ -489,6 +489,8 @@ Town.prototype.refreshIdSpans=function(){
489489 el ( 'town-id' ) . innerHTML = '0x' + intToHex ( this . townId2 ) + intToHex ( this . townId1 ) ;
490490}
491491Town . prototype . save = function ( ) {
492+ grassPrevious . save ( ) ;
493+
492494 savegame . storeByte ( Offsets . TOWN_NATIVEFRUIT , this . nativeFruit ) ;
493495 savegame . storeByte ( Offsets . TOWN_GRASSTYPE , this . grassType ) ;
494496 savegame . storeByte ( Offsets . ISLAND_GRASSTYPE , this . grassTypeIsland ) ;
@@ -570,51 +572,6 @@ Town.prototype.maxTurnipPrices=function(){
570572 } )
571573}
572574
573- Town . prototype . setGrass = function ( b ) {
574- var MAX_CURRENT = ( 16 * 16 ) * ( 5 * 4 ) ;
575- for ( var i = 0 ; i < MAX_CURRENT ; i ++ ) {
576- grassCurrent . tiles [ i ] = b & 0x0f ;
577- savegame . storeByte ( Offsets . MAP_GRASS_CURRENT + i , grassCurrent . tiles [ i ] ) ;
578- }
579- grassCurrent . draw ( ) ;
580-
581- var MAX = ( 8 * 8 ) * ( 8 * 6 ) * 4 ;
582- for ( var i = 0 ; i < MAX ; i ++ ) {
583- grassPrevious . tiles [ i ] = ~ b & 0xff ;
584- savegame . storeByte ( Offsets . MAP_GRASS_PREVIOUS + i , grassPrevious . tiles [ i ] ) ;
585- }
586- grassPrevious . draw ( ) ;
587-
588-
589- MarcDialogs . close ( ) ;
590- }
591- Town . prototype . fillGrass = function ( ) { MarcDialogs . confirm ( 'Do you want to revive all grass?' , function ( ) { town . setGrass ( 0x00 ) } ) } ;
592- Town . prototype . fillDesert = function ( ) { MarcDialogs . confirm ( 'Do you want to kill all grass?' , function ( ) { town . setGrass ( 0xff ) } ) } ;
593- Town . prototype . fillStrippedGrass = function ( ) {
594- MarcDialogs . confirm ( 'Do you want to strip all grass?' , function ( ) {
595- var MAX_CURRENT = ( 16 * 16 ) * ( 5 * 4 ) ;
596- for ( var i = 0 ; i < MAX_CURRENT / 2 ; i ++ ) {
597- grassCurrent . tiles [ i * 2 + 0 ] = 0x00 ;
598- grassCurrent . tiles [ i * 2 + 1 ] = 0x0f ;
599- savegame . storeByte ( Offsets . MAP_GRASS_CURRENT + i * 2 + 0 , grassCurrent . tiles [ i * 2 + 0 ] ) ;
600- savegame . storeByte ( Offsets . MAP_GRASS_CURRENT + i * 2 + 1 , grassCurrent . tiles [ i * 2 + 1 ] ) ;
601- }
602- grassCurrent . draw ( ) ;
603-
604- var MAX = ( ( 16 * 16 ) * ( 5 * 4 ) ) * 2 ;
605- for ( var i = 0 ; i < MAX ; i ++ ) {
606- var b ;
607- if ( i % 2 == 0 ) {
608- b = 0x00 ;
609- } else {
610- b = 0xff ;
611- }
612- savegame . storeByte ( Offsets . MAP_GRASS_PREVIOUS + i , b )
613- }
614-
615- MarcDialogs . close ( ) ;
616- } ) ;
617- }
618575
619576
620577
@@ -958,24 +915,79 @@ GrassMapCurrent.prototype.save=function(){
958915}
959916
960917
918+
919+
920+
921+
922+
923+
924+ function mouseDownGrass ( evt , grassMap ) {
925+ if ( evt . which == 3 )
926+ mouseHeld = 2 ;
927+ else if ( evt . which == 1 )
928+ mouseHeld = 1 ;
929+ else mouseHeld = 0 ;
930+
931+ clickGrass ( evt , grassMap , true ) ;
932+ }
933+
934+ function clickGrass ( evt , grassMap , firstClick ) {
935+ var rect = grassMap . canvas . getBoundingClientRect ( ) ;
936+ var x = parseInt ( ( evt . clientX - rect . left ) / grassMap . _TILE_SIZE ) ;
937+ var y = parseInt ( ( evt . clientY - rect . top ) / grassMap . _TILE_SIZE ) ;
938+ if ( parseInt ( evt . clientX - rect . left ) > grassMap . canvas . width || parseInt ( evt . clientY - rect . top ) > grassMap . canvas . height )
939+ return false ;
940+
941+ var tile = y * grassMap . width + x ;
942+ if ( currentEditingItem === tile && mouseHeld && ! firstClick )
943+ return false ;
944+ currentEditingItem = tile ;
945+
946+ if ( mouseHeld == 1 ) {
947+ grassMap . alterSingle ( x , y , 64 ) ;
948+ grassMap . alterSingle ( x - 1 , y - 1 , 64 ) ;
949+ grassMap . alterSingle ( x - 1 , y , 64 ) ;
950+ grassMap . alterSingle ( x - 1 , y + 1 , 64 ) ;
951+ grassMap . alterSingle ( x , y - 1 , 64 ) ;
952+ grassMap . alterSingle ( x , y + 1 , 64 ) ;
953+ grassMap . alterSingle ( x + 1 , y - 1 , 64 ) ;
954+ grassMap . alterSingle ( x + 1 , y , 64 ) ;
955+ grassMap . alterSingle ( x + 1 , y + 1 , 64 ) ;
956+ grassMap . draw ( ) ;
957+ } else if ( mouseHeld == 2 ) {
958+ grassMap . alterSingle ( x , y , - 128 ) ;
959+ grassMap . alterSingle ( x - 1 , y - 1 , - 128 ) ;
960+ grassMap . alterSingle ( x - 1 , y , - 128 ) ;
961+ grassMap . alterSingle ( x - 1 , y + 1 , - 128 ) ;
962+ grassMap . alterSingle ( x , y - 1 , - 128 ) ;
963+ grassMap . alterSingle ( x , y + 1 , - 128 ) ;
964+ grassMap . alterSingle ( x + 1 , y - 1 , - 128 ) ;
965+ grassMap . alterSingle ( x + 1 , y , - 128 ) ;
966+ grassMap . alterSingle ( x + 1 , y + 1 , - 128 ) ;
967+ grassMap . draw ( ) ;
968+ }
969+ }
970+ function addGrassMapEvents ( grassMap ) {
971+ addEvent ( grassMap . canvas , 'click' , prevent ) ;
972+ addEvent ( grassMap . canvas , 'mousedown' , function ( evt ) { mouseDownGrass ( evt , grassMap ) } ) ;
973+ addEvent ( grassMap . canvas , 'mouseup' , mouseUp ) ;
974+ addEvent ( grassMap . canvas , 'mousemove' , function ( evt ) { clickGrass ( evt , grassMap , false ) } ) ;
975+ }
961976function GrassMapPrevious ( offset , canvasId , width , height ) {
962977 this . offset = offset ;
963978 this . canvas = el ( canvasId ) ;
964979 this . width = width ;
965980 this . height = height ;
981+ this . _TILE_SIZE = 3 ;
966982
967- this . canvas . width = this . width * 16 ;
968- this . canvas . height = this . height * 16 ;
983+ this . canvas . width = this . width * 16 * this . _TILE_SIZE ;
984+ this . canvas . height = this . height * 16 * this . _TILE_SIZE ;
969985
970- this . tiles = new Array ( width * height * 16 * 16 ) ;
971- for ( var i = 0 ; i < this . tiles . length ; i ++ )
972- this . tiles [ i ] = savegame . readByte1 ( this . offset + i ) ;
973986
974- this . draw ( ) ;
975- }
976- GrassMapPrevious . prototype . draw = function ( ) {
987+ addGrassMapEvents ( this ) ;
988+
989+ this . _offsets = [ ] ;
977990 var tile = 0 ;
978- var ctx = this . canvas . getContext ( '2d' ) ;
979991 for ( var i = 0 ; i < this . height * 2 ; i ++ ) {
980992 for ( var j = 0 ; j < this . width * 2 ; j ++ ) {
981993 for ( var y4 = 0 ; y4 < 2 ; y4 ++ ) {
@@ -984,10 +996,7 @@ GrassMapPrevious.prototype.draw=function(){
984996 for ( var x2 = 0 ; x2 < 2 ; x2 ++ ) {
985997 for ( var y1 = 0 ; y1 < 2 ; y1 ++ ) {
986998 for ( var x1 = 0 ; x1 < 2 ; x1 ++ ) {
987- var color = this . tiles [ tile ] ;
988- ctx . fillStyle = 'rgba(' + color + ',' + color + ',' + color + ',1)' ;
989- ctx . fillRect ( ( j * 8 + x4 * 4 + x2 * 2 + x1 ) , ( i * 8 + y4 * 4 + y2 * 2 + y1 ) , 1 , 1 ) ;
990-
999+ this . _offsets [ ( i * 8 + y4 * 4 + y2 * 2 + y1 ) * this . width * 16 + ( j * 8 + x4 * 4 + x2 * 2 + x1 ) ] = tile ;
9911000 tile ++ ;
9921001 }
9931002 }
@@ -997,8 +1006,51 @@ GrassMapPrevious.prototype.draw=function(){
9971006 }
9981007 }
9991008 }
1009+
1010+ this . tiles = new Array ( width * height * 16 * 16 ) ;
1011+ for ( var i = 0 ; i < this . tiles . length ; i ++ )
1012+ this . tiles [ i ] = savegame . readByte1 ( this . offset + i ) ;
1013+
1014+ this . draw ( ) ;
10001015}
1016+ GrassMapPrevious . prototype . draw = function ( ) {
1017+ var ctx = this . canvas . getContext ( '2d' ) ;
1018+
1019+ ctx . fillStyle = '#ebe399' ;
1020+ ctx . fillRect ( 0 , 0 , this . canvas . width , this . canvas . height ) ;
10011021
1022+ var width = this . width * 16 ;
1023+ var height = this . height * 16 ;
1024+ for ( var x = 0 ; x < width ; x ++ ) {
1025+ for ( var y = 0 ; y < height ; y ++ ) {
1026+ ctx . fillStyle = 'rgba(115,189,74,+' + ( this . tiles [ this . _offsets [ y * width + x ] ] / 255 ) + ')' ;
1027+ ctx . fillRect ( x * this . _TILE_SIZE , y * this . _TILE_SIZE , this . _TILE_SIZE , this . _TILE_SIZE ) ;
1028+ }
1029+ }
1030+ }
1031+ GrassMapPrevious . prototype . alterAll = function ( v ) {
1032+ for ( var i = 0 ; i < this . tiles . length ; i ++ ) {
1033+ this . tiles [ i ] += v ;
1034+ if ( this . tiles [ i ] > 255 )
1035+ this . tiles [ i ] = 255 ;
1036+ else if ( this . tiles [ i ] < 0 )
1037+ this . tiles [ i ] = 0 ;
1038+ }
1039+ this . draw ( ) ;
1040+ }
1041+ GrassMapPrevious . prototype . alterSingle = function ( x , y , v ) {
1042+ var width = this . width * 16 ;
1043+ var t = this . _offsets [ y * width + x ] ;
1044+ this . tiles [ t ] += v ;
1045+ if ( this . tiles [ t ] > 255 )
1046+ this . tiles [ t ] = 255 ;
1047+ else if ( this . tiles [ t ] < 0 )
1048+ this . tiles [ t ] = 0 ;
1049+ }
1050+ GrassMapPrevious . prototype . save = function ( ) {
1051+ for ( var i = 0 ; i < this . tiles . length ; i ++ )
1052+ savegame . storeByte ( this . offset + i , this . tiles [ i ] ) ;
1053+ }
10021054
10031055
10041056
@@ -3053,7 +3105,7 @@ function initializeEverything(){
30533105 }
30543106
30553107 addEvent ( window , 'contextmenu' , prevent ) ;
3056- addEvent ( window , 'mouseup' , function ( ) { mouseHeld = 0 } ) ;
3108+ addEvent ( window , 'mouseup' , mouseUp ) ;
30573109
30583110 moveBuildingOverlay = document . createElement ( 'div' ) ;
30593111 moveBuildingOverlay . id = 'move-building-overlay' ;
0 commit comments