Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ jobs:
chmod +x .tools/Godot_v${{ steps.godot-config.outputs.version }}-${{ steps.godot-config.outputs.status }}_linux.x86_64
./.tools/Godot_v${{ steps.godot-config.outputs.version }}-${{ steps.godot-config.outputs.status }}_linux.x86_64 --version

- name: Install Godot system dependencies
shell: bash
run: |
set -euo pipefail
sudo apt-get update && sudo apt-get install -y libfontconfig1

- name: Run headless smoke test
shell: bash
run: |
Expand Down
51 changes: 21 additions & 30 deletions scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const GoalProgression := preload("res://scripts/goal_progression.gd")
const GoalReward := preload("res://scripts/goal_reward.gd")
const RESOURCE_TRENDS := Constants.RESOURCE_TRENDS
const ColonyStance := preload("res://scripts/colony_stance.gd")
const TileRender := preload("res://scripts/tile_render.gd")


@onready var world_grid: GridContainer = %WorldGrid
Expand Down Expand Up @@ -2245,39 +2246,29 @@ func worker_texture(name: String, frame: int, carrying: String = "") -> Texture2
worker_texture_cache[cache_key] = texture
return texture

## Delegates to TileRender.tile_style, passing scene state via context.
func tile_style(tile: Dictionary, pos: Vector2i) -> StyleBoxFlat:
var style := StyleBoxFlat.new()
style.corner_radius_top_left = 8
style.corner_radius_top_right = 8
style.corner_radius_bottom_right = 8
style.corner_radius_bottom_left = 8
style.border_width_left = 2
style.border_width_top = 2
style.border_width_right = 2
style.border_width_bottom = 2
style.content_margin_left = 4
style.content_margin_top = 3
style.content_margin_right = 4
style.content_margin_bottom = 3
var kind := "stockpile" if pos == stockpile_pos else String(tile.kind)
style.bg_color = TILE_BACKDROPS.get(kind, Color("#1b2128"))
style.border_color = tile_accent(tile, pos)
style.shadow_color = Color(0, 0, 0, 0.25)
style.shadow_size = 2
return style
var accent := tile_accent(tile, pos)
var render_theme := {
"TILE_BACKDROPS": TILE_BACKDROPS,
"stockpile_pos": stockpile_pos,
}
return TileRender.tile_style(tile, pos, render_theme, accent)


## Delegates to TileRender.tile_accent, passing scene state via context.
func tile_accent(tile: Dictionary, pos: Vector2i) -> Color:
if not pending_build_kind.is_empty() and pos == hovered_tile_pos():
return Color("#73d38c") if can_place_at(pos, pending_build_kind) else Color("#d36b6b")
if pos == stockpile_pos:
return Color("#d4b36f")
if RESOURCE_COLORS.has(String(tile.resource)):
return RESOURCE_COLORS[String(tile.resource)]
if STRUCTURE_COLORS.has(String(tile.kind)):
return STRUCTURE_COLORS[String(tile.kind)]
if String(tile.kind) == "foundation":
return Color("#c7a25e")
return Color(1, 1, 1, 0.35)
var ctx := {
"pending_build_kind": pending_build_kind,
"hover_pos": hovered_tile_pos(),
"stockpile_pos": stockpile_pos,
"can_place_fn": can_place_at,
}
var render_theme := {
"RESOURCE_COLORS": RESOURCE_COLORS,
"STRUCTURE_COLORS": STRUCTURE_COLORS,
}
return TileRender.tile_accent(tile, pos, ctx, render_theme)

func task_name(worker: Dictionary) -> String:
if int(worker.get("break_ticks", 0)) > 0:
Expand Down
70 changes: 70 additions & 0 deletions scripts/tile_render.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## Pure tile rendering helpers — no scene references, fully testable.
## Consumes constants from constants.gd and a context dict from the caller.

class_name TileRender


## Returns a StyleBoxFlat for the given tile using the provided theme.
## `theme` must contain TILE_BACKDROPS (Dictionary of kind → Color).
static func tile_style(tile: Dictionary, pos: Vector2i, theme: Dictionary, accent_color: Color) -> StyleBoxFlat:
var style := StyleBoxFlat.new()
style.corner_radius_top_left = 8
style.corner_radius_top_right = 8
style.corner_radius_bottom_right = 8
style.corner_radius_bottom_left = 8
style.border_width_left = 2
style.border_width_top = 2
style.border_width_right = 2
style.border_width_bottom = 2
style.content_margin_left = 4
style.content_margin_top = 3
style.content_margin_right = 4
style.content_margin_bottom = 3

var kind := String(tile.kind)
if theme.has("stockpile_pos") and pos == theme["stockpile_pos"]:
kind = "stockpile"

style.bg_color = theme.get("TILE_BACKDROPS", {}).get(kind, Color("#1b2128"))
style.border_color = accent_color
style.shadow_color = Color(0, 0, 0, 0.25)
style.shadow_size = 2
return style


## Returns the accent (border) color for a tile based on context.
## `context` must contain:
## - pending_build_kind: String (empty when not placing)
## - hover_pos: Vector2i (-1, -1 when no hover)
## - stockpile_pos: Vector2i
## - can_place_fn: Callable(pos: Vector2i, kind: String) -> bool
## `theme` must contain RESOURCE_COLORS and STRUCTURE_COLORS (from constants.gd).
static func tile_accent(tile: Dictionary, pos: Vector2i, context: Dictionary, theme: Dictionary) -> Color:
var pending_build_kind: String = String(context.get("pending_build_kind", ""))
var hover_pos: Vector2i = Vector2i(context.get("hover_pos", Vector2i(-1, -1)))
var stockpile_pos: Vector2i = Vector2i(context.get("stockpile_pos", Vector2i(-1, -1)))
var can_place_fn: Callable = context.get("can_place_fn", func(_p: Vector2i, _k: String): return false)

# Build placement highlight
if not pending_build_kind.is_empty() and pos == hover_pos:
return Color("#73d38c") if can_place_fn.call(pos, pending_build_kind) else Color("#d36b6b")

# Stockpile accent
if pos == stockpile_pos:
return Color("#d4b36f")

# Resource accent
var resource_colors: Dictionary = theme.get("RESOURCE_COLORS", {})
if resource_colors.has(String(tile.resource)):
return resource_colors[String(tile.resource)]

# Structure accent
var structure_colors: Dictionary = theme.get("STRUCTURE_COLORS", {})
if structure_colors.has(String(tile.kind)):
return structure_colors[String(tile.kind)]

# Foundation accent
if String(tile.kind) == "foundation":
return Color("#c7a25e")

return Color(1, 1, 1, 0.35)
3 changes: 3 additions & 0 deletions smoke.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fontconfig error: Cannot load default config file: No such file: (null)
Godot Engine v4.2.2.stable.official.15073afe3 - https://godotengine.org

3 changes: 3 additions & 0 deletions smoke_ci.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
libfontconfig.so.1: cannot open shared object file: No such file or directory
Godot Engine v4.2.2.stable.official.15073afe3 - https://godotengine.org

Loading
Loading