refactor: Remove repeated code
This commit is contained in:
@@ -2,7 +2,6 @@ package cz.jzitnik.events.handlers;
|
||||
|
||||
import com.googlecode.lanterna.TerminalPosition;
|
||||
import com.googlecode.lanterna.TerminalSize;
|
||||
import com.googlecode.lanterna.TextColor;
|
||||
import com.googlecode.lanterna.screen.TerminalScreen;
|
||||
import cz.jzitnik.annotations.EventHandler;
|
||||
import cz.jzitnik.annotations.injectors.InjectConfig;
|
||||
@@ -19,9 +18,6 @@ import cz.jzitnik.game.ResourceManager;
|
||||
import cz.jzitnik.states.RenderState;
|
||||
import cz.jzitnik.states.ScreenBuffer;
|
||||
import cz.jzitnik.states.TerminalState;
|
||||
import cz.jzitnik.ui.pixels.ColoredPixel;
|
||||
import cz.jzitnik.ui.pixels.Empty;
|
||||
import cz.jzitnik.ui.pixels.Pixel;
|
||||
import cz.jzitnik.utils.DependencyManager;
|
||||
import cz.jzitnik.utils.RerenderUtils;
|
||||
import cz.jzitnik.utils.events.AbstractEventHandler;
|
||||
@@ -29,15 +25,12 @@ import cz.jzitnik.utils.events.EventManager;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@EventHandler(FullRoomDraw.class)
|
||||
public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
|
||||
public FullRoomDrawHandler(DependencyManager dm) {
|
||||
super(dm);
|
||||
}
|
||||
|
||||
@InjectState
|
||||
private GameState gameState;
|
||||
|
||||
@@ -59,11 +52,8 @@ public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
|
||||
@InjectConfig
|
||||
private Debugging debugging;
|
||||
|
||||
public enum DoorPosition {
|
||||
TOP,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
BOTTOM,
|
||||
public FullRoomDrawHandler(DependencyManager dm) {
|
||||
super(dm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,13 +64,7 @@ public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
|
||||
List<RerenderScreen.ScreenPart> partsToRerender = new ArrayList<>();
|
||||
GameRoom currentRoom = gameState.getCurrentRoom();
|
||||
|
||||
Set<DoorPosition> doorPositions = RerenderUtils.getDoorPositions(currentRoom);
|
||||
|
||||
var buffer = screenBuffer.getRenderedBuffer();
|
||||
var overrideBuffer = currentRoom.getOverrideBuffer();
|
||||
|
||||
BufferedImage room = resourceManager.getResource(currentRoom.getTexture());
|
||||
BufferedImage doors = resourceManager.getResource(ResourceManager.Resource.DOORS);
|
||||
Player player = gameState.getPlayer();
|
||||
BufferedImage playerTexture = RerenderUtils.getPlayer(resourceManager, player);
|
||||
TerminalSize terminalSize = terminalScreen.getTerminalSize();
|
||||
@@ -92,22 +76,7 @@ public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
|
||||
int startX = start.getX();
|
||||
int startY = start.getY();
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
RerenderUtils.PixelResult pixelResult = RerenderUtils.getPixel(currentRoom, room, doors, doorPositions, player, playerTexture, x, y, debugging);
|
||||
int pixel = pixelResult.pixel();
|
||||
int red = (pixel >> 16) & 0xff;
|
||||
int green = (pixel >> 8) & 0xff;
|
||||
int blue = pixel & 0xff;
|
||||
|
||||
Pixel overridePixel = overrideBuffer[y][x];
|
||||
Pixel pixel1 = new ColoredPixel(new TextColor.RGB(red, green, blue));
|
||||
|
||||
Pixel finalPixelLeft = overridePixel.getClass() == Empty.class || pixelResult.isPlayer() ? pixel1 : overridePixel;
|
||||
|
||||
buffer[y + startY][x + startX] = finalPixelLeft;
|
||||
}
|
||||
}
|
||||
RerenderUtils.rerenderPart(0, width - 1, 0, height - 1, startX, startY, currentRoom, room, player, playerTexture, screenBuffer, resourceManager, debugging);
|
||||
|
||||
partsToRerender.add(new RerenderScreen.ScreenPart(
|
||||
new TerminalPosition(startX, startY),
|
||||
@@ -128,4 +97,11 @@ public class FullRoomDrawHandler extends AbstractEventHandler<FullRoomDraw> {
|
||||
renderState.setTerminalTooSmall(true);
|
||||
}
|
||||
}
|
||||
|
||||
public enum DoorPosition {
|
||||
TOP,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
BOTTOM,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user