mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-10 15:46:06 +02:00
Improve code formatting
This commit is contained in:
@@ -5,7 +5,7 @@ import javafx.scene.shape.Rectangle;
|
|||||||
|
|
||||||
public class Square extends com.yes.yes.utils.Part {
|
public class Square extends com.yes.yes.utils.Part {
|
||||||
public Square() {
|
public Square() {
|
||||||
var rect = new Rectangle(25,25);
|
var rect = new Rectangle(25, 25);
|
||||||
rect.setFill(Color.RED);
|
rect.setFill(Color.RED);
|
||||||
rect.setStroke(Color.BLACK);
|
rect.setStroke(Color.BLACK);
|
||||||
rect.setStrokeWidth(1);
|
rect.setStrokeWidth(1);
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import com.yes.yes.utils.*;
|
|||||||
import com.yes.yes.world.Chunk;
|
import com.yes.yes.world.Chunk;
|
||||||
import com.yes.yes.world.World;
|
import com.yes.yes.world.World;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.*;
|
||||||
import javafx.scene.input.KeyCodeCombination;
|
|
||||||
import javafx.scene.input.KeyCombination;
|
|
||||||
import javafx.scene.input.KeyEvent;
|
|
||||||
|
|
||||||
public class PlayerManager {
|
public class PlayerManager {
|
||||||
|
|
||||||
@@ -30,12 +27,18 @@ public class PlayerManager {
|
|||||||
Scene scene = world.getScene();
|
Scene scene = world.getScene();
|
||||||
scene.setOnKeyPressed(this::ProcessKeyPress);
|
scene.setOnKeyPressed(this::ProcessKeyPress);
|
||||||
|
|
||||||
scene.widthProperty().addListener((e)-> loadAllOnScreen());
|
scene.widthProperty().addListener((e) -> loadAllOnScreen());
|
||||||
scene.heightProperty().addListener((e)-> loadAllOnScreen());
|
scene.heightProperty().addListener((e) -> loadAllOnScreen());
|
||||||
|
|
||||||
world.setOnMouseClicked((e) ->
|
world.setOnMouseClicked(this::ProcessClick);
|
||||||
{
|
world.setTranslateX(Integer.MAX_VALUE / -5000d);
|
||||||
Coordinate mouseCoordinate = new Coordinate((int) e.getX(), (int) e.getY());
|
world.setTranslateY(Integer.MAX_VALUE / -5000d);
|
||||||
|
|
||||||
|
loadAllOnScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessClick(MouseEvent mouse) {
|
||||||
|
Coordinate mouseCoordinate = new Coordinate((int) mouse.getX(), (int) mouse.getY());
|
||||||
Coordinate chunkCoordinate = Coordinate.WorldToChunkCoordinate(mouseCoordinate);
|
Coordinate chunkCoordinate = Coordinate.WorldToChunkCoordinate(mouseCoordinate);
|
||||||
Coordinate blockCoordinate = Coordinate.WorldToChunkBlock(mouseCoordinate);
|
Coordinate blockCoordinate = Coordinate.WorldToChunkBlock(mouseCoordinate);
|
||||||
|
|
||||||
@@ -56,13 +59,6 @@ public class PlayerManager {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
world.setTranslateX(Integer.MAX_VALUE / -5000d);
|
|
||||||
world.setTranslateY(Integer.MAX_VALUE / -5000d);
|
|
||||||
|
|
||||||
loadAllOnScreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ProcessKeyPress(KeyEvent key) {
|
private void ProcessKeyPress(KeyEvent key) {
|
||||||
if (LEFT_KEY.match(key)) {
|
if (LEFT_KEY.match(key)) {
|
||||||
@@ -113,8 +109,7 @@ public class PlayerManager {
|
|||||||
chunkPos = new Coordinate(chunkPosition.x, chunkPosition.y);
|
chunkPos = new Coordinate(chunkPosition.x, chunkPosition.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAllOnScreen()
|
private void loadAllOnScreen() {
|
||||||
{
|
|
||||||
Size loadedChunks = getAmountOfLoadedChunks();
|
Size loadedChunks = getAmountOfLoadedChunks();
|
||||||
Coordinate chunkPosition = getCurrentChunkPosition();
|
Coordinate chunkPosition = getCurrentChunkPosition();
|
||||||
|
|
||||||
@@ -125,18 +120,16 @@ public class PlayerManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Coordinate getCurrentChunkPosition()
|
private Coordinate getCurrentChunkPosition() {
|
||||||
{
|
|
||||||
double offset = Chunk.CHUNK_SIZE * Chunk.ENTITY_SIZE;
|
double offset = Chunk.CHUNK_SIZE * Chunk.ENTITY_SIZE;
|
||||||
|
|
||||||
int chunkX = -(int) Math.floor((world.getTranslateX() + offset) / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE);
|
int chunkX = -(int) Math.floor((world.getTranslateX() + offset) / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE);
|
||||||
int chunkY = -(int) Math.floor((world.getTranslateY() + offset) / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE);
|
int chunkY = -(int) Math.floor((world.getTranslateY() + offset) / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE);
|
||||||
|
|
||||||
return new Coordinate(chunkX,chunkY);
|
return new Coordinate(chunkX, chunkY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Size getAmountOfLoadedChunks()
|
private Size getAmountOfLoadedChunks() {
|
||||||
{
|
|
||||||
int loadedChunksX = (int) Math.ceil(world.getScene().getWidth() / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE) + 1;
|
int loadedChunksX = (int) Math.ceil(world.getScene().getWidth() / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE) + 1;
|
||||||
int loadedChunksY = (int) Math.ceil(world.getScene().getHeight() / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE) + 1;
|
int loadedChunksY = (int) Math.ceil(world.getScene().getHeight() / Chunk.CHUNK_SIZE / Chunk.ENTITY_SIZE) + 1;
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class EntityRegistry {
|
public class EntityRegistry {
|
||||||
|
private static final HashMap<String, RegistryEntry> entities = new HashMap<>();
|
||||||
|
|
||||||
private EntityRegistry() {
|
private EntityRegistry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HashMap<String, RegistryEntry> entities = new HashMap<>();
|
|
||||||
|
|
||||||
public static void register(RegistryEntry entry) throws AlreadyExistsException {
|
public static void register(RegistryEntry entry) throws AlreadyExistsException {
|
||||||
if (entities.containsKey(entry.getName())) {
|
if (entities.containsKey(entry.getName())) {
|
||||||
throw new AlreadyExistsException("Name already registered");
|
throw new AlreadyExistsException("Name already registered");
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import java.util.function.Consumer;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class GlobalEventHandler {
|
public class GlobalEventHandler {
|
||||||
|
private static final EventHandler handler = new EventHandler();
|
||||||
|
|
||||||
private GlobalEventHandler() {
|
private GlobalEventHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final EventHandler handler = new EventHandler();
|
|
||||||
|
|
||||||
public static <T> void addListener(String eventName, Consumer<T> function) {
|
public static <T> void addListener(String eventName, Consumer<T> function) {
|
||||||
handler.addListener(eventName, function);
|
handler.addListener(eventName, function);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,11 @@ public class Item extends javafx.scene.Group {
|
|||||||
throw new IllegalArgumentException("Argument out of range");
|
throw new IllegalArgumentException("Argument out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parts[layer][section] != null) {
|
if (parts[layer][section] != null) {
|
||||||
this.getChildren().remove(parts[layer][section]);
|
this.getChildren().remove(parts[layer][section]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
parts[layer][section] = part;
|
parts[layer][section] = part;
|
||||||
this.getChildren().add(part);
|
this.getChildren().add(part);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<VBox spacing="20.0" xmlns:fx="http://javafx.com/fxml"
|
<VBox xmlns:fx="http://javafx.com/fxml" spacing="20.0"
|
||||||
fx:controller="com.yes.yes.MainController" fx:id="root">
|
fx:controller="com.yes.yes.MainController" fx:id="root">
|
||||||
</VBox>
|
</VBox>
|
||||||
|
|||||||
Reference in New Issue
Block a user