Change initial world time

This commit is contained in:
2025-07-11 14:29:59 +02:00
parent d66aabd58a
commit 2e4459b92c
3 changed files with 22 additions and 4 deletions

View File

@@ -107,12 +107,13 @@ CREATE MEMORY TABLE "PUBLIC"."CONFIG"(
"VALUE" VARCHAR "VALUE" VARCHAR
); );
ALTER TABLE "PUBLIC"."CONFIG" ADD CONSTRAINT "PUBLIC"."CONSTRAINT_7" PRIMARY KEY("KEY"); 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 INSERT INTO "PUBLIC"."CONFIG" VALUES
('start_game', 'Hero Home,Main,Start'), ('start_game', 'Hero Home,Main,Start'),
('screen', '1000x800'), ('screen', '1000x800'),
('camera_scale', '2'), ('camera_scale', '2'),
('full_day_duration', '600'); ('full_day_duration', '600'),
('initial_time', '08:30');
CREATE MEMORY TABLE "PUBLIC"."LEVELS"( 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", "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 "MAX_HP" VARCHAR NOT NULL

View File

@@ -74,13 +74,13 @@ public class DemoRunner implements GameRunner {
var layer = map.layer(start[1]); var layer = map.layer(start[1]);
var label = layer.label(start[2]); var label = layer.label(start[2]);
time.setTime(dao.config.find("initial_time").getValue());
context.openMap(map.$); context.openMap(map.$);
context.getMap().getObjectLayer(layer.$).addEntity(this.player); context.getMap().getObjectLayer(layer.$).addEntity(this.player);
player.setCoordinates(label.getX(), label.getY()); player.setCoordinates(label.getX(), label.getY());
context.resume(); context.resume();
hud.show(); hud.show();
var x = A.maps.hero_home.main.entry;
} }
public void returnToStartMenu() { public void returnToStartMenu() {

View File

@@ -6,7 +6,11 @@ import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class WorldTime { public class WorldTime {
private static final float MINUTES_PER_DAY = 1440f; // 60min * 24
@Getter @Getter
private float progress = 0; private float progress = 0;
@@ -18,6 +22,19 @@ public class WorldTime {
this.period = Float.parseFloat(dao.config.find("full_day_duration").getValue()); 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() { public int getHour() {
return (int) (progress * 24); return (int) (progress * 24);
} }