hex-world
    Preparing search index...

    Class ResourceLayer

    Per-cell resources — ore, fish, forest yield — stored in the map's metadata channel and drawn as instanced camera-facing icons, one draw call per resource type.

    Like TerritoryLayer, the layer holds no cell state of its own: the data lives in HexMap.cellData, so it serializes with the map through serializeMap / serializeMapJSON / .hexpack with no companion file. The types themselves are descriptor-driven, so a pack can carry resources this library has never heard of.

    Rebuilds walk the sparse metadata store rather than the map, so cost scales with the number of deposits, not the size of the world. Mutations mark the layer dirty; call update once per frame or refresh straight after a batch.

    const resources = new ResourceLayer({
    parent: world.scene, layout: world.layout, map: () => world.map,
    descriptors: DEFAULT_RESOURCE_DESCRIPTORS,
    isWater: world.isWater, fogData,
    });
    generateResources(world.map, DEFAULT_RESOURCE_DESCRIPTORS, seed, { isWater: world.isWater });
    resources.refresh();
    Index

    Constructors

    Accessors

    Methods

    • The resource type id on a cell, or null if it has none.

      Parameters

      • col: number
      • row: number

      Returns string | null

    • The remaining quantity on a cell, or null when the cell has no resource or stores no amount (an undepletable deposit).

      Parameters

      • col: number
      • row: number

      Returns number | null

    • Place a resource on a cell. Pass an amount for deposits that deplete; omit it for permanent ones. Out-of-bounds cells are skipped.

      Parameters

      • col: number
      • row: number
      • type: string
      • Optionalamount: number

      Returns void

    • Change a cell's remaining quantity, removing the deposit when it runs out. No-op on cells with no resource. Returns the new amount, or null if the deposit was removed or the cell had nothing to deplete.

      Parameters

      • col: number
      • row: number
      • amount: number

      Returns number | null

    • Remove the resource from a cell.

      Parameters

      • col: number
      • row: number

      Returns void

    • Remove every resource from the map, optionally limited to one type.

      Parameters

      • Optionaltype: string

      Returns void

    • Attach or detach fog of war. Icons then hide on unexplored cells and dim on explored-but-unseen ones, exactly as the terrain and scatter beneath them do.

      Parameters

      Returns void

    • Match ChunkManager.setHideUnexplored so icons and ground agree.

      Parameters

      • enabled: boolean

      Returns void

    • Match ChunkManager.setDimExplored so icons and ground agree.

      Parameters

      • enabled: boolean

      Returns void

    • Show or hide the whole layer without discarding resource data.

      Parameters

      • visible: boolean

      Returns void

    • Rebuild only if something changed since the last build. Cheap to call every frame.

      Returns void

    • Remove the icon meshes and free their GPU resources. Resource data on the map, and any icon textures you supplied, are left alone.

      Returns void