Skip to content

Commit

Permalink
Merge pull request #20 from linomp/feat/background-img-loading
Browse files Browse the repository at this point in the history
simple fix for caching machine view gifs & optimized gif size
  • Loading branch information
linomp authored Mar 16, 2024
2 parents a1e2c83 + bd7060b commit 01f84b9
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 12 deletions.
1 change: 0 additions & 1 deletion mvp/client/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<head>
<meta charset="utf-8">
<link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
Expand Down
Binary file removed mvp/client/ui/public/img/apple-touch-icon.png
Binary file not shown.
Binary file added mvp/client/ui/public/img/running_173.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mvp/client/ui/public/img/running_246.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mvp/client/ui/public/img/stopped.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions mvp/client/ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import { onMount } from "svelte";
import { Route, Router } from "svelte-navigator";
import { GameParametersService, OpenAPI } from "./api/generated/";
import { globalSettings } from "src/stores/stores";
import { isUndefinedOrNull } from "src/shared/utils";
import HomePage from "src/pages/HomePage.svelte";
import Spinner from "src/components/graphical/Spinner.svelte";
import { globalSettings } from "./stores/stores";
import { isUndefinedOrNull } from "./shared/utils";
import Preloader from "src/components/Preloader.svelte";
OpenAPI.BASE = import.meta.env.VITE_API_BASE;
Expand All @@ -25,6 +26,7 @@
</svelte:head>

<Router primary={false}>
<Preloader />
{#if isUndefinedOrNull($globalSettings)}
<div class="spinner-container">
<Spinner />
Expand Down
24 changes: 24 additions & 0 deletions mvp/client/ui/src/components/Preloader.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script lang="ts">
import {
RUNNING_MACHINE_SRC,
STOPPED_MACHINE_SRC,
} from "src/shared/constants";
</script>

<img
class="preload-image"
src={RUNNING_MACHINE_SRC}
alt="loading gif..."
width="0"
height="0"
hidden={true}
/>

<img
class="preload-image"
src={STOPPED_MACHINE_SRC}
alt="loading gif..."
width="0"
height="0"
hidden={true}
/>
8 changes: 5 additions & 3 deletions mvp/client/ui/src/components/graphical/MachineView.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<script lang="ts">
import { dayInProgress, gameOver, gameSession } from "src/stores/stores";
import { isUndefinedOrNull } from "src/shared/utils";
import runningMachineSrc from "/img/healthy.gif";
const stoppedMachineSrc = new URL("/img/stopped.PNG", import.meta.url).href;
import {
RUNNING_MACHINE_SRC,
STOPPED_MACHINE_SRC,
} from "src/shared/constants";
let stopAnimation = false;
Expand All @@ -13,7 +15,7 @@

<img
class="machine-view"
src={stopAnimation ? stoppedMachineSrc : runningMachineSrc}
src={stopAnimation ? STOPPED_MACHINE_SRC : RUNNING_MACHINE_SRC}
alt="..."
width="369"
height="276"
Expand Down
4 changes: 3 additions & 1 deletion mvp/client/ui/src/shared/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const SAMPLE_INTERVAL_MS = 100;
export const SAMPLE_INTERVAL_MS = 50;
export const RUNNING_MACHINE_SRC = "/img/running_246.gif"
export const STOPPED_MACHINE_SRC = "/img/stopped.gif"
6 changes: 3 additions & 3 deletions mvp/server/core/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Gameplay

DEFAULT_SESSION_ID = 'test'
GAME_TICK_INTERVAL = 0.05
GAME_TICK_INTERVAL = 0.03 # 30ms
IDLE_SESSION_TTL_SECONDS = 60 * 30 # 15 minutes
SESSION_CLEANUP_INTERVAL_SECONDS = 60 * 60 # 60 minutes
TIMESTEPS_PER_MOVE = 8 # we conceptualize every player move as a full working day, or "8 hours"
TIMESTEPS_PER_MOVE = 24 # we conceptualize every player move as a full working day, or "8 hours"
GAME_OVER_MESSAGE_MACHINE_BREAKDOWN = "Machine health has reached 0%"
GAME_OVER_MESSAGE_NO_MONEY = "Player ran out of money"

Expand All @@ -13,7 +13,7 @@
OIL_AGE_MAPPING_MAX = 365
TEMPERATURE_MAPPING_MAX = 100
MECHANICAL_WEAR_MAPPING_MAX = 1000
HEALTH_RECOVERY_FACTOR_ON_MAINTENANCE = 1.90
HEALTH_RECOVERY_FACTOR_ON_MAINTENANCE = 1.75
MECHANICAL_WEAR_REDUCTION_FACTOR_ON_MAINTENANCE = 100

# Financials
Expand Down
3 changes: 2 additions & 1 deletion mvp/server/core/game/GameSession.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import math
from datetime import datetime
from typing import Callable

Expand Down Expand Up @@ -81,7 +82,7 @@ async def advance_one_turn(self) -> list[MachineState]:
self.current_step += 1
self.machine_state.update_parameters(self.current_step)
# Player earns money for the production at every timestep
self.available_funds += REVENUE_PER_DAY / TIMESTEPS_PER_MOVE
self.available_funds += math.ceil(REVENUE_PER_DAY / TIMESTEPS_PER_MOVE)
self._log()

await asyncio.sleep(GAME_TICK_INTERVAL)
Expand Down
2 changes: 1 addition & 1 deletion mvp/server/core/machine/OperationalParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def compute_decay_speed(self) -> float:

computed = min(mapping_max, computed)

return map_value(computed, from_low=0, from_high=mapping_max, to_low=0, to_high=0.05)
return map_value(computed, from_low=0, from_high=mapping_max, to_low=0, to_high=0.005)

def compute_machine_temperature(self, current_timestep: int) -> float:
# temperature grows linearly over the 8 hours of a shift (resets every 8 hours)
Expand Down

0 comments on commit 01f84b9

Please sign in to comment.