From 2e4459b92ceb55311434a694b6a9a59cec835ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Fri, 11 Jul 2025 14:29:59 +0200 Subject: [PATCH] Change initial world time --- data.sql | 5 +++-- .../bartlomiejpluta/demo/runner/DemoRunner.java | 4 ++-- .../demo/world/time/WorldTime.java | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/data.sql b/data.sql index 8938976..de590b8 100644 --- a/data.sql +++ b/data.sql @@ -107,12 +107,13 @@ CREATE MEMORY TABLE "PUBLIC"."CONFIG"( "VALUE" VARCHAR ); ALTER TABLE "PUBLIC"."CONFIG" ADD CONSTRAINT "PUBLIC"."CONSTRAINT_7" PRIMARY KEY("KEY"); --- 4 +/- SELECT COUNT(*) FROM PUBLIC.CONFIG; +-- 5 +/- SELECT COUNT(*) FROM PUBLIC.CONFIG; INSERT INTO "PUBLIC"."CONFIG" VALUES ('start_game', 'Hero Home,Main,Start'), ('screen', '1000x800'), ('camera_scale', '2'), -('full_day_duration', '600'); +('full_day_duration', '600'), +('initial_time', '08:30'); CREATE MEMORY TABLE "PUBLIC"."LEVELS"( "LEVEL" INT DEFAULT NEXT VALUE FOR "PUBLIC"."SYSTEM_SEQUENCE_704587BB_DC0E_44AB_A7F0_3DE0CA44FE3F" NOT NULL NULL_TO_DEFAULT SEQUENCE "PUBLIC"."SYSTEM_SEQUENCE_704587BB_DC0E_44AB_A7F0_3DE0CA44FE3F", "MAX_HP" VARCHAR NOT NULL diff --git a/src/main/java/com/bartlomiejpluta/demo/runner/DemoRunner.java b/src/main/java/com/bartlomiejpluta/demo/runner/DemoRunner.java index 93d375b..bbe4fdd 100644 --- a/src/main/java/com/bartlomiejpluta/demo/runner/DemoRunner.java +++ b/src/main/java/com/bartlomiejpluta/demo/runner/DemoRunner.java @@ -74,13 +74,13 @@ public class DemoRunner implements GameRunner { var layer = map.layer(start[1]); var label = layer.label(start[2]); + time.setTime(dao.config.find("initial_time").getValue()); + context.openMap(map.$); context.getMap().getObjectLayer(layer.$).addEntity(this.player); player.setCoordinates(label.getX(), label.getY()); context.resume(); hud.show(); - - var x = A.maps.hero_home.main.entry; } public void returnToStartMenu() { diff --git a/src/main/java/com/bartlomiejpluta/demo/world/time/WorldTime.java b/src/main/java/com/bartlomiejpluta/demo/world/time/WorldTime.java index 160aa67..23539e0 100644 --- a/src/main/java/com/bartlomiejpluta/demo/world/time/WorldTime.java +++ b/src/main/java/com/bartlomiejpluta/demo/world/time/WorldTime.java @@ -6,7 +6,11 @@ import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; +import static java.lang.Math.max; +import static java.lang.Math.min; + public class WorldTime { + private static final float MINUTES_PER_DAY = 1440f; // 60min * 24 @Getter private float progress = 0; @@ -18,6 +22,19 @@ public class WorldTime { this.period = Float.parseFloat(dao.config.find("full_day_duration").getValue()); } + public void setProgress(float progress) { + this.progress = max(0, min(1, progress)); + } + + public void setTime(@NonNull String time) { + var splitted = time.split(":"); + this.setTime(Integer.valueOf(splitted[0], 10), Integer.valueOf(splitted[1], 10)); + } + + public void setTime(int h, int m) { + this.progress = (h * 60 + m) / MINUTES_PER_DAY; + } + public int getHour() { return (int) (progress * 24); }