diff --git a/src/App.scss b/src/App.scss
index eeaf8dd..0490aee 100644
--- a/src/App.scss
+++ b/src/App.scss
@@ -74,6 +74,8 @@
.school {
grid-area: school;
padding: 1rem;
+
+ overflow-y: auto;
}
.unit {
diff --git a/src/App.tsx b/src/App.tsx
index 9affcc4..4a67284 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -7,6 +7,8 @@ import { DebugView } from './views/DebugView'
export const App = observer(function () {
+ console.dir(performance.now());
+
return (
diff --git a/src/model/calendar.ts b/src/model/calendar.ts
index 4dcc272..ed53a41 100644
--- a/src/model/calendar.ts
+++ b/src/model/calendar.ts
@@ -37,6 +37,7 @@ export class Calendar {
public static deserialize(data: CalendarDto): Calendar {
const calendar = new Calendar();
+ calendar.day = data.day;
calendar.progress = Progress.deserialize(data.progress, true, calendar.handleProgress.bind(calendar));
return calendar;
diff --git a/src/model/game.ts b/src/model/game.ts
index 74627b3..ec83f55 100644
--- a/src/model/game.ts
+++ b/src/model/game.ts
@@ -10,6 +10,10 @@ export class Game {
makeAutoObservable(this);
}
+ public restart() {
+ this.school = new School();
+ }
+
public save(): void {
const data = this.school.serialize();
localStorage.setItem('save', JSON.stringify(data))
diff --git a/src/model/school.ts b/src/model/school.ts
index cb065be..a45d3d0 100644
--- a/src/model/school.ts
+++ b/src/model/school.ts
@@ -6,7 +6,7 @@ import { Upgrades } from './upgrades';
import { PartialResourceSet, ResourceSet } from '../types/resources';
import { addResourceSets, fullResourceSet, multiplyResourceSet, roundResourceSet, subtractResourceSets } from '../utils/resources';
import { v7 as uuid } from 'uuid';
-import { GameClock } from '../utils/gameClock';
+import { GameClock, nowTime } from '../utils/gameClock';
import { Calendar, CalendarDto } from './calendar';
import { getRandomHumanName } from '../utils/humanNames';
import { Time as Time } from './time';
@@ -50,12 +50,10 @@ export class School {
}
public tick(time: number) {
- const scaledTime = time;
-
- this.calendar.progress.tick(scaledTime);
+ this.calendar.progress.tick(time);
for (let unit of this.units)
- unit.progress.tick(scaledTime);
+ unit.progress.tick(time);
this.tps = GameClock.tps;
}
diff --git a/src/prefabs/upgrades.ts b/src/prefabs/upgrades.ts
index 43bd79e..424e71e 100644
--- a/src/prefabs/upgrades.ts
+++ b/src/prefabs/upgrades.ts
@@ -18,10 +18,10 @@ export const upgrades: UpgradePrefab[] = [
{
id: 'moreStudents',
name: "Больше учеников",
- description: (level) => `Увеличить количество учеников с ${level} до ${level + 1}`,
+ description: (level) => `Увеличить количество учеников с ${level + 1} до ${level + 2}`,
costToView: (level) => fullResourceSet(),
costToOpen: (level) => ({ reputation: 20 * (level / 10 + 1) }),
- costToBuy: (level) => ({ gold: 10 }),
+ costToBuy: (level) => ({ gold: 10 * (level + 1) }),
execute: (level) => {
game.school.increaseStudentCount();
},
diff --git a/src/utils/gameClock.ts b/src/utils/gameClock.ts
index af9009c..13267fa 100644
--- a/src/utils/gameClock.ts
+++ b/src/utils/gameClock.ts
@@ -1,6 +1,10 @@
import { game } from "../model/game";
import { ExternalSignal } from "./mobx/externalSignal";
+export function nowTime() {
+ return performance.timeOrigin + performance.now();
+}
+
export class GameClock {
public static lastTime = 0;
@@ -9,27 +13,18 @@ export class GameClock {
public static readonly pausedSignal = new ExternalSignal('GameClock.paused');
- // public static async start(): Promise
{
- // let lastTime = performance.now();
-
- // setInterval(() => {
- // let now = performance.now();
- // let delta = now - lastTime;
-
- // school.tick(delta / 1000);
-
- // lastTime = now;
- // }, 33);
- // }
-
public static start(): void {
- const loop = (now: number) => {
+ this.lastTime = nowTime();
+
+ const loop = () => {
+ if (GameClock.paused)
+ return;
+
+ let now = nowTime();
+
let delta = now - GameClock.lastTime;
GameClock.lastTime = now;
- if (GameClock.paused)
- delta *= 0;
-
GameClock.frames.push(now);
while (GameClock.frames[0] < now - 1000)
GameClock.frames.shift();
@@ -63,12 +58,20 @@ export class GameClock {
}
public static pause() {
+ if (GameClock.paused)
+ return;
+
GameClock.paused = true;
GameClock.pausedSignal.trigger();
}
public static resume() {
+ if (!GameClock.paused)
+ return;
+
GameClock.paused = false;
GameClock.pausedSignal.trigger();
+
+ GameClock.start();
}
}
diff --git a/src/views copy/UnitListView.tsx b/src/views copy/UnitListView.tsx
deleted file mode 100644
index 27a782b..0000000
--- a/src/views copy/UnitListView.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import { observer } from "mobx-react-lite";
-import { school } from "../model/school";
-import { Student } from "../model/student";
-import { Owner } from "../model/owner";
-import { OwnerUnitView } from "./OwnerUnitView";
-import { IUnit } from "../types/unit";
-
-export const UnitListView = observer(function () {
-
- function renderUnit(unit: IUnit) {
- if (unit instanceof Owner)
- return
- // // else if (unit instanceof Student)
- // // return StudentView({ unit });
- else
- return '???';
- }
-
- return {
- school.units.map((unit) => - {renderUnit(unit)}
)
- }
-});
diff --git a/src/views/DebugView.tsx b/src/views/DebugView.tsx
index de882e9..8b646ca 100644
--- a/src/views/DebugView.tsx
+++ b/src/views/DebugView.tsx
@@ -7,6 +7,10 @@ export const DebugView = observer(function () {
const [skipTime, setSkipTime] = useState(5);
+ const isDebugMode = location.hostname === "localhost" ||
+ location.hostname === "127.0.0.1" ||
+ location.hostname === "[::1]";
+
function handleTimeScaleChange(event: ChangeEvent): void {
game.school.time.setTimeScale(Number(event.target.value));
}
@@ -15,6 +19,10 @@ export const DebugView = observer(function () {
GameClock.skipTime(skipTime);
}
+ function handleRestartClick(): void {
+ game.restart();
+ }
+
function handleSaveClick(): void {
game.save();
}
@@ -22,6 +30,7 @@ export const DebugView = observer(function () {
function handleLoadClick(): void {
game.school.time.pause();
game.load();
+ game.school.time.resume();
}
function handleTickClick(): void {
@@ -32,31 +41,40 @@ export const DebugView = observer(function () {
return
+
diff --git a/src/views/UnitListView.tsx b/src/views/UnitListView.tsx
index 3b5dd5a..da084ee 100644
--- a/src/views/UnitListView.tsx
+++ b/src/views/UnitListView.tsx
@@ -8,15 +8,6 @@ import { game } from "../model/game";
export const UnitListView = observer(function () {
- function renderUnit(unit: IUnit) {
- if (unit instanceof Owner)
- return
- else if (unit instanceof Student)
- return
- else
- return '???';
- }
-
return