Options
All
  • Public
  • Public/Protected
  • All
Menu

FGE - Functional Game Engine - v1.0.3

Index

Clock Type aliases

Routine Type aliases

Runner Type aliases

State Type aliases

Utility Type aliases

Clock Functions

Routine Functions

Runner Functions

State Functions

Clock Type aliases

Clock

Clock: { delta: number; elapsed: number; now: number; startedAt: number }

A basic clock

Type declaration

  • Readonly delta: number
  • Readonly elapsed: number
  • Readonly now: number
  • Readonly startedAt: number

Routine Type aliases

PatchRoutine

PatchRoutine<S, C>: (state: S, clock: C) => NestedPartial<S> | Promise<NestedPartial<S>>

A patch routine returns only the modifications to apply on the state

Type parameters

Type declaration

Routine

Routine<S, C>: (state: S, clock: C) => S | Promise<S>

A routine is launched by the runner, takes a state and a clock and returns a new reference to the state if updated

Type parameters

Type declaration

    • (state: S, clock: C): S | Promise<S>
    • Parameters

      • state: S
      • clock: C

      Returns S | Promise<S>

Runner Type aliases

Runner

Runner<S, C>: (state: S, routines: readonly Routine<S, C>[], clock: C) => Promise<RunnerReturnType<S, C>>

A runner takes a state and a clock, applies the routines on the state and updates the clock, creating new references in case of modifications

Type parameters

Type declaration

RunnerReturnType

RunnerReturnType<S, C>: readonly [state: S, clock: C]

A runner returns a tuple composed of the updated state and the updated clock

Type parameters

State Type aliases

AnyState

AnyState: Record<string, unknown>

Represents any state object

Utility Type aliases

NestedPartial

NestedPartial<T>: {}

Partial utility type for nested object fields

Type parameters

  • T

Type declaration

Clock Functions

Const createClock

  • Creates a basic clock

    Returns Clock

    A clock initialized with default values using Date API

Routine Functions

Const update

  • Helper to transform a patch routine into an usable routine

    Type parameters

    Parameters

    • patchRoutine: PatchRoutine<S, C>

      A routine returning only modifications to apply on the state

    Returns Routine<S, C>

    The patched state

Runner Functions

Const applyRoutines

  • applyRoutines<S, C>(state: S, routines: readonly Routine<S, C>[], clock: C): Promise<S>
  • Applies the routines' behaviors on the state

    Type parameters

    Parameters

    • state: S

      The state of the game

    • routines: readonly Routine<S, C>[]

      Behaviors to execute

    • clock: C

      Clock of the game

    Returns Promise<S>

    A promise containing the modified state

Const createVariableTimeStepRunner

  • createVariableTimeStepRunner<T>(minDelta: number, maxDelta: number): Runner<T, Clock>
  • Creates a runner with variable time delta clamped between two min-max values

    Type parameters

    Parameters

    • minDelta: number

      The min value for the delta

    • maxDelta: number

      The max value for the delta

    Returns Runner<T, Clock>

    A variable time step runner updating the clock each tick and applying routines' behaviors on the state

State Functions

patch

  • patch<S>(state: S, modifications: NestedPartial<S>): S
  • patch<S, R>(state: S, modifications: R): R
  • patch<S>(state: S, modifications: S): S
  • Deeply patches the state

    Type parameters

    Parameters

    • state: S

      State to patch

    • modifications: NestedPartial<S>

      Modification object, partially represents the state and can have nested fields

    Returns S

    The patched state

  • Type parameters

    • S: readonly unknown[]

    • R: S

    Parameters

    • state: S
    • modifications: R

    Returns R

  • Type parameters

    • S

    Parameters

    • state: S
    • modifications: S

    Returns S