Skip to content

⏱ Crafting — Runtime / Time

📦 Folder Overview

This folder documents the time abstractions used by the Crafting system.

Crafting separates gameplay time from wall-clock time:

  • game time via ITimeProvider (used while running)
  • wall-clock time via IWallClockProvider (used for offline logic)

This keeps runtime behaviour deterministic, testable, and independent of Unity static APIs.


🧩 What Lives Here

  • time provider abstractions used by Crafting
  • wall-clock provider contract and default implementation
  • helpers for selecting time modes

🎯 Purpose

These abstractions provide a consistent way to:

  • track job progress during runtime
  • compute elapsed time while offline
  • restore job state safely after reload

They separate runtime ticking from real-world time.


🧠 Usage Guidance

Game Time

Provided via ITimeProvider.

Used for:

  • job ticking
  • progress calculation
  • duration tracking

Time source is selected via CraftTimeMode.


Wall-Clock Time

Provided via IWallClockProvider.

Used for:

  • capturing timestamps
  • computing offline elapsed time
  • determining offline completion

If not assigned, the service uses a default implementation.


⚙️ Default Implementation

SystemWallClock

public sealed class SystemWallClock : IWallClockProvider
{
    public long UtcNowSeconds => System.DateTimeOffset.UtcNow.ToUnixTimeSeconds();
}
  • uses system UTC time
  • returns Unix epoch seconds
  • stateless and allocation-free

⚠️ Important Notes

  • wall-clock values should be non-negative UTC seconds
  • incorrect values may affect offline calculations
  • Crafting records timestamps rather than caching provider values

🚫 Not for Production Use

This folder does not include:

  • gameplay logic
  • scheduling rules
  • persistence systems

  • Crafting Core (job execution and persistence)
  • Crafting Contracts (job snapshots and state)

🧠 Design Notes

  • separates runtime and real-world time
  • supports offline progress without coupling to Unity APIs

If custom behaviour is required, provide your own time providers.