diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index c13f8bd..1dc4361 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ default-cli - com.yes.yes/com.yes.yes.HelloApplication + com.yes.yes/com.yes.yes.YesApplication diff --git a/src/main/java/com/yes/yes/HelloController.java b/src/main/java/com/yes/yes/HelloController.java deleted file mode 100644 index d08083d..0000000 --- a/src/main/java/com/yes/yes/HelloController.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.yes.yes; - -import javafx.fxml.FXML; -import javafx.scene.control.Label; - -public class HelloController { - @FXML - private Label welcomeText; - - @FXML - protected void onHelloButtonClick() { - welcomeText.setText("Welcome to JavaFX Application!"); - } -} \ No newline at end of file diff --git a/src/main/java/com/yes/yes/MainController.java b/src/main/java/com/yes/yes/MainController.java new file mode 100644 index 0000000..25e099a --- /dev/null +++ b/src/main/java/com/yes/yes/MainController.java @@ -0,0 +1,17 @@ +package com.yes.yes; + +import com.yes.yes.world.World; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.VBox; + +public class MainController { + @FXML + VBox root; + + public void initialize() { + World chunk = new World(); + + root.getChildren().add(chunk); + } +} \ No newline at end of file diff --git a/src/main/java/com/yes/yes/HelloApplication.java b/src/main/java/com/yes/yes/YesApplication.java similarity index 69% rename from src/main/java/com/yes/yes/HelloApplication.java rename to src/main/java/com/yes/yes/YesApplication.java index 2b59c03..fdfb029 100644 --- a/src/main/java/com/yes/yes/HelloApplication.java +++ b/src/main/java/com/yes/yes/YesApplication.java @@ -1,16 +1,15 @@ package com.yes.yes; -import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; import java.io.IOException; -public class HelloApplication extends Application { +public class YesApplication extends javafx.application.Application { @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); + FXMLLoader fxmlLoader = new FXMLLoader(YesApplication.class.getResource("main-view.fxml")); Scene scene = new Scene(fxmlLoader.load(), 320, 240); stage.setTitle("Hello!"); stage.setScene(scene); diff --git a/src/main/java/com/yes/yes/utils/Component.java b/src/main/java/com/yes/yes/utils/Component.java new file mode 100644 index 0000000..25e9194 --- /dev/null +++ b/src/main/java/com/yes/yes/utils/Component.java @@ -0,0 +1,4 @@ +package com.yes.yes.utils; + +public abstract class Component extends javafx.scene.shape.Shape { +} diff --git a/src/main/java/com/yes/yes/utils/Coordinate.java b/src/main/java/com/yes/yes/utils/Coordinate.java new file mode 100644 index 0000000..d709d18 --- /dev/null +++ b/src/main/java/com/yes/yes/utils/Coordinate.java @@ -0,0 +1,27 @@ +package com.yes.yes.utils; + +import java.util.Objects; + +public class Coordinate { + public int x; + public int y; + + public Coordinate(int x, int y) { + this.x = x; + this.y = y; + } + public Coordinate() {} + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Coordinate)) return false; + Coordinate that = (Coordinate) o; + return x == that.x && y == that.y; + } + + @Override + public int hashCode() { + return Objects.hash(x, y); + } +} \ No newline at end of file diff --git a/src/main/java/com/yes/yes/utils/Entity.java b/src/main/java/com/yes/yes/utils/Entity.java new file mode 100644 index 0000000..2d68f32 --- /dev/null +++ b/src/main/java/com/yes/yes/utils/Entity.java @@ -0,0 +1,4 @@ +package com.yes.yes.utils; + +public abstract class Entity { +} diff --git a/src/main/java/com/yes/yes/world/Chunk.java b/src/main/java/com/yes/yes/world/Chunk.java new file mode 100644 index 0000000..c97dfd6 --- /dev/null +++ b/src/main/java/com/yes/yes/world/Chunk.java @@ -0,0 +1,50 @@ +package com.yes.yes.world; + +import com.yes.yes.utils.Component; +import javafx.scene.layout.ColumnConstraints; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.RowConstraints; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; + +public class Chunk extends GridPane { + private static final int CHUNK_SIZE = 16; + private static final double COMPONENT_SIZE = 50; + private final Component[] data = new Component[CHUNK_SIZE * CHUNK_SIZE]; + + public Chunk() { + super(); + this.setMaxSize(CHUNK_SIZE * COMPONENT_SIZE, CHUNK_SIZE * COMPONENT_SIZE); + this.setMinSize(CHUNK_SIZE * COMPONENT_SIZE, CHUNK_SIZE * COMPONENT_SIZE); + + for (int i = 0; i < CHUNK_SIZE; i++) { + for (int j = 0; j < CHUNK_SIZE; j++) { + this.getColumnConstraints().add(new ColumnConstraints(COMPONENT_SIZE)); + this.getRowConstraints().add(new RowConstraints(COMPONENT_SIZE)); + + + Rectangle rect = new Rectangle(COMPONENT_SIZE, COMPONENT_SIZE); + rect.setFill(Color.color((i+j*16)/257d,(i+j*16)/257d, (i+j*16)/257d,1)); //DEBUG CODE + rect.setStroke(Color.BLACK); + rect.strokeWidthProperty().set(0.5); + this.add(rect, i, j); + } + } + } + + public void setComponent(Component component, int x, int y) { + data[x + y * CHUNK_SIZE] = component; + this.add(component, x, y); + } + + public void removeComponent(int x, int y) { + this.getChildren().remove(data[x + y * CHUNK_SIZE]); + data[x + y * CHUNK_SIZE] = null; + } + + public Component getComponent(int x, int y) { + return data[x + y * CHUNK_SIZE]; + } + + +} diff --git a/src/main/java/com/yes/yes/world/World.java b/src/main/java/com/yes/yes/world/World.java new file mode 100644 index 0000000..c5e789f --- /dev/null +++ b/src/main/java/com/yes/yes/world/World.java @@ -0,0 +1,30 @@ +package com.yes.yes.world; + +import com.yes.yes.utils.Coordinate; +import javafx.scene.layout.GridPane; + +import java.util.HashMap; + +public class World extends GridPane { + private final HashMap chunks = new HashMap<>(); + + public World() { + super(); + + for (int x = 0; x < 4; x++) {//DEBUG CODE + for (int y = 0; y < 4; y++) { + chunks.put(new Coordinate(x, y), new Chunk()); + this.add(chunks.get(new Coordinate(x, y)), x, y); + } + } + + this.unload(new Coordinate(2, 2)); //DEBUG CODE + } + + public void unload(Coordinate pos) { + this.getChildren().remove(chunks.get(pos)); + } + public void load(Coordinate pos) { + this.add(chunks.get(pos), pos.x, pos.y); + } +} diff --git a/src/main/resources/com/yes/yes/hello-view.fxml b/src/main/resources/com/yes/yes/main-view.fxml similarity index 52% rename from src/main/resources/com/yes/yes/hello-view.fxml rename to src/main/resources/com/yes/yes/main-view.fxml index 8f5b21e..943c89f 100644 --- a/src/main/resources/com/yes/yes/hello-view.fxml +++ b/src/main/resources/com/yes/yes/main-view.fxml @@ -6,11 +6,5 @@ - - - - -