mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 00:46:01 +02:00
Improve code formatting
This commit is contained in:
@@ -20,7 +20,7 @@ public class YesApplication extends javafx.application.Application {
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(YesApplication.class.getResource("main-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), 1280 , 720 );
|
||||
Scene scene = new Scene(fxmlLoader.load(), 1280, 720);
|
||||
stage.setTitle("Yes!");
|
||||
stage.setScene(scene);
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import com.yes.yes.utils.*;
|
||||
|
||||
public class DataStoreEvent extends Component {
|
||||
|
||||
String dataKey;
|
||||
String eventName;
|
||||
boolean global;
|
||||
private final String dataKey;
|
||||
private final String eventName;
|
||||
private final boolean global;
|
||||
|
||||
|
||||
public DataStoreEvent(Entity entity, BlockContainer blockContainer, String dataKey, String eventName, boolean global) {
|
||||
|
||||
@@ -19,7 +19,7 @@ public class DestroyBehaviour extends Component {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if(this.parent.getData(dataKey) !=null) {
|
||||
if (this.parent.getData(dataKey) != null) {
|
||||
this.parent.setData(dataKey, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import com.yes.yes.utils.*;
|
||||
|
||||
public class EventDataStore extends Component {
|
||||
|
||||
String eventName;
|
||||
String dataKey;
|
||||
boolean global;
|
||||
private final String eventName;
|
||||
private final String dataKey;
|
||||
private final boolean global;
|
||||
|
||||
public EventDataStore(Entity entity, BlockContainer blockContainer, String eventName, String dataKey, boolean global) {
|
||||
super(entity, blockContainer);
|
||||
|
||||
@@ -8,8 +8,8 @@ import javafx.scene.text.Text;
|
||||
|
||||
public class HubDisplayBehaviour extends Component {
|
||||
|
||||
String eventName;
|
||||
Text text;
|
||||
private final String eventName;
|
||||
private final Text text;
|
||||
|
||||
public HubDisplayBehaviour(Entity entity, BlockContainer blockContainer, String eventName, Text text) {
|
||||
super(entity, blockContainer);
|
||||
@@ -17,8 +17,7 @@ public class HubDisplayBehaviour extends Component {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
private void updateText(String content)
|
||||
{
|
||||
private void updateText(String content) {
|
||||
this.text.setText(content);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@ package com.yes.yes.behaviours;
|
||||
|
||||
import com.yes.yes.utils.*;
|
||||
import com.yes.yes.world.Chunk;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
@@ -13,8 +11,8 @@ import javafx.scene.transform.Translate;
|
||||
|
||||
public class ItemBehaviour extends Component {
|
||||
|
||||
private StackPane itemGroup;
|
||||
private final String dataKey;
|
||||
private StackPane itemGroup;
|
||||
|
||||
public ItemBehaviour(Entity entity, BlockContainer blockContainer, String dataKey) {
|
||||
super(entity, blockContainer);
|
||||
@@ -22,21 +20,20 @@ public class ItemBehaviour extends Component {
|
||||
}
|
||||
|
||||
private void itemChanged(Item item) {
|
||||
//GlobalExecQueue.schedule(() -> {
|
||||
Platform.runLater(() -> {
|
||||
GlobalExecQueue.schedule(() -> {
|
||||
try {
|
||||
|
||||
this.parent.getChildren().clear();
|
||||
this.itemGroup.getChildren().clear();
|
||||
|
||||
if (item != null)
|
||||
this.itemGroup.getChildren().add(item);
|
||||
this.itemGroup.getChildren().add(item.clone());
|
||||
else {
|
||||
Rectangle alignmentRectangle = new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE);
|
||||
alignmentRectangle.setFill(Color.rgb(0, 0, 0, 0));
|
||||
this.itemGroup.getChildren().add(alignmentRectangle);
|
||||
}
|
||||
} catch (IndexOutOfBoundsException ignore) {
|
||||
}
|
||||
catch (IndexOutOfBoundsException ex){System.out.print(ex.getMessage() + " | " + this.parent.getClass().getSimpleName()); }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,11 +50,11 @@ public class ItemBehaviour extends Component {
|
||||
Scale s = new Scale(0.7, 0.7);
|
||||
itemGroup.getTransforms().add(s);
|
||||
|
||||
Translate translate = new Translate(Chunk.ENTITY_SIZE/4,Chunk.ENTITY_SIZE/4);
|
||||
Translate translate = new Translate(Chunk.ENTITY_SIZE / 4d, Chunk.ENTITY_SIZE / 4d);
|
||||
itemGroup.getTransforms().add(translate);
|
||||
|
||||
Rectangle alignmentRectangle = new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE);
|
||||
alignmentRectangle.setFill(Color.rgb(0,0,0,0));
|
||||
alignmentRectangle.setFill(Color.rgb(0, 0, 0, 0));
|
||||
this.itemGroup.getChildren().add(alignmentRectangle);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ public class OfferBehaviour extends Component {
|
||||
}
|
||||
|
||||
private void placed(Entity entity) {
|
||||
//System.out.println("Entity placed in range");
|
||||
try {
|
||||
if (blockContainer.getBlockRelative(direction, parent.getRotation()) == entity) {
|
||||
this.receiver = entity;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ReceiveBehaviour extends Component {
|
||||
this.parent.addListener("placed", this, this::placed);
|
||||
}
|
||||
|
||||
void receive(Pair<Entity,Item> pair) {
|
||||
void receive(Pair<Entity, Item> pair) {
|
||||
if (offerer == null || offerer != pair.getKey()) return;
|
||||
|
||||
if (this.parent.getData(dataKey) == pair.getValue())
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.yes.yes.behaviours;
|
||||
|
||||
import com.yes.yes.utils.*;
|
||||
import javafx.application.Platform;
|
||||
|
||||
public class StackBehaviour extends Component {
|
||||
private final int processingDuration;
|
||||
private String receiveDataKey1;
|
||||
private String receiveDataKey2;
|
||||
private String offerDataKey;
|
||||
private final String receiveDataKey1;
|
||||
private final String receiveDataKey2;
|
||||
private final String offerDataKey;
|
||||
private int progress = 0;
|
||||
|
||||
|
||||
@@ -26,8 +25,7 @@ public class StackBehaviour extends Component {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
//GlobalExecQueue.schedule( () -> {
|
||||
Platform.runLater(() -> {
|
||||
GlobalExecQueue.schedule(() -> {
|
||||
if (progress > processingDuration) {
|
||||
if (parent.getData(offerDataKey) != null) return;
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ public class Cutter extends Entity {
|
||||
public Cutter() {
|
||||
super();
|
||||
|
||||
Circle c = new Circle(Chunk.ENTITY_SIZE / 2);
|
||||
Circle c = new Circle(Chunk.ENTITY_SIZE / 2d);
|
||||
c.setFill(Color.BLACK);
|
||||
c.setCenterX(Chunk.ENTITY_SIZE / 2);
|
||||
c.setCenterY(Chunk.ENTITY_SIZE / 2);
|
||||
c.setCenterX(Chunk.ENTITY_SIZE / 2d);
|
||||
c.setCenterY(Chunk.ENTITY_SIZE / 2d);
|
||||
|
||||
Polygon p = new Polygon();
|
||||
p.getPoints().addAll(
|
||||
|
||||
@@ -8,14 +8,13 @@ import com.yes.yes.utils.Direction;
|
||||
import com.yes.yes.utils.Entity;
|
||||
import com.yes.yes.world.Chunk;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
|
||||
public class DestroyMachine extends Entity {
|
||||
public DestroyMachine() {
|
||||
super();
|
||||
Rectangle r = new Rectangle(Chunk.ENTITY_SIZE,Chunk.ENTITY_SIZE);
|
||||
Rectangle r = new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE);
|
||||
|
||||
Polygon p = new Polygon();
|
||||
p.getPoints().addAll(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.yes.yes.entities.machines;
|
||||
|
||||
import com.yes.yes.behaviours.GeneratorBehaviour;
|
||||
import com.yes.yes.behaviours.ItemBehaviour;
|
||||
import com.yes.yes.behaviours.OfferBehaviour;
|
||||
import com.yes.yes.behaviours.PlaceBehaviour;
|
||||
import com.yes.yes.entities.parts.Square;
|
||||
@@ -15,7 +14,7 @@ import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
|
||||
public class GeneratorMachine extends Entity {
|
||||
Rectangle rectangle;
|
||||
private final Rectangle rectangle;
|
||||
|
||||
public GeneratorMachine() {
|
||||
super();
|
||||
@@ -39,7 +38,6 @@ public class GeneratorMachine extends Entity {
|
||||
rectangle.setFill(blockContainer.chunkColor());
|
||||
|
||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||
//this.addBehaviour(new ItemBehaviour(this, blockContainer, "Item"));
|
||||
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.UP, "Item"));
|
||||
this.addBehaviour(new GeneratorBehaviour(this, blockContainer, generateItem(blockContainer.chunkColor()), "Item"));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.yes.yes.entities.machines;
|
||||
|
||||
import com.yes.yes.behaviours.EventDataStore;
|
||||
import com.yes.yes.behaviours.HubDisplayBehaviour;
|
||||
import com.yes.yes.behaviours.ItemBehaviour;
|
||||
import com.yes.yes.behaviours.PlaceBehaviour;
|
||||
import com.yes.yes.utils.BlockContainer;
|
||||
import com.yes.yes.utils.Entity;
|
||||
@@ -16,7 +14,7 @@ import javafx.scene.text.Text;
|
||||
|
||||
public class HubDisplay extends Entity implements NotOverridable {
|
||||
|
||||
Text text;
|
||||
private final Text text;
|
||||
|
||||
public HubDisplay() {
|
||||
Rectangle r = new Rectangle(Chunk.ENTITY_SIZE, Chunk.ENTITY_SIZE);
|
||||
@@ -36,6 +34,6 @@ public class HubDisplay extends Entity implements NotOverridable {
|
||||
public HubDisplay(BlockContainer blockContainer) {
|
||||
this();
|
||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new HubDisplayBehaviour(this, blockContainer, "hub:statusText",text));
|
||||
this.addBehaviour(new HubDisplayBehaviour(this, blockContainer, "hub:statusText", text));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ public class Stacker extends Entity {
|
||||
public Stacker(BlockContainer blockContainer) {
|
||||
this();
|
||||
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||
this.addBehaviour(new StackBehaviour(this,blockContainer,"Input1","Input2","Output",2));
|
||||
this.addBehaviour(new StackBehaviour(this, blockContainer, "Input1", "Input2", "Output", 2));
|
||||
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.UP, "Output"));
|
||||
this.addBehaviour(new ReceiveBehaviour(this,blockContainer,Direction.LEFT,"Input1"));
|
||||
this.addBehaviour(new ReceiveBehaviour(this,blockContainer,Direction.RIGHT,"Input2"));
|
||||
this.addBehaviour(new ReceiveBehaviour(this, blockContainer, Direction.LEFT, "Input1"));
|
||||
this.addBehaviour(new ReceiveBehaviour(this, blockContainer, Direction.RIGHT, "Input2"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,15 @@ package com.yes.yes.entities.parts;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Square extends com.yes.yes.utils.Part {
|
||||
|
||||
Rectangle rect = new Rectangle(23, 23);
|
||||
Rectangle rect;
|
||||
|
||||
public Square(Color color)
|
||||
{
|
||||
public Square(Color color) {
|
||||
this();
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
public Square() {
|
||||
rect = new Rectangle(23, 23);
|
||||
rect.setStroke(Color.BLACK);
|
||||
@@ -22,8 +20,7 @@ public class Square extends com.yes.yes.utils.Part {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onColorChanged(Color color)
|
||||
{
|
||||
protected void onColorChanged(Color color) {
|
||||
rect.setFill(color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,16 +42,16 @@ public class GameManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
GlobalEventHandler.trigger("global:timerTick", null);
|
||||
//GlobalExecQueue.run();
|
||||
GlobalExecQueue.run();
|
||||
} catch (Exception ex) {
|
||||
//ex.printStackTrace();
|
||||
ex.printStackTrace();
|
||||
}
|
||||
//System.out.println("Finished tick!");
|
||||
}, 0, 10, TimeUnit.MILLISECONDS);
|
||||
}, 0, 100, TimeUnit.MILLISECONDS);
|
||||
|
||||
GlobalEventHandler.addListener("app:closing", this, (__) -> executor.shutdown());
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ public class HubManager {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Item generateObjective() {
|
||||
Item item = new Item();
|
||||
|
||||
@@ -38,17 +37,17 @@ public class HubManager {
|
||||
int complexity = level % 10; //TODO: Make complexity make stuff more complex
|
||||
|
||||
//for (int l = 0; l < layerCount && l < 4; l++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
//item.setPart(l, i, new Square(Color.RED));
|
||||
item.setPart(0, i, new Square(Color.GREEN));
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
//item.setPart(l, i, new Square(Color.RED));
|
||||
item.setPart(0, i, new Square(Color.GREEN));
|
||||
}
|
||||
|
||||
//}
|
||||
return item;
|
||||
}
|
||||
|
||||
private String getStatusText() {
|
||||
return String.format("%s\n%s/%s",level,objectiveCompletion,objectiveTotal);
|
||||
return String.format("%s\n%s/%s", level, objectiveCompletion, objectiveTotal);
|
||||
}
|
||||
|
||||
private void objectiveCompletion(Item item) {
|
||||
@@ -60,7 +59,7 @@ public class HubManager {
|
||||
newLevel();
|
||||
}
|
||||
|
||||
GlobalEventHandler.trigger("hub:statusText",getStatusText());
|
||||
GlobalEventHandler.trigger("hub:statusText", getStatusText());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class Entity extends javafx.scene.Group {
|
||||
|
||||
public final void setData(String key, Object value) {
|
||||
data.put(key, value);
|
||||
this.trigger(key+"Changed",value);
|
||||
this.trigger(key + "Changed", value);
|
||||
}
|
||||
|
||||
public final <T> T getData(String key) {
|
||||
|
||||
@@ -2,11 +2,13 @@ package com.yes.yes.utils;
|
||||
|
||||
import javafx.application.Platform;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
public class GlobalExecQueue {
|
||||
private final static ArrayList<Runnable> queue = new ArrayList<>();
|
||||
private final static Queue<Runnable> queue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private GlobalExecQueue() {
|
||||
}
|
||||
@@ -16,22 +18,21 @@ public class GlobalExecQueue {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void run() {
|
||||
//Semaphore s = new Semaphore(0);
|
||||
Platform.runLater( () -> {
|
||||
for (Runnable runnable : queue) {
|
||||
Semaphore s = new Semaphore(0);
|
||||
Platform.runLater(() -> {
|
||||
while (queue.size() > 0) {
|
||||
synchronized (GlobalExecQueue.class) {
|
||||
runnable.run();
|
||||
Objects.requireNonNull(queue.poll()).run();
|
||||
}
|
||||
}
|
||||
// s.release();
|
||||
s.release();
|
||||
});
|
||||
/*try {
|
||||
//s.acquire();
|
||||
try {
|
||||
s.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
queue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.yes.yes.utils;
|
||||
|
||||
public class NoiseGenerator {
|
||||
private NoiseGenerator(){}
|
||||
private NoiseGenerator() {
|
||||
}
|
||||
|
||||
public static double calculate(int value)
|
||||
{
|
||||
return Math.abs(Math.sin(Math.tan(value) + Math.pow(value,2)) * Math.cos(Math.pow(value,2)) * Integer.MAX_VALUE);
|
||||
public static double calculate(int value) {
|
||||
return Math.abs(Math.sin(Math.tan(value) + Math.pow(value, 2)) * Math.cos(Math.pow(value, 2)) * Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,15 @@ public abstract class Part extends javafx.scene.Group {
|
||||
|
||||
protected abstract void onColorChanged(Color color);
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
onColorChanged(color);
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
Reference in New Issue
Block a user