2022-10-07 17:34:13 -04:00
elements . on _try _move _into _test = {
color : "#ffffff" ,
properties : {
ticks : 0 ,
attemptedMovesIntoPixel : 0 ,
} ,
behavior : behaviors . POWDER ,
reactions : {
"dirt" : { elem1 : "diamond" } ,
} ,
state : "solid" ,
2023-08-15 22:54:02 -04:00
hidden : true ,
excludeRandom : true ,
2022-10-07 17:34:13 -04:00
category : "special" ,
density : 1000 ,
tick : function ( pixel ) {
pixel . ticks ++ ;
} ,
onTryMoveInto : function ( pixel , otherPixel ) {
pixel . attemptedMovesIntoPixel ++ ;
var otherElement = otherPixel . element ;
if ( otherElement === "ash" ) {
console . log ( ` This is a test of potentially undesired multiplicate running. (tick: ${ pixelTicks } , move attempts: ${ pixel . attemptedMovesIntoPixel } ) ` ) ;
//if(deletePixel(pixel.x,pixel.y)) {
// console.log("This pixel has been deleted.");
//};
} ;
} ,
desc : " Try burying this pixel and see what happens . ( Use Debug ) \ n \ nonTryMoveInto is run as part of tryMove , < em > before reactions < / e m > , w h i l e t i c k f u n c t i o n s a r e r u n a s p a r t o f p i x e l D r a w . \ n < s p a n s t y l e = ' c o l o r : r e d ; ' > I n s o m e c i r c u m s t a n c e s , s u c h a s a p i x e l b e i n g b u r i e d u n d e r a p i l e o f a n y t h i n g t h a t i s n ' t a s t u r d y p o w d e r , t h i s f u n c t i o n m a y r u n m u l t i p l e t i m e s p e r t i c k . < / s p a n > F o r e x a m p l e , b u r y t h i s p i x e l i n a s h a n d l o o k i n t h e c o n s o l e . \ n \ n T o u s e t h i s f u n c t i o n , i n c l u d e i n y o u r e l e m e n t d e f i n i t i o n t h e \ " o n T r y M o v e I n t o \ " k e y w i t h a f u n c t i o n v a l u e , s i m i l a r l y t o t i c k f u n c t i o n s . T h i s f u n c t i o n t a k e s t w o a r g u m e n t s ; \ " o t h e r P i x e l \ " i s t h e p i x e l t h a t i s t r y i n g t o m o v e a n d \ " p i x e l \ " i s t h e p i x e l w h o s e p o s i t i o n o t h e r P i x e l i s t r y i n g t o m o v e i n t o . " ,
related : [ "debug" , "ash" ] ,
}
2023-08-01 21:45:34 -04:00
function tryMove ( pixel , nx , ny , leaveBehind , force ) {
if ( pixel . drag && ! force ) { return true ; }
2022-10-07 17:34:13 -04:00
var info = elements [ pixel . element ] ;
var oob = outOfBounds ( nx , ny ) ;
if ( isEmpty ( nx , ny , false , oob ) ) { // If coords is empty, move to coords
2023-03-08 17:03:42 -05:00
//console.log(`Moving ${pixel.element} (${pixel.x},${pixel.y}) to (${nx},${ny})`);
2022-10-07 17:34:13 -04:00
movePixel ( pixel , nx , ny , leaveBehind ) ;
return true ;
}
else if ( ! oob ) {
2023-03-08 17:03:42 -05:00
//console.log(`Moving ${pixel.element} (${pixel.x},${pixel.y}) to (${nx},${ny})`);
2022-10-07 17:34:13 -04:00
// Reactions
newPixel = pixelMap [ nx ] [ ny ] ;
var newInfo = elements [ newPixel . element ] ;
2023-08-15 22:54:02 -04:00
var returnVal = false ;
2022-10-07 17:34:13 -04:00
if ( newInfo . onTryMoveInto !== undefined ) {
newInfo . onTryMoveInto ( newPixel , pixel ) ;
2023-03-08 17:03:42 -05:00
if ( ! pixel || pixel . del ) {
return "deleted" ;
} ;
2023-08-15 22:54:02 -04:00
returnVal = true ;
2022-10-07 17:34:13 -04:00
}
var rr1 = false ;
if ( info . reactions !== undefined && info . reactions [ newPixel . element ] !== undefined ) {
rr1 = reactPixels ( pixel , newPixel )
if ( rr1 ) {
return true ;
}
}
if ( ! rr1 && elements [ newPixel . element ] . reactions !== undefined && elements [ newPixel . element ] . reactions [ pixel . element ] !== undefined && ! elements [ newPixel . element ] . reactions [ pixel . element ] . oneway ) {
if ( reactPixels ( newPixel , pixel ) ) {
return true ;
}
}
// Density
if ( elements [ pixel . element ] . id !== elements [ newPixel . element ] . id ) {
if ( info . density !== undefined && elements [ newPixel . element ] . density !== undefined ) {
// if the pixel's state + ">" + newPixel's state is in validDensitySwaps, and the pixel's density is larger than the newPixel's density, swap the pixels
if ( validDensitySwaps [ info . state ] [ elements [ newPixel . element ] . state ] && info . density >= elements [ newPixel . element ] . density ) {
// chance depending on the difference in density
if ( Math . random ( ) < ( info . density - elements [ newPixel . element ] . density ) / ( info . density + elements [ newPixel . element ] . density ) ) {
swapPixels ( pixel , newPixel ) ;
return true ;
}
}
}
}
2023-08-15 22:54:02 -04:00
if ( returnVal ) {
return true ;
}
2022-10-07 17:34:13 -04:00
}
return false ;
}