idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
3,500
private Transform getTransform ( ) { final Resolution output = config . getOutput ( ) ; final double scaleX = output . getWidth ( ) / ( double ) source . getWidth ( ) ; final double scaleY = output . getHeight ( ) / ( double ) source . getHeight ( ) ; return filter . getTransform ( scaleX , scaleY ) ; }
Get the transform associated to the filter keeping screen scale independent .
3,501
void render ( ) { if ( screen . isReady ( ) ) { final Graphic g = screen . getGraphic ( ) ; if ( buf == null ) { target . render ( g ) ; } else { target . render ( graphic ) ; g . drawImage ( filter . filter ( buf ) , transform , 0 , 0 ) ; } } }
Local render routine .
3,502
private static String formatResolution ( Resolution resolution , int depth ) { return new StringBuilder ( MIN_LENGTH ) . append ( String . valueOf ( resolution . getWidth ( ) ) ) . append ( Constant . STAR ) . append ( String . valueOf ( resolution . getHeight ( ) ) ) . append ( Constant . STAR ) . append ( depth ) . a...
Format resolution to string .
3,503
private void initFullscreen ( Resolution output , int depth ) { final java . awt . Window window = new java . awt . Window ( frame , conf ) ; window . setBackground ( Color . BLACK ) ; window . setIgnoreRepaint ( true ) ; window . setPreferredSize ( new Dimension ( output . getWidth ( ) , output . getHeight ( ) ) ) ; d...
Prepare fullscreen mode .
3,504
private String getSupportedResolutions ( ) { final StringBuilder builder = new StringBuilder ( Constant . HUNDRED ) ; int i = 0 ; for ( final DisplayMode display : dev . getDisplayModes ( ) ) { final StringBuilder widthSpace = new StringBuilder ( ) ; final int width = display . getWidth ( ) ; if ( width < Constant . TH...
Get the supported resolution information .
3,505
private DisplayMode isSupported ( DisplayMode display ) { final DisplayMode [ ] supported = dev . getDisplayModes ( ) ; for ( final DisplayMode current : supported ) { final boolean multiDepth = current . getBitDepth ( ) != DisplayMode . BIT_DEPTH_MULTI && display . equals ( current ) ; if ( multiDepth || current . get...
Check if the display mode is supported .
3,506
private static String getTempDir ( Class < ? > loader ) { final File temp = new File ( TEMP , loader . getSimpleName ( ) ) ; final String path = temp . getAbsolutePath ( ) ; if ( ! temp . isDirectory ( ) && ! temp . mkdir ( ) ) { Verbose . warning ( ERROR_CREATE_TEMP_DIR , path ) ; } return path ; }
Create the temp directory relative to loader class name .
3,507
private String getPrefix ( ) { final String prefix ; if ( loader . isPresent ( ) ) { prefix = loader . get ( ) . getPackage ( ) . getName ( ) . replace ( Constant . DOT , File . separator ) ; } else { prefix = resourcesDir ; } return prefix ; }
Get the resources prefix .
3,508
private Media create ( String prefix , int prefixLength , File file ) { final String currentPath = file . getPath ( ) ; final String [ ] systemPath = SLASH . split ( currentPath . substring ( currentPath . indexOf ( prefix ) + prefixLength ) . replace ( File . separator , Constant . SLASH ) ) ; final Media media ; if (...
Create media from file .
3,509
private InputStream getInputFromJarOrTemp ( ) throws FileNotFoundException { final InputStream input = loader . get ( ) . getResourceAsStream ( UtilFolder . getPathSeparator ( separator , getPath ( ) ) ) ; if ( input == null ) { return new FileInputStream ( getPathTemp ( ) ) ; } return input ; }
Get input stream from JAR by default try in temporary folder if not found in JAR .
3,510
private String getPathTemp ( ) { return UtilFolder . getPathSeparator ( File . separator , getTempDir ( loader . get ( ) ) , path . replace ( separator , File . separator ) ) ; }
Get the temporary path equivalent .
3,511
public static synchronized void addFormat ( AudioFormat format ) { Check . notNull ( format ) ; for ( final String current : format . getFormats ( ) ) { if ( FACTORIES . put ( current , format ) != null ) { throw new LionEngineException ( ERROR_EXISTS + current ) ; } } }
Add a supported audio format .
3,512
public static void copy ( InputStream source , OutputStream destination ) throws IOException { Check . notNull ( source ) ; Check . notNull ( destination ) ; final byte [ ] buffer = new byte [ BUFFER_COPY ] ; while ( true ) { final int read = source . read ( buffer ) ; if ( read == - 1 ) { break ; } destination . write...
Copy a stream onto another .
3,513
public static File getCopy ( String name , InputStream input ) { Check . notNull ( name ) ; Check . notNull ( input ) ; final String prefix ; final String suffix ; final int minimumPrefix = 3 ; final int i = name . lastIndexOf ( Constant . DOT ) ; if ( i > minimumPrefix ) { prefix = name . substring ( 0 , i ) ; suffix ...
Get of full copy of the input stream stored in a temporary file .
3,514
void robotPress ( int click ) { lastClick = click ; if ( lastClick < clicks . length ) { clicks [ lastClick ] = true ; } }
Robot click mouse .
3,515
void robotRelease ( int click ) { lastClick = 0 ; final int button = click ; if ( button < clicks . length ) { clicks [ button ] = false ; clicked [ button ] = false ; } }
Robot release mouse .
3,516
void addActionReleased ( int click , EventAction action ) { final Integer key = Integer . valueOf ( click ) ; final List < EventAction > list ; if ( actionsReleased . get ( key ) == null ) { list = new ArrayList < > ( ) ; actionsReleased . put ( key , list ) ; } else { list = actionsReleased . get ( key ) ; } list . ad...
Add a released action .
3,517
boolean hasClickedOnce ( int click ) { if ( click < clicks . length && clicks [ click ] && ! clicked [ click ] ) { clicked [ click ] = true ; return true ; } return false ; }
Check if click is clicked once .
3,518
private static Transition getTransitionSingleGroup ( Collection < String > groups ) { final Iterator < String > iterator = groups . iterator ( ) ; final String group = iterator . next ( ) ; return new Transition ( TransitionType . CENTER , group , group ) ; }
Get the tile transition with one group only .
3,519
private static Transition getTransitionTwoGroups ( Collection < String > neighborGroups ) { final Iterator < String > iterator = new HashSet < > ( neighborGroups ) . iterator ( ) ; final String groupIn = iterator . next ( ) ; final String groupOut = iterator . next ( ) ; final TransitionType type = getTransitionType ( ...
Get the tile transition between two groups .
3,520
private static TransitionType getTransitionType ( String groupIn , Collection < String > neighborGroups ) { final boolean [ ] bits = new boolean [ TransitionType . BITS ] ; int i = 0 ; for ( final String neighborGroup : neighborGroups ) { bits [ i ] = ! groupIn . equals ( neighborGroup ) ; i ++ ; } return TransitionTyp...
Get the transition type from one group to another .
3,521
public Transition getTransition ( Tile tile ) { final Collection < String > neighborGroups = getNeighborGroups ( tile ) ; final Collection < String > groups = new HashSet < > ( neighborGroups ) ; final Transition transition ; if ( groups . size ( ) == 1 && mapGroup . getGroup ( tile ) . equals ( groups . iterator ( ) ....
Get the tile transition .
3,522
private Collection < String > getNeighborGroups ( Tile tile ) { final Collection < String > neighborGroups = new ArrayList < > ( TransitionType . BITS ) ; addNeighborGroup ( neighborGroups , tile , 1 , - 1 ) ; addNeighborGroup ( neighborGroups , tile , - 1 , - 1 ) ; addNeighborGroup ( neighborGroups , tile , 1 , 1 ) ; ...
Get the direct neighbor angle groups .
3,523
private void addNeighborGroup ( Collection < String > neighborGroups , Tile tile , int ox , int oy ) { final Tile neighbor = map . getTile ( tile . getInTileX ( ) + ox , tile . getInTileY ( ) + oy ) ; if ( neighbor != null ) { final String neighborGroup = getNeighborGroup ( tile , neighbor ) ; if ( neighborGroup != nul...
Add the neighbor group if exists .
3,524
private String getNeighborGroup ( Tile tile , Tile neighbor ) { final String neighborGroup ; if ( isTransition ( neighbor ) ) { if ( isTransition ( tile ) ) { neighborGroup = getOtherGroup ( tile , neighbor ) ; } else { neighborGroup = null ; } } else { neighborGroup = mapGroup . getGroup ( neighbor ) ; } return neighb...
Get the neighbor group depending if it is a transition tile .
3,525
private String getOtherGroup ( Tile tile , Tile neighbor ) { final String group = mapGroup . getGroup ( tile ) ; for ( final Tile shared : getSharedNeigbors ( tile , neighbor ) ) { final String sharedNeighborGroup = mapGroup . getGroup ( shared ) ; if ( ! group . equals ( sharedNeighborGroup ) && ! isTransition ( share...
Get the other transition group excluding the current group and transition itself .
3,526
private Collection < Tile > getSharedNeigbors ( Tile tile1 , Tile tile2 ) { final Collection < Tile > neighbors1 = map . getNeighbors ( tile1 ) ; final Collection < Tile > neighbors2 = map . getNeighbors ( tile2 ) ; final Collection < Tile > sharedNeighbors = new HashSet < > ( 2 ) ; for ( final Tile neighbor : neighbor...
Get the neighbors in commons between two tiles .
3,527
private static Robot createRobot ( ) { try { return new Robot ( ) ; } catch ( final AWTException exception ) { Verbose . exception ( exception , ERROR_ROBOT ) ; return null ; } }
Create a mouse robot .
3,528
public void setResolution ( Resolution output , Resolution source ) { Check . notNull ( output ) ; Check . notNull ( source ) ; xRatio = output . getWidth ( ) / ( double ) source . getWidth ( ) ; yRatio = output . getHeight ( ) / ( double ) source . getHeight ( ) ; }
Set the resolution used . This will compute mouse horizontal and vertical ratio .
3,529
public Sprite getRaster ( int id ) { return rasters . get ( UtilMath . clamp ( id , 0 , rasters . size ( ) - 1 ) ) ; }
Get raster surface from its id .
3,530
private void updateAdd ( ) { if ( willAdd ) { for ( final Featurable featurable : toAdd ) { featurables . add ( featurable ) ; for ( final HandlerListener listener : listeners ) { listener . notifyHandlableAdded ( featurable ) ; } if ( featurable . hasFeature ( Transformable . class ) ) { final Transformable transforma...
Update the add list . Prepare features add to main list and notify listeners .
3,531
private void updateRemove ( ) { if ( willDelete ) { for ( final Integer id : toDelete ) { final Featurable featurable = featurables . get ( id ) ; for ( final HandlerListener listener : listeners ) { listener . notifyHandlableRemoved ( featurable ) ; } featurable . getFeature ( Identifiable . class ) . notifyDestroyed ...
Update the remove list . Remove from main list and notify listeners . Notify featurable destroyed .
3,532
private static Integer getFreeId ( ) { if ( ! RECYCLE . isEmpty ( ) ) { final Integer id = RECYCLE . poll ( ) ; IDS . add ( id ) ; return id ; } if ( IDS . size ( ) == Integer . MAX_VALUE ) { throw new LionEngineException ( ERROR_FREE_ID ) ; } Integer id ; while ( IDS . contains ( id = Integer . valueOf ( lastId ) ) ) ...
Get the next unused ID .
3,533
public void addMessage ( String message , int x , int y , long time ) { messages . add ( new MessageData ( message , x , y , time ) ) ; hasMessage = true ; }
Add a timed message .
3,534
private static String extractFromJar ( Media media ) { try ( InputStream input = media . getInputStream ( ) ) { final File file = UtilStream . getCopy ( media . getFile ( ) . getName ( ) , input ) ; return file . getAbsolutePath ( ) ; } catch ( final IOException exception ) { throw new LionEngineException ( exception )...
Extract music from jar to temp file .
3,535
private void play ( String track , String name ) { Verbose . info ( INFO_PLAYING , name ) ; play ( track ) ; }
Play the track .
3,536
private void updateAttackCheck ( ) { attacking = false ; attacked = false ; if ( target == null ) { state = AttackState . NONE ; } else { final double dist = UtilMath . getDistance ( transformable . getX ( ) , transformable . getY ( ) , transformable . getWidth ( ) , transformable . getHeight ( ) , target . getX ( ) , ...
Update the attack check case .
3,537
private void checkTargetDistance ( double dist ) { if ( distAttack . includes ( dist ) ) { if ( checker . canAttack ( ) ) { state = AttackState . ATTACKING ; } } else if ( tick . elapsed ( attackPause ) ) { for ( final AttackerListener listener : listeners ) { listener . notifyReachingTarget ( target ) ; } } }
Check the target distance and update the attack state .
3,538
private void updateAttacking ( ) { if ( tick . elapsed ( attackPause ) ) { updateAttackHit ( ) ; } else if ( attacked ) { if ( AnimState . FINISHED == animator . getAnimState ( ) ) { for ( final AttackerListener listener : listeners ) { listener . notifyAttackAnimEnded ( ) ; } attacked = false ; state = AttackState . C...
Update the attacking case .
3,539
private void updateAttackHit ( ) { if ( ! attacking ) { for ( final AttackerListener listener : listeners ) { listener . notifyAttackStarted ( target ) ; } attacking = true ; attacked = false ; } if ( animator . getFrame ( ) >= frameAttack ) { attacking = false ; for ( final AttackerListener listener : listeners ) { li...
Update the attack state and hit when possible .
3,540
public static int getRandomInteger ( Range range ) { Check . notNull ( range ) ; return getRandomInteger ( range . getMin ( ) , range . getMax ( ) ) ; }
Get a random value from range .
3,541
public static int getRandomInteger ( int min , int max ) { Check . inferiorOrEqual ( min , max ) ; return min + RANDOM . nextInt ( max + 1 - min ) ; }
Get a random value from an interval .
3,542
public static ImageBuffer createFunctionDraw ( CollisionFormula collision , int tw , int th ) { final ImageBuffer buffer = Graphics . createImageBuffer ( tw , th , ColorRgba . TRANSPARENT ) ; final Graphic g = buffer . createGraphic ( ) ; g . setColor ( ColorRgba . PURPLE ) ; createFunctionDraw ( g , collision , tw , t...
Create the function draw to buffer .
3,543
private static void createFunctionDraw ( Graphic g , CollisionFormula formula , int tw , int th ) { for ( int x = 0 ; x < tw ; x ++ ) { for ( int y = 0 ; y < th ; y ++ ) { renderCollision ( g , formula , th , x , y ) ; } } }
Create the function draw to buffer by computing all possible locations .
3,544
private static void renderCollision ( Graphic g , CollisionFormula formula , int th , int x , int y ) { final CollisionFunction function = formula . getFunction ( ) ; final CollisionRange range = formula . getRange ( ) ; switch ( range . getOutput ( ) ) { case X : renderX ( g , function , range , th , y ) ; break ; cas...
Render collision from current vector .
3,545
private static void renderX ( Graphic g , CollisionFunction function , CollisionRange range , int th , int y ) { if ( UtilMath . isBetween ( y , range . getMinY ( ) , range . getMaxY ( ) ) ) { g . drawRect ( function . getRenderX ( y ) , th - y - 1 , 0 , 0 , false ) ; } }
Render horizontal collision from current vector .
3,546
private static void renderY ( Graphic g , CollisionFunction function , CollisionRange range , int th , int x ) { if ( UtilMath . isBetween ( x , range . getMinX ( ) , range . getMaxX ( ) ) ) { g . drawRect ( x , th - function . getRenderY ( x ) - 1 , 0 , 0 , false ) ; } }
Render vertical collision from current vector .
3,547
private void renderCollision ( Graphic g , TileCollision tile , int x , int y ) { for ( final CollisionFormula collision : tile . getCollisionFormulas ( ) ) { final ImageBuffer buffer = collisionCache . get ( collision ) ; if ( buffer != null ) { g . drawImage ( buffer , x , y ) ; } } }
Render the collision function .
3,548
public final void setScreenSize ( int width , int height ) { screenWidth = width ; screenHeight = height ; final double scaleH = width / ( double ) Scene . NATIVE . getWidth ( ) ; final double scaleV = height / ( double ) Scene . NATIVE . getHeight ( ) ; this . scaleH = scaleH ; this . scaleV = scaleV ; primary . updat...
Called when the resolution changed .
3,549
public static List < LauncherConfig > imports ( Configurer configurer ) { Check . notNull ( configurer ) ; final Collection < Xml > children = configurer . getRoot ( ) . getChildren ( NODE_LAUNCHER ) ; final List < LauncherConfig > launchers = new ArrayList < > ( children . size ( ) ) ; for ( final Xml launcher : child...
Import the launcher data from configurer .
3,550
public static LauncherConfig imports ( Xml node ) { Check . notNull ( node ) ; final Collection < Xml > children = node . getChildren ( LaunchableConfig . NODE_LAUNCHABLE ) ; final Collection < LaunchableConfig > launchables = new ArrayList < > ( children . size ( ) ) ; for ( final Xml launchable : children ) { launcha...
Import the launcher data from node .
3,551
public static Xml exports ( LauncherConfig config ) { Check . notNull ( config ) ; final Xml node = new Xml ( NODE_LAUNCHER ) ; node . writeInteger ( ATT_RATE , config . getRate ( ) ) ; for ( final LaunchableConfig launchable : config . getLaunchables ( ) ) { node . add ( LaunchableConfig . exports ( launchable ) ) ; }...
Export the launcher node from config .
3,552
public static CollisionRange imports ( XmlReader node ) { Check . notNull ( node ) ; final String axisName = node . readString ( ATT_AXIS ) ; try { final Axis axis = Axis . valueOf ( axisName ) ; final int minX = node . readInteger ( ATT_MIN_X ) ; final int maxX = node . readInteger ( ATT_MAX_X ) ; final int minY = nod...
Create the collision range data from a node .
3,553
public static void exports ( Xml root , CollisionRange range ) { Check . notNull ( root ) ; Check . notNull ( range ) ; final Xml node = root . createChild ( NODE_RANGE ) ; node . writeString ( ATT_AXIS , range . getOutput ( ) . name ( ) ) ; node . writeInteger ( ATT_MIN_X , range . getMinX ( ) ) ; node . writeInteger ...
Export the collision range as a node .
3,554
private void computeFrameRate ( Timing updateFpsTimer , long lastTime , long currentTime ) { if ( updateFpsTimer . elapsed ( Constant . ONE_SECOND_IN_MILLI ) ) { currentFrameRate = ( int ) Math . round ( Constant . ONE_SECOND_IN_NANO / ( double ) ( currentTime - lastTime ) ) ; updateFpsTimer . restart ( ) ; } }
Compute the frame rate depending of the game loop speed .
3,555
protected final void render ( Graphic g , int x , int y , int w , int h , int ox , int oy ) { if ( Mirror . HORIZONTAL == mirror ) { g . drawImage ( surface , x , y , x + w , y + h , ox * w + w , oy * h , ox * w , oy * h + h ) ; } else if ( Mirror . VERTICAL == mirror ) { g . drawImage ( surface , x , y , x + w , y + h...
Render an extract of a surface to a specified destination .
3,556
protected void stretch ( int newWidth , int newHeight ) { width = newWidth ; height = newHeight ; surface = Graphics . resize ( surfaceOriginal , newWidth , newHeight ) ; }
Stretch the surface with the specified new size .
3,557
private boolean isTileNotAvailable ( Pathfindable mover , int ctx , int cty , Integer ignoreObjectId ) { final Collection < Integer > ids = getObjectsId ( ctx , cty ) ; final Tile tile = map . getTile ( ctx , cty ) ; if ( tile != null ) { final TilePath tilePath = tile . getFeature ( TilePath . class ) ; if ( mover . i...
Check if area if used .
3,558
private boolean isBlocked ( Pathfindable mover , int tx , int ty ) { final Collection < Integer > ids = getObjectsId ( tx , ty ) ; int ignoredCount = 0 ; for ( final Integer id : ids ) { if ( mover . isIgnoredId ( id ) ) { ignoredCount ++ ; } } return ignoredCount < ids . size ( ) ; }
Check if all objects id are non blocking .
3,559
private boolean isTileBlocked ( Pathfindable mover , int tx , int ty ) { final Tile tile = map . getTile ( tx , ty ) ; if ( tile != null ) { final TilePath tilePath = tile . getFeature ( TilePath . class ) ; return mover . isBlocking ( tilePath . getCategory ( ) ) ; } return false ; }
Check if tile is blocking .
3,560
private CoordTile getClosestAvailableTile ( Pathfindable mover , int stx , int sty , int stw , int sth , int dtx , int dty , int dtw , int dth , int radius ) { int closestX = 0 ; int closestY = 0 ; double dist = Double . MAX_VALUE ; int size = 1 ; boolean found = false ; while ( ! found ) { for ( int tx = stx - size ; ...
Get the closest unused location around the area . The returned tile is not blocking nor used by an object .
3,561
private CoordTile getFreeTileAround ( Pathfindable mover , int tx , int ty , int tw , int th , int radius , Integer id ) { for ( int ctx = tx - radius ; ctx <= tx + radius ; ctx ++ ) { for ( int cty = ty - radius ; cty <= ty + radius ; cty ++ ) { if ( isAreaAvailable ( mover , ctx , cty , tw , th , id ) ) { return new ...
Search a free area from this location .
3,562
private String getCategory ( String group ) { for ( final PathCategory category : categories . values ( ) ) { if ( category . getGroups ( ) . contains ( group ) ) { return category . getName ( ) ; } } return null ; }
Get the group category .
3,563
public void setLocation ( int x , int y ) { screenX = UtilMath . clamp ( x , minX , maxX ) ; screenY = UtilMath . clamp ( y , minY , maxY ) ; }
Set cursor location .
3,564
public void setArea ( int minX , int minY , int maxX , int maxY ) { this . minX = Math . min ( minX , maxX ) ; this . minY = Math . min ( minY , maxY ) ; this . maxX = Math . max ( maxX , minX ) ; this . maxY = Math . max ( maxY , minY ) ; }
Allows cursor to move only inside the specified area . The cursor location will not exceed this area .
3,565
public void setGrid ( int width , int height ) { Check . superiorStrict ( width , 0 ) ; Check . superiorStrict ( height , 0 ) ; gridWidth = width ; gridHeight = height ; }
Set the grid size .
3,566
private static double getRasterFactor ( int i , RasterData data ) { Check . notNull ( data ) ; final double force = data . getForce ( ) ; final double amplitude = data . getAmplitude ( ) ; final int offset = data . getOffset ( ) ; if ( 0 == data . getType ( ) ) { return force * UtilMath . sin ( i * amplitude + offset )...
Get raster color .
3,567
public void loadRasters ( int imageHeight , boolean save , String prefix ) { Check . notNull ( prefix ) ; final Raster raster = Raster . load ( rasterFile ) ; final int max = UtilConversion . boolToInt ( rasterSmooth ) + 1 ; for ( int m = 0 ; m < max ; m ++ ) { for ( int i = 0 ; i < MAX_RASTERS ; i ++ ) { final String ...
Load rasters .
3,568
public ImageBuffer getRaster ( int id ) { return rasters . get ( UtilMath . clamp ( id , 0 , rasters . size ( ) - 1 ) ) ; }
Get the raster from its ID .
3,569
private ImageBuffer createRaster ( Media rasterMedia , Raster raster , int i , boolean save ) { final ImageBuffer rasterBuffer ; if ( rasterMedia . exists ( ) ) { rasterBuffer = Graphics . getImageBuffer ( rasterMedia ) ; rasterBuffer . prepare ( ) ; } else { final double fr = getRasterFactor ( i , raster . getRed ( ) ...
Create raster from data or load from cache .
3,570
private static boolean hasSync ( Screen screen ) { final Config config = screen . getConfig ( ) ; final Resolution output = config . getOutput ( ) ; return config . isWindowed ( ) && output . getRate ( ) > 0 ; }
Check if screen has sync locked .
3,571
private static int computeE1 ( int a , int b , int c , int d , int e , int f ) { if ( d == b && e != c || b == f && e != a ) { return b ; } return e ; }
Compute E1 pixel .
3,572
private static int computeE3 ( int a , int b , int d , int e , int g , int h ) { if ( d == b && e != g || d == h && e != a ) { return d ; } return e ; }
Compute E3 pixel .
3,573
private static int computeE5 ( int b , int c , int e , int f , int h , int i ) { if ( b == f && e != i || h == f && e != c ) { return f ; } return e ; }
Compute E5 pixel .
3,574
private static int computeE7 ( int d , int e , int f , int g , int h , int i ) { if ( d == h && e != i || h == f && e != g ) { return h ; } return e ; }
Compute E7 pixel .
3,575
public static ActionConfig imports ( Configurer configurer ) { Check . notNull ( configurer ) ; return imports ( configurer . getRoot ( ) ) ; }
Import the action data from setup .
3,576
public static ActionConfig imports ( Xml root ) { Check . notNull ( root ) ; final Xml nodeAction = root . getChild ( NODE_ACTION ) ; final String name = nodeAction . readString ( ATT_NAME ) ; final String description = nodeAction . readString ( ATT_DESCRIPTION ) ; final int x = nodeAction . readInteger ( ATT_X ) ; fin...
Import the action data from node .
3,577
public static Xml exports ( ActionConfig config ) { Check . notNull ( config ) ; final Xml nodeAction = new Xml ( NODE_ACTION ) ; nodeAction . writeString ( ATT_NAME , config . getName ( ) ) ; nodeAction . writeString ( ATT_DESCRIPTION , config . getDescription ( ) ) ; nodeAction . writeInteger ( ATT_X , config . getX ...
Export the action node from data .
3,578
public int setParent ( Node parent ) { if ( parent != null ) { depth = parent . getDepth ( ) + 1 ; } this . parent = parent ; return depth ; }
Set the node parent .
3,579
public final void saveToFile ( Media media ) { try ( FileWriting writing = new FileWriting ( media ) ) { saving ( writing ) ; } catch ( final IOException exception ) { throw new LionEngineException ( exception , media , "Error on saving to file !" ) ; } }
Save world to the specified file .
3,580
public final void loadFromFile ( Media media ) { try ( FileReading reading = new FileReading ( media ) ) { loading ( reading ) ; } catch ( final IOException exception ) { throw new LionEngineException ( exception , media , "Error on loading from file !" ) ; } }
Load world from the specified file .
3,581
public void fill ( Graphic g , ColorRgba color ) { g . setColor ( color ) ; g . drawRect ( 0 , 0 , source . getWidth ( ) , source . getHeight ( ) , true ) ; }
Fill with color .
3,582
public final < T extends InputDevice > T getInputDevice ( Class < T > type ) { return context . getInputDevice ( type ) ; }
Get the input device instance from its type .
3,583
public static LayerableConfig imports ( Configurer configurer ) { Check . notNull ( configurer ) ; return imports ( configurer . getRoot ( ) ) ; }
Imports the layerable config from configurer .
3,584
public static LayerableConfig imports ( Xml root ) { Check . notNull ( root ) ; final Xml node = root . getChild ( NODE_LAYERABLE ) ; final int layerRefresh = node . readInteger ( ATT_REFRESH ) ; final int layerDisplay = node . readInteger ( ATT_DISPLAY ) ; return new LayerableConfig ( layerRefresh , layerDisplay ) ; }
Imports the layerable config from node .
3,585
public static Xml exports ( LayerableConfig config ) { Check . notNull ( config ) ; final Xml node = new Xml ( NODE_LAYERABLE ) ; node . writeInteger ( ATT_REFRESH , config . getLayerRefresh ( ) ) ; node . writeInteger ( ATT_DISPLAY , config . getLayerDisplay ( ) ) ; return node ; }
Exports the layerable node from config .
3,586
protected static int readInt ( InputStream input , int bytesNumber , boolean bigEndian ) throws IOException { final int oneByte = 8 ; int ret = 0 ; int sv ; if ( bigEndian ) { sv = ( bytesNumber - 1 ) * oneByte ; } else { sv = 0 ; } final int cnt ; if ( bigEndian ) { cnt = - oneByte ; } else { cnt = oneByte ; } for ( i...
Read integer in image data .
3,587
protected static void checkSkippedError ( long skipped , int instead ) throws IOException { if ( skipped != instead ) { throw new IOException ( MESSAGE_SKIPPED + skipped + MESSAGE_BYTES_INSTEAD_OF + instead ) ; } }
Skipped message error .
3,588
private static boolean checkHeader ( InputStream input , int [ ] header ) throws IOException { for ( final int b : header ) { if ( b != input . read ( ) ) { return false ; } } return true ; }
Check header data .
3,589
private void update ( CollisionCategory category ) { final CollisionResult result = results . get ( category . getName ( ) ) ; if ( result != null && ( result . getX ( ) != null || result . getY ( ) != null ) && Boolean . TRUE . equals ( enabledAxis . get ( category . getAxis ( ) ) ) ) { onCollided ( result , category ...
Update the tile collision computation .
3,590
private void onCollided ( CollisionResult result , CollisionCategory category ) { for ( final TileCollidableListener listener : listeners ) { listener . notifyTileCollided ( result , category ) ; } }
Called when a collision occurred on a specified axis .
3,591
public static int multiplyRgb ( int rgb , double fr , double fg , double fb ) { if ( rgb == 0 ) { return rgb ; } final int a = rgb >> Constant . BYTE_4 & 0xFF ; final int r = ( int ) UtilMath . clamp ( ( rgb >> Constant . BYTE_3 & 0xFF ) * fr , 0 , 255 ) ; final int g = ( int ) UtilMath . clamp ( ( rgb >> Constant . BY...
Apply an rgb factor .
3,592
public static int inc ( int value , int r , int g , int b ) { final int alpha = value >> Constant . BYTE_4 & 0xFF ; if ( alpha == 0 ) { return 0 ; } final int red = value >> Constant . BYTE_3 & 0xFF ; final int green = value >> Constant . BYTE_2 & 0xFF ; final int blue = value >> Constant . BYTE_1 & 0xFF ; final int al...
Get the increased color value . Current color not modified .
3,593
public static double getDelta ( ColorRgba a , ColorRgba b ) { Check . notNull ( a ) ; Check . notNull ( b ) ; final int dr = a . getRed ( ) - b . getRed ( ) ; final int dg = a . getGreen ( ) - b . getGreen ( ) ; final int db = a . getBlue ( ) - b . getBlue ( ) ; return Math . sqrt ( dr * dr + dg * dg + db * db ) ; }
Return the delta between two colors .
3,594
public static ColorRgba getWeightedColor ( ImageBuffer surface , int sx , int sy , int width , int height ) { Check . notNull ( surface ) ; int r = 0 ; int g = 0 ; int b = 0 ; int count = 0 ; for ( int x = 0 ; x < width ; x ++ ) { for ( int y = 0 ; y < height ; y ++ ) { final ColorRgba color = new ColorRgba ( surface ....
Get the weighted color of an area .
3,595
private static Map < Transition , Collection < TileRef > > getTransitions ( MapTile map ) { final Map < Transition , Collection < TileRef > > transitions = new HashMap < > ( ) ; final MapTransitionExtractor extractor = new MapTransitionExtractor ( map ) ; for ( int ty = 1 ; ty < map . getInTileHeight ( ) - 1 ; ty ++ ) ...
Get map tile transitions .
3,596
private static void checkTransition ( Map < Transition , Collection < TileRef > > transitions , MapTransitionExtractor extractor , Tile tile ) { final Transition transition = extractor . getTransition ( tile ) ; if ( transition != null ) { getTiles ( transitions , transition ) . add ( new TileRef ( tile ) ) ; final Tra...
Check the tile transition and add it to transitions collection if valid .
3,597
private static Collection < TileRef > getTiles ( Map < Transition , Collection < TileRef > > transitions , Transition transition ) { if ( ! transitions . containsKey ( transition ) ) { transitions . put ( transition , new HashSet < TileRef > ( ) ) ; } return transitions . get ( transition ) ; }
Get the tiles for the transition . Create empty list if new transition .
3,598
public static double getRound ( double speed , double value ) { if ( speed < 0 ) { return Math . floor ( value ) ; } return Math . ceil ( value ) ; }
Get the rounded floor or ceil value depending of the speed .
3,599
public static boolean isBetween ( double value , double min , double max ) { return Double . compare ( value , min ) >= 0 && Double . compare ( value , max ) <= 0 ; }
Check if value is between an interval .