Record original-alignment implementation and traceability checkpoint

Capture current source, content data, tests, asset licenses, and original-specification traceability. Original implementation remains incomplete. The accepted matching UI generation passed 154 suites and 12,253 checks, with eight rendered staff-contract screens reviewed. Latest native Windows and full-original acceptance remain outstanding.
This commit is contained in:
Takeshi
2026-09-30 23:52:24 +09:00
parent 6077e02ebe
commit 5dde0c5ec2
490 changed files with 54051 additions and 809 deletions
+526 -114
View File
@@ -2,6 +2,7 @@ class_name WorldPreview
extends Control
signal facility_selected(instance_id: StringName)
signal staff_assignment_dropped(data: Dictionary, facility_id: StringName)
signal construction_selected(job_id: StringName)
signal legacy_stair_selected(stair_id: StringName)
signal cell_clicked(cell: Vector3i)
@@ -14,7 +15,12 @@ enum LayerMode {
BACK,
}
const RoomPresentation := preload("res://scripts/ui/room_presentation.gd")
const People := preload("res://scripts/ui/pixel_people.gd")
const PixelArt := preload("res://scripts/ui/pixel_tower_art.gd")
const InactiveLayerRooms := preload("res://scripts/ui/inactive_layer_rooms.gd")
const LAYER_LENS_SHADER := preload("res://assets/shaders/layer_lens.gdshader")
const LAYER_TRANSITION_SECONDS := 0.55
const MAP_PADDING := Vector2(76.0, 70.0)
const INVALID_PREVIEW := {&"can_build": false, &"error_codes": [], &"reasons": [], &"cells": []}
const INVALID_EXCAVATION_PREVIEW := {
@@ -27,7 +33,10 @@ const INVALID_EXCAVATION_PREVIEW := {
var layer_mode := LayerMode.FRONT:
set(value):
var previous := layer_mode
layer_mode = clampi(value, LayerMode.FRONT, LayerMode.BACK) as LayerMode
if previous != layer_mode and is_node_ready():
_start_layer_transition()
if _hovered_cell != null:
_hovered_cell = Vector3i(_hovered_cell.x, _hovered_cell.y, layer_mode)
queue_redraw()
@@ -47,12 +56,29 @@ var visual_theme: VisualThemeProfile = null
var zoom_level := 1.0
var pan_offset := Vector2.ZERO
var show_grid := false
var pan_mode := false
var _drawing := false
var _draw_cache: Dictionary = {}
var _inactive_layer_art: Node2D
var _layer_lens: ColorRect
var _layer_transition_elapsed := LAYER_TRANSITION_SECONDS
var _animation_time := 0.0
var _animation_frame := -1
var _actor_tracks: Dictionary = {}
var _elevator_tracks: Dictionary = {}
var _boarded_actor_ids: Dictionary = {}
var _carried_patients: Dictionary = {}
var _treated_patients: Dictionary = {}
var _resting_staff: Dictionary = {}
var _room_presentations: Dictionary = {}
var _queue_positions: Dictionary = {}
var _queue_hidden: Dictionary = {}
var _landing_badges: Array[Dictionary] = []
var _transport_report: Dictionary = {}
var _dragging := false
var _drag_button := MOUSE_BUTTON_NONE
var _runtime: Variant = null
var _hovered_cell: Variant = null
@@ -70,6 +96,18 @@ func _ready() -> void:
if _runtime == null:
_runtime = get_node_or_null("/root/SimulationRuntime")
_connect_runtime()
_inactive_layer_art = InactiveLayerRooms.new()
_inactive_layer_art.name = "InactiveLayerRooms"
add_child(_inactive_layer_art)
_layer_lens = ColorRect.new()
_layer_lens.name = "LayerLens"
_layer_lens.mouse_filter = Control.MOUSE_FILTER_IGNORE
_layer_lens.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
var lens_material := ShaderMaterial.new()
lens_material.shader = LAYER_LENS_SHADER
_layer_lens.material = lens_material
_layer_lens.visible = false
add_child(_layer_lens)
queue_redraw()
@@ -173,6 +211,8 @@ func get_build_preview_report(cell: Variant = null) -> Dictionary:
func get_map_rect() -> Rect2:
if _drawing and _draw_cache.has(&"rect"):
return _draw_cache[&"rect"]
var bounds := _world_bounds()
if bounds.is_empty():
return Rect2()
@@ -181,10 +221,16 @@ func get_map_rect() -> Rect2:
int(bounds[&"max_x"]) - int(bounds[&"min_x"]) + 1,
int(bounds[&"max_y"]) - int(bounds[&"min_y"]) + 1
) * dimensions
return Rect2(((size - map_size) * 0.5 + pan_offset).floor(), map_size)
var result_value = Rect2(((size - map_size) * 0.5 + pan_offset).floor(), map_size)
if _drawing:
_draw_cache[&"rect"] = result_value
return result_value
func _cell_dimensions() -> Vector2:
if _drawing and _draw_cache.has(&"dimensions"):
return _draw_cache[&"dimensions"]
var bounds := _world_bounds()
if bounds.is_empty():
return Vector2(32, 48)
@@ -195,7 +241,11 @@ func _cell_dimensions() -> Vector2:
# Native 16px units use integer magnification. Large worlds can be viewed
# at overview scale, then enlarged with the same invertible camera mapping.
var pixel := maxf(floorf(fit), 1.0) if fit >= 1.0 else maxf(fit, 0.25)
return (Vector2(16, 24) * pixel * zoom_level).round().max(Vector2(4, 6))
var result_value = (Vector2(16, 24) * pixel * zoom_level).round().max(Vector2(4, 6))
if _drawing:
_draw_cache[&"dimensions"] = result_value
return result_value
func set_zoom(value: float, anchor := Vector2(-1, -1)) -> void:
@@ -217,12 +267,77 @@ func reset_view() -> void:
queue_redraw()
func focus_operating_area() -> void:
# Explicit framing, never continuous tracking: the player's pan stays put.
zoom_level = 1.0
pan_offset = Vector2.ZERO
var area := Rect2()
var construction: Variant = _service(&"construction_service")
if construction != null:
for item: Dictionary in construction.get_facilities():
if int(item.get(&"layer", 0)) != layer_mode:
continue
var cells := _cells_from_serialized(item.get(&"occupied_cells", []))
if cells.is_empty():
continue
var rect := _cell_bounds_rect(cells)
area = area.merge(rect) if area.has_area() else rect
if area.has_area():
var relative := (area.get_center()-get_map_rect().position) / get_map_rect().size
zoom_level = clampf(minf(size.x*0.68/area.size.x, size.y*0.65/area.size.y), 0.5, 2.0)
var rect := get_map_rect()
pan_offset += size*Vector2(0.5, 0.58) - (rect.position+rect.size*relative)
else:
zoom_level = 2.0
pan_offset += size*Vector2(0.5, 0.65) - cell_to_canvas(Vector3i(0, 1, layer_mode))
_clamp_pan()
clear_hovered_cell()
queue_redraw()
func set_pan_mode(enabled: bool) -> void:
pan_mode = enabled
_end_pan_drag()
clear_hovered_cell()
func _end_pan_drag() -> void:
_dragging = false
_drag_button = MOUSE_BUTTON_NONE
mouse_default_cursor_shape = Control.CURSOR_DRAG if pan_mode else Control.CURSOR_ARROW
func _notification(what: int) -> void:
if what == NOTIFICATION_APPLICATION_FOCUS_OUT:
_end_pan_drag()
func _clamp_pan() -> void:
var extent := get_map_rect().size * 0.5 + size * 0.3
pan_offset = pan_offset.clamp(-extent, extent)
func _start_layer_transition() -> void:
if _layer_lens == null: return
_layer_transition_elapsed = 0.0
var center := size * 0.5
if _hovered_cell != null:
center = cell_to_canvas(_hovered_cell)
var lens_material := _layer_lens.material as ShaderMaterial
lens_material.set_shader_parameter("center", center / size.max(Vector2.ONE))
lens_material.set_shader_parameter("extent", size)
lens_material.set_shader_parameter("progress", 0.0)
_layer_lens.visible = true
func _process(delta: float) -> void:
# UI transitions complete even in active pause; actor time remains frozen.
if _layer_lens != null and _layer_lens.visible:
_layer_transition_elapsed = minf(_layer_transition_elapsed + maxf(delta, 0.0), LAYER_TRANSITION_SECONDS)
var lens_material := _layer_lens.material as ShaderMaterial
lens_material.set_shader_parameter("extent", size)
lens_material.set_shader_parameter("progress", _layer_transition_elapsed / LAYER_TRANSITION_SECONDS)
_layer_lens.visible = _layer_transition_elapsed < LAYER_TRANSITION_SECONDS
var clock := get_node_or_null("/root/GameClock")
if clock != null and bool(clock.get("paused")):
return
@@ -294,9 +409,15 @@ func facility_at_canvas(canvas_position: Vector2) -> StringName:
func _gui_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_MIDDLE:
_dragging = event.pressed
mouse_default_cursor_shape = Control.CURSOR_DRAG if _dragging else Control.CURSOR_ARROW
if not event.pressed and event.button_index == _drag_button:
_end_pan_drag()
accept_event()
return
if event.button_index == MOUSE_BUTTON_MIDDLE or (pan_mode and event.button_index == MOUSE_BUTTON_LEFT):
if event.pressed:
_dragging = true
_drag_button = event.button_index
mouse_default_cursor_shape = Control.CURSOR_DRAG
accept_event()
return
if event.pressed and event.button_index in [MOUSE_BUTTON_WHEEL_UP, MOUSE_BUTTON_WHEEL_DOWN]:
@@ -304,13 +425,18 @@ func _gui_input(event: InputEvent) -> void:
accept_event()
return
if event is InputEventMouseMotion and _dragging:
var mask := MOUSE_BUTTON_MASK_LEFT if _drag_button == MOUSE_BUTTON_LEFT else MOUSE_BUTTON_MASK_MIDDLE
if not event.button_mask & mask:
_end_pan_drag()
return
pan_offset += event.relative
_clamp_pan()
queue_redraw()
accept_event()
return
if event is InputEventMouseMotion:
_set_hovered_cell(canvas_to_cell(event.position))
if not pan_mode:
_set_hovered_cell(canvas_to_cell(event.position))
return
if not event is InputEventMouseButton or not event.pressed or event.button_index != MOUSE_BUTTON_LEFT:
return
@@ -348,6 +474,16 @@ func _gui_input(event: InputEvent) -> void:
func _draw() -> void:
_drawing = true
_draw_cache.clear()
_draw_contents()
_drawing = false
_draw_cache.clear()
func _draw_contents() -> void:
if _inactive_layer_art != null:
_inactive_layer_art.visible = false
_draw_background()
var bounds := _world_bounds()
if bounds.is_empty():
@@ -359,12 +495,14 @@ func _draw() -> void:
_draw_world_cells(bounds, map_rect)
if show_grid:
_draw_congestion_overlay(bounds)
_prepare_room_presentations()
_prepare_queues()
_draw_world_entity_icons()
_draw_legacy_stairs()
_draw_elevators()
_draw_other_layer()
_draw_construction_labels()
_draw_facility_labels()
_draw_queue_badges()
_draw_actors()
_draw_excavation_jobs()
_draw_build_preview()
@@ -519,6 +657,79 @@ func _draw_congestion_overlay(bounds: Dictionary) -> void:
draw_line(Vector2(rect.end.x, rect.position.y), Vector2(rect.position.x, rect.end.y), color, 2.0)
func _completed_facilities_for_draw() -> Array:
if _drawing and _draw_cache.has(&"completed_facilities"):
return _draw_cache[&"completed_facilities"]
var construction: Variant = _service(&"construction_service")
var facilities: Array = construction.get_facilities() if construction != null else []
if _drawing:
_draw_cache[&"completed_facilities"] = facilities
return facilities
func _construction_jobs_for_draw() -> Array:
if _drawing and _draw_cache.has(&"construction_jobs"):
return _draw_cache[&"construction_jobs"]
var construction: Variant = _service(&"construction_service")
var jobs: Array = construction.get_jobs() if construction != null else []
if _drawing:
_draw_cache[&"construction_jobs"] = jobs
return jobs
func _other_layer_rooms() -> Array[Dictionary]:
var rooms: Array[Dictionary] = []
for facility: Dictionary in _completed_facilities_for_draw():
if int(facility.get(&"layer", 0)) == layer_mode: continue
var cells := _cells_from_serialized(facility.get(&"occupied_cells", []))
if cells.is_empty(): continue
var rect := _cell_bounds_rect(cells)
if rect.intersects(Rect2(Vector2.ZERO, size)):
rooms.append({&"id": facility[&"instance_id"], &"rect": rect, &"definition_id": facility[&"definition_id"], &"origin_x": cells[0].x})
for job: ConstructionJob in _construction_jobs_for_draw():
if job.layer == layer_mode or job.state in [ConstructionJob.State.COMPLETED, ConstructionJob.State.CANCELLED]: continue
if job.reserved_cells.is_empty(): continue
var rect := _cell_bounds_rect(job.reserved_cells)
if rect.intersects(Rect2(Vector2.ZERO, size)):
rooms.append({&"id":job.job_id, &"rect":rect, &"definition_id":job.definition_id,
&"origin_x":job.origin.x, &"building":true, &"progress":job.progress})
for stair: Dictionary in get_legacy_stair_records():
var upper: Vector3i = stair[&"to"] if stair[&"to"].y > stair[&"from"].y else stair[&"from"]
if upper.z == layer_mode: continue
var rect := _legacy_stair_rect(upper)
if rect.intersects(Rect2(Vector2.ZERO,size)):
rooms.append({&"id":stair[&"id"], &"rect":rect, &"legacy_stair":true,
&"definition_id":&"service_stairs" if upper.z==LayerMode.BACK else &"guest_stairs", &"origin_x":upper.x})
return rooms
func _draw_other_layer() -> void:
# Opposite-layer footprints are visual context only. Hit testing still uses
# the selected layer's WorldService occupancy, including overlapping rooms.
var rooms := _other_layer_rooms()
if _inactive_layer_art != null:
_inactive_layer_art.visible = layer_mode == LayerMode.FRONT
_inactive_layer_art.set("rooms", rooms)
_inactive_layer_art.set("pixel_scale", _cell_dimensions().x / 16.0)
_inactive_layer_art.set("dungeon", visual_theme.pixel_dungeon_tiles if visual_theme != null else null)
_inactive_layer_art.set("town", visual_theme.pixel_town_tiles if visual_theme != null else null)
_inactive_layer_art.queue_redraw()
for room: Dictionary in rooms:
var rect: Rect2 = room[&"rect"]
if bool(room.get(&"building", false)):
var color := Color(0.95,0.76,0.35,0.45)
draw_rect(rect.grow(-2),color,false,1.0)
_draw_hatch(rect.grow(-3),Color(color,0.24),_cell_dimensions().x)
_draw_readable_badge(rect.position+Vector2(3,3),"%s 工事%d%%" % ["裏" if layer_mode==LayerMode.FRONT else "表",clampi(int(room[&"progress"])/100,0,100)])
continue
if layer_mode == LayerMode.FRONT:
draw_rect(rect.grow(-2), Color(0.6, 0.87, 0.9, 0.45), false, 1.0)
else:
var color := Color(0.94, 0.83, 0.54, 0.55)
draw_rect(rect.grow(-2), color, false, 1.0)
draw_line(rect.position+Vector2(3,3), rect.end-Vector2(3,3), Color(color,0.2), 1.0)
func _draw_world_entity_icons() -> void:
var construction: Variant = _service(&"construction_service")
if construction == null or not construction.has_method(&"get_facilities"):
@@ -526,7 +737,7 @@ func _draw_world_entity_icons() -> void:
var p := _cell_dimensions().x / 16.0
var dungeon := visual_theme.pixel_dungeon_tiles if visual_theme != null else null
var town := visual_theme.pixel_town_tiles if visual_theme != null else null
for value: Variant in construction.call(&"get_facilities"):
for value: Variant in _completed_facilities_for_draw():
if not value is Dictionary or int(value.get(&"layer",0)) != layer_mode:
continue
var facility: Dictionary = value
@@ -537,15 +748,144 @@ func _draw_world_entity_icons() -> void:
if not rect.intersects(Rect2(Vector2.ZERO,size)):
continue
var id := StringName(facility.get(&"definition_id",&""))
PixelArt.room(self,rect,id,p,dungeon,town,layer_mode==LayerMode.BACK,cells[0].x)
PixelArt.room(self,rect,id,p,dungeon,town,layer_mode==LayerMode.BACK,cells[0].x, _room_presentations.get(StringName(facility.get(&"instance_id", &"")), {}))
var instance_id := StringName(facility.get(&"instance_id",&""))
# Thin status lamp conveys operational state without repainting a room.
draw_rect(Rect2(rect.end.x-4*p,rect.position.y+2*p,2*p,2*p),_facility_color(instance_id))
if instance_id==selected_entity_id:
draw_rect(rect.grow(-p),Color("f5d582"),false,2*p)
var data: Dictionary = _room_presentations.get(instance_id, {})
if not data.is_empty() and (rect.size.x >= 80 or instance_id == selected_entity_id) and id not in [&"guest_corridor", &"service_corridor", &"guest_stairs", &"service_stairs", &"guest_elevator", &"service_elevator"]:
var status := RoomPresentation.label(data, RoomPresentation.slots(rect, p, id).size())
_draw_readable_badge(rect.position+Vector2(2, 2), status.replace("利用", "治療") if id == &"infirmary" else status.replace("利用", "休憩") if id in [&"staff_waiting_room", &"staff_dormitory"] else status)
func _draw_readable_badge(at: Vector2, text: String) -> void:
var width := ThemeDB.fallback_font.get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, 10).x+6
var rect := Rect2(at, Vector2(width, 14))
if not rect.intersects(Rect2(Vector2.ZERO, size)):
return
draw_rect(rect, Color("34413b", 0.94))
draw_string(ThemeDB.fallback_font, at+Vector2(3, 11), text, HORIZONTAL_ALIGNMENT_LEFT, -1, 10, Color("fff2ce"))
func _prepare_room_presentations() -> void:
_room_presentations.clear()
_carried_patients.clear()
_treated_patients.clear()
_resting_staff.clear()
var service: Variant = _service(&"facility_service")
if service == null:
return
for instance: Variant in service.get_instances():
if instance.origin.z == layer_mode:
_room_presentations[instance.instance_id] = RoomPresentation.describe(instance)
var staff: Variant = _service(&"staff_service")
if staff != null:
if _runtime is Object and _runtime.has_method("get_staff_rest_report"):
for member: StaffRuntime in staff.get_staff_members():
if member.state != StaffRuntime.State.OFF_DUTY: continue
var rest: Dictionary = _runtime.get_staff_rest_report(member.staff_id)
if not rest.get(&"resting", false): continue
_resting_staff[member.staff_id] = rest[&"facility_id"]
var room: Dictionary = _room_presentations.get(rest[&"facility_id"], {})
if not room.is_empty():
room[&"people"].append(member.staff_id)
room[&"count"] += 1
for task: StaffTask in staff.get_tasks():
if task.task_type != &"rescue_transport" or task.is_terminal() or task.assigned_staff_id.is_empty(): continue
if task.state == StaffTask.State.WORKING:
_treated_patients[task.target_entity_id] = task.rescue_facility_id
var data: Dictionary = _room_presentations.get(task.rescue_facility_id, {})
if not data.is_empty():
data[&"people"].append(task.target_entity_id)
data[&"count"] += 1
else:
_carried_patients[task.target_entity_id] = task.assigned_staff_id
func _prepare_queues() -> void:
_queue_positions.clear()
_queue_hidden.clear()
_landing_badges.clear()
_transport_report.clear()
var groups: Dictionary = {}
var facilities: Variant = _service(&"facility_service")
var guests: Variant = _service(&"guest_service")
if facilities != null and guests != null:
for instance: Variant in facilities.get_instances():
for request_id: StringName in instance.queue_entries:
var request: Variant = facilities.get_request(request_id)
if request == null:
continue
for guest_id: StringName in request.guest_ids:
var guest: Variant = guests.get_guest(guest_id)
if guest != null and guest.state == GuestRuntime.State.QUEUING:
_add_queue_member(groups, "guest/"+String(guest_id), guest.current_cell)
var transport: Variant = _service(&"elevators")
if transport != null:
_transport_report = transport.get_report()
var trips: Array = _transport_report.get(&"trips", [])
trips.sort_custom(func(a: Dictionary, b: Dictionary) -> bool: return int(a[&"enqueued_at"]) < int(b[&"enqueued_at"]) or (a[&"enqueued_at"] == b[&"enqueued_at"] and String(a[&"actor_id"]) < String(b[&"actor_id"])))
for trip: Dictionary in trips:
if trip[&"state"] == PathService.ELEVATOR_REQUEST_QUEUED:
var cell: Variant = trip[&"from"]
if cell is Array:
cell = Vector3i(cell[0], cell[1], cell[2])
_add_queue_member(groups, _elevator_actor_key(String(trip[&"actor_id"])), cell)
var lift_cells: Dictionary = {}
for shaft: Dictionary in _transport_report.get(&"shafts", []):
for stop: Vector3i in _cells_from_serialized(shaft.get(&"stops", [])):
lift_cells[stop] = true
var reserved: Dictionary = {}
var cells: Array = groups.keys()
cells.sort_custom(func(a: Vector3i, b: Vector3i) -> bool: return a.y < b.y or (a.y == b.y and a.x < b.x))
for cell: Vector3i in cells:
var members: Array = groups[cell]
var lane: Array[Vector3i] = []
if not lift_cells.has(cell):
lane.append(cell)
var world: Variant = _service(&"world_service")
for direction: int in [-1, 1]:
for distance: int in range(1, 9):
var next := cell + Vector3i(direction*distance, 0, 0)
if world == null or not world.is_walkable(next):
break
var occupant: StringName = world.get_occupant(next)
var facility: Variant = facilities.get_instance(occupant) if facilities != null else null
if facility != null and facility.definition_id not in [&"guest_corridor", &"service_corridor"]:
break
lane.append(next)
var index := 0
for target: Vector3i in lane:
if index >= members.size():
break
if reserved.has(target):
continue
reserved[target] = true
_queue_positions[members[index]] = cell_to_canvas(target)
index += 1
for hidden: int in range(index, members.size()):
_queue_hidden[members[hidden]] = true
var text := "待ち%d人" % members.size()
if index < members.size():
text += "(他%d人)" % (members.size()-index)
_landing_badges.append({&"at": get_cell_rect(cell).position + Vector2(-80 if lift_cells.has(cell) else 0, -16), &"text": text})
func _add_queue_member(groups: Dictionary, key: String, cell: Vector3i) -> void:
if cell.z != layer_mode:
return
if not groups.has(cell):
groups[cell] = []
if not groups[cell].has(key):
groups[cell].append(key)
func get_legacy_stair_records() -> Array[Dictionary]:
if _drawing and _draw_cache.has(&"legacy_stair_records"):
return _draw_cache[&"legacy_stair_records"]
var result: Array[Dictionary] = []
var service: Variant = _service(&"legacy_stairs")
if service == null or not service.has_method(&"create_snapshot"):
@@ -560,6 +900,8 @@ func get_legacy_stair_records() -> Array[Dictionary]:
var connector: Dictionary = path.call(&"get_connector", StringName(row[&"id"])) if path != null else {}
record[&"access_id"] = connector.get(&"access_id", &"")
result.append(record)
if _drawing:
_draw_cache[&"legacy_stair_records"] = result
return result
@@ -601,21 +943,6 @@ func _cell_bounds_rect(cells: Array[Vector3i]) -> Rect2:
return result
func _draw_queue_badges() -> void:
var service: Variant = _service(&"facility_service")
if service==null or not service.has_method(&"get_instances"):
return
for instance: Variant in service.call(&"get_instances"):
if instance==null or instance.origin.z!=layer_mode or instance.queue_entries.is_empty():
continue
var count: int = instance.queue_entries.size()
var rect := get_cell_rect(instance.origin)
var at := Vector2(rect.position.x+3,rect.position.y+3)
draw_rect(Rect2(at,Vector2(30,15)),Color("76593f"))
draw_rect(Rect2(at+Vector2.ONE,Vector2(28,13)),Color("bb974e"))
draw_string(ThemeDB.fallback_font,at+Vector2(3,11),"待%d" % count,HORIZONTAL_ALIGNMENT_LEFT,-1,10,Color("fff2ce"))
func _draw_hatch(rect: Rect2, color: Color, cell_size: float) -> void:
if cell_size < 8.0:
return
@@ -632,7 +959,7 @@ func _draw_construction_labels() -> void:
if construction == null or not construction.has_method(&"get_jobs"):
return
var font := ThemeDB.fallback_font
for job: Variant in construction.call(&"get_jobs"):
for job: Variant in _construction_jobs_for_draw():
if job == null or int(job.layer) != layer_mode or int(job.state) in [2, 3]:
continue
var rect := get_cell_rect(job.origin)
@@ -647,7 +974,7 @@ func _draw_facility_labels() -> void:
var registry: Variant = _service(&"definition_registry")
if construction == null or not construction.has_method(&"get_facilities"):
return
for value: Variant in construction.call(&"get_facilities"):
for value: Variant in _completed_facilities_for_draw():
if not value is Dictionary or int(value.get(&"layer",0))!=layer_mode:
continue
var facility: Dictionary = value
@@ -677,7 +1004,7 @@ func _draw_elevators() -> void:
if transport == null or not transport.has_method(&"get_report"):
_elevator_tracks.clear()
return
var report_value: Variant = transport.call(&"get_report")
var report_value: Variant = _transport_report
if not report_value is Dictionary:
return
var alive: Dictionary = {}
@@ -708,7 +1035,8 @@ func _draw_elevators() -> void:
var phase := StringName(shaft.get(&"phase", &"IDLE"))
var doors_open := operational and phase in [&"IDLE", &"BOARDING", &"ALIGHTING"]
PixelArt.elevator_cabin(self,cabin,p,layer_mode==LayerMode.BACK,operational)
var visible_count := mini(passengers.size(), maxi(width*2-1,1))
var seat_columns := maxi(int((cabin.size.x / p - 4.0) / 8.0), 1)
var visible_count := mini(passengers.size(), seat_columns*2)
for index: int in range(visible_count):
var actor_key := _elevator_actor_key(String(passengers[index]))
var is_staff := actor_key.begins_with("staff/")
@@ -719,17 +1047,21 @@ func _draw_elevators() -> void:
person = people.call(getter,StringName(actor_key.get_slice("/",1)))
var carrying := is_staff and person != null and not String(person.carried_inventory_id).is_empty()
var state := int(person.state) if person != null else 0
var x := cabin.position.x+5*p+float(index)*(cabin.size.x-10*p)/maxf(float(visible_count-1),1.0)
if visible_count == 1:
x = cabin.get_center().x
var center := Vector2(x,cabin.end.y-_cell_dimensions().y*0.5)
var x := cabin.position.x + (2.0 + (index % seat_columns + 0.5)*8.0)*p
var feet := cabin.end.y - (2.0 + int(index / seat_columns)*9.0)*p
var center := Vector2(x, feet+3*p-_cell_dimensions().y*0.5)
_draw_pixel_actor(center,actor_key,is_staff,state,false,carrying,&"",true)
PixelArt.elevator_gate(self,cabin,p,doors_open)
var waiting := int(shaft.get(&"waiting_count",0))
if waiting > 0:
var badge := Vector2(cabin.end.x+2*p,cabin.position.y+2*p)
draw_rect(Rect2(badge,Vector2(20,12)*p),Color("76593f"))
draw_string(ThemeDB.fallback_font,badge+Vector2(2,9)*p,"待%d" % waiting,HORIZONTAL_ALIGNMENT_LEFT,-1,clampi(int(7*p),8,13),Color("f6e8bc"))
var capacity := int(shaft.get(&"capacity", 0))
var load_text := "%d/%d人" % [passengers.size(), capacity]
if capacity > 0 and passengers.size() >= capacity:
load_text = "満員 " + load_text
if not operational:
load_text = "停止 " + load_text
_draw_readable_badge(Vector2(cabin.position.x, cabin.position.y-14), load_text)
for badge: Dictionary in _landing_badges:
_draw_readable_badge(badge[&"at"], badge[&"text"])
for shaft_id: Variant in _elevator_tracks.keys():
if not alive.has(shaft_id):
_elevator_tracks.erase(shaft_id)
@@ -769,14 +1101,18 @@ func _draw_actors() -> void:
continue
var key := "guest/"+String(guest.guest_id)
alive[key] = true
if _boarded_actor_ids.has(key):
if _boarded_actor_ids.has(key) or _queue_hidden.has(key):
_actor_tracks.erase(key)
continue
var position := _tracked_actor_position(key,guest.current_cell)
if guest.current_cell.z==layer_mode:
var receiving := not String(guest.current_service_id).is_empty()
if receiving:
if _queue_positions.has(key):
position = _queue_positions[key]
elif receiving:
position = _service_use_position(guest,position,service_slots)
if not position.is_finite():
continue
else:
position += _actor_offset(guest.current_cell,counts)
_draw_pixel_actor(position,key,false,int(guest.state),receiving,false,_guest_activity(guest))
@@ -787,17 +1123,70 @@ func _draw_actors() -> void:
continue
var key := "staff/"+String(staff.staff_id)
alive[key] = true
if _boarded_actor_ids.has(key):
if _boarded_actor_ids.has(key) or _queue_hidden.has(key):
_actor_tracks.erase(key)
continue
var position := _tracked_actor_position(key,staff.current_cell)
if staff.current_cell.z==layer_mode:
_draw_pixel_actor(position+_actor_offset(staff.current_cell,counts),key,true,int(staff.state),false,not String(staff.carried_inventory_id).is_empty(),staff.role_id)
if _carried_patients.has(staff.staff_id):
var carrier: Variant = staff_service.get_staff(_carried_patients[staff.staff_id])
if carrier != null:
position = _tracked_actor_position("staff/"+String(carrier.staff_id), carrier.current_cell) - Vector2(0, 12*_cell_dimensions().x/16.0)
_draw_pixel_actor(position,key,true,int(staff.state),false,false)
continue
if _resting_staff.has(staff.staff_id):
position = _resting_staff_position(staff.staff_id, position)
if position.is_finite(): _draw_pixel_actor(position,key,true,int(staff.state),false,false)
continue
if _treated_patients.has(staff.staff_id):
position = _rescue_treatment_position(staff.staff_id, position)
if position.is_finite(): _draw_pixel_actor(position,key,true,int(staff.state),false,false)
continue
_draw_pixel_actor(_queue_positions.get(key, _staff_work_position(staff, position+_actor_offset(staff.current_cell,counts))),key,true,int(staff.state),false,not String(staff.carried_inventory_id).is_empty(),_staff_work_animation(staff))
for key: Variant in _actor_tracks.keys():
if not alive.has(key):
_actor_tracks.erase(key)
func _staff_work_animation(staff: StaffRuntime) -> StringName:
if staff.role_id != &"cleaner":
return &"work"
# A staffed base is not a cleaning site. Animate only a live job at its
# authoritative destination, including after load and interruption.
var service: Variant = _service(&"staff_service")
var bridge: Variant = _service(&"cleaning_bridge")
var task: StaffTask = service.get_task(staff.current_task_id) if service != null else null
if staff.state == StaffRuntime.State.WORKING and task != null and task.task_type == FacilityCleaningBridge.TASK_TYPE and task.state == StaffTask.State.WORKING and bridge != null and bridge.task_can_work(task, staff):
return &"clean"
return &"idle"
func _staff_work_position(staff: Variant, fallback: Vector2) -> Vector2:
if staff.state not in [StaffRuntime.State.WORKING, StaffRuntime.State.AVAILABLE]:
return fallback
var service: Variant = _service(&"facility_service")
var facility: Variant = service.get_instance(staff.assigned_facility_id) if service != null else null
if facility == null:
return fallback
var world: Variant = _service(&"world_service")
var cells: Array[Vector3i] = world.get_entity_cells(staff.assigned_facility_id) if world != null else []
if not cells.has(staff.current_cell):
return fallback
var data: Dictionary = _room_presentations.get(staff.assigned_facility_id, {})
var workers: Array = data.get(&"staff", [])
var slot := workers.find(staff.staff_id)
if slot < 0:
return fallback
var rect := _cell_bounds_rect(cells)
var p := _cell_dimensions().x / 16.0
if rect.size.y < 40*p:
return fallback
var columns := maxi(int(rect.size.x / (16*p)), 1)
if slot >= columns:
return fallback
return Vector2(rect.position.x+(slot+0.5)*rect.size.x/columns, rect.position.y+26*p-_cell_dimensions().y*0.5)
func _tracked_actor_position(key: String, cell: Vector3i) -> Vector2:
if not _actor_tracks.has(key):
_actor_tracks[key] = {&"cell":cell,&"from":cell,&"at":_animation_time,&"direction":1.0}
@@ -817,7 +1206,7 @@ func _tracked_actor_position(key: String, cell: Vector3i) -> Vector2:
return cell_to_canvas(track[&"from"]).lerp(cell_to_canvas(cell),t)
func _service_use_position(guest: Variant, fallback: Vector2, slots: Dictionary) -> Vector2:
func _service_use_position(guest: Variant, fallback: Vector2, _slots: Dictionary) -> Vector2:
# Guest paths stop at an access cell. While a service is active, project the
# occupant into that facility's use position; authoritative paths stay intact.
var id := StringName(guest.target_facility_id)
@@ -828,11 +1217,19 @@ func _service_use_position(guest: Variant, fallback: Vector2, slots: Dictionary)
if cells.is_empty() or cells[0].z!=layer_mode:
return fallback
var rect := _cell_bounds_rect(cells)
var slot := int(slots.get(id,0))
slots[id] = slot+1
var data: Dictionary = _room_presentations.get(id, {})
var slot := (data.get(&"people", []) as Array).find(guest.guest_id)
if slot < 0:
return fallback
var p := _cell_dimensions().x/16.0
var x := rect.position.x+minf(9.0+float(slot%4)*14.0,rect.size.x/p-5.0)*p
return Vector2(x,rect.end.y-_cell_dimensions().y*0.5)
var anchors := RoomPresentation.slots(rect, p, _guest_activity(guest))
if slot >= anchors.size():
return Vector2(INF, INF)
var at := anchors[slot]
if _guest_activity(guest) in [&"standard_room", &"premium_room"]:
at.y -= 5*p
return at + Vector2(0, 3*p-_cell_dimensions().y*0.5)
func _guest_activity(guest: Variant) -> StringName:
@@ -844,67 +1241,34 @@ func _guest_activity(guest: Variant) -> StringName:
func _draw_pixel_actor(center: Vector2, key: String, staff: bool, state: int, receiving: bool, carrying: bool, activity: StringName = &"", riding := false) -> void:
var texture := visual_theme.pixel_dungeon_tiles if visual_theme != null else null
if texture==null:
return
var world_pixel := _cell_dimensions().x/16.0
var p := maxf(floorf(world_pixel*0.5),1.0) if world_pixel>=1.0 else world_pixel
var track: Dictionary = _actor_tracks.get(key,{})
var moving: bool = track.get(&"cell",Vector3i.ZERO)!=track.get(&"from",Vector3i.ZERO) and _animation_time-float(track.get(&"at",0.0))<0.42
var world_pixel := _cell_dimensions().x / 16.0
var scale := 0.5 if riding else 0.75
var p := maxf(floorf(world_pixel * scale), 1.0) if world_pixel >= 2.0 else world_pixel * scale
var track: Dictionary = _actor_tracks.get(key, {})
var moving: bool = not receiving and not _queue_positions.has(key) and track.get(&"cell", Vector3i.ZERO) != track.get(&"from", Vector3i.ZERO) and _animation_time - float(track.get(&"at", 0.0)) < 0.42
var clock := get_node_or_null("/root/GameClock")
var paused := clock != null and bool(clock.get("paused"))
moving = moving and not paused and not riding
var variant := int(absi(key.hash()))%5
var tile_id := (96 if staff else 84)+variant
var frame := int(_animation_time*9.0+variant)%4
var step := (1.0 if frame==0 else (-1.0 if frame==2 else 0.0)) if moving else 0.0
var at := (center+Vector2(-8*p, _cell_dimensions().y*0.5-3*world_pixel-16*p)).round()
var source := Vector2((tile_id%12)*16,(tile_id/12)*16)
# Retain the same character; split only the feet into a four-phase walk.
# Neighbouring atlas tiles are other people, never animation frames.
var bob := -p if moving and frame%2==0 else 0.0
draw_rect(Rect2(at+Vector2(4,14)*p,Vector2(8,1)*p),Color("3a453c",0.35))
var flip := float(track.get(&"direction",1.0))<0.0
var torso := Rect2(at+Vector2(0,bob),Vector2(16,15)*p)
if flip:
torso.position.x += torso.size.x
torso.size.x = -torso.size.x
draw_texture_rect_region(texture,torso,Rect2(source,Vector2(16,15)))
for leg in range(2):
var leg_x := float(leg)*8*p
var stride := step*p*(1.0 if leg==0 else -1.0)
var foot := Rect2(at+Vector2(leg_x,14*p+stride+bob),Vector2(8,2)*p)
if flip:
foot.position.x = at.x+float(2-leg)*8*p
foot.size.x = -foot.size.x
draw_texture_rect_region(texture,foot,Rect2(source+Vector2(leg*8,14),Vector2(8,2)))
if staff:
draw_rect(Rect2(at+Vector2(7,8)*p,Vector2(2,3)*p),Color("81c6ba"))
if carrying:
PixelArt.tile(self,texture,89,Rect2(at+Vector2(9,6)*p,Vector2(9,9)*p))
var working := staff and state==StaffRuntime.State.WORKING and not riding
var resting := receiving and activity==&"standard_room"
if resting:
var lift := float(int(_animation_time*2)%3) if not paused else 0.0
draw_string(ThemeDB.fallback_font,at+Vector2(11,-1-lift)*p,"z",HORIZONTAL_ALIGNMENT_LEFT,-1,maxi(int(6*p),7),Color("f7efd6"))
if staff and activity==&"cleaner" and (moving or working):
var sweep := step*p if working or moving else 0.0
draw_rect(Rect2(at+Vector2(12*p+sweep,7*p),Vector2(p,8*p)),Color("b7975c"))
draw_rect(Rect2(at+Vector2(10*p+sweep,14*p),Vector2(5*p,2*p)),Color("cdb375"))
if receiving and activity in [&"cafeteria",&"tavern"]:
var lift := p if not paused and int(_animation_time*3)%2==0 else 0.0
draw_rect(Rect2(at+Vector2(11*p,8*p-lift),Vector2(3*p,2*p)),Color("e6d7b5"))
var waiting := not staff and state==GuestRuntime.State.QUEUING and not riding
if (receiving and not resting) or working or waiting:
var badge := Rect2(at+Vector2(10,-4)*p,Vector2(6,5)*p)
draw_rect(badge,Color("f2e9cb"))
var mark := Color("c39150") if waiting else Color("61958a")
if waiting:
draw_rect(Rect2(badge.position+Vector2(2,1)*p,Vector2(1,2)*p),mark)
draw_rect(Rect2(badge.position+Vector2(2,3)*p,Vector2(2,1)*p),mark)
else:
var offset := 1.0 if not paused and int(_animation_time*3)%2==0 else 0.0
draw_rect(Rect2(badge.position+Vector2(1+offset,2)*p,Vector2(3,1)*p),mark)
var variant := int(absi(key.hash())) % 15
var frame := int(_animation_time * 12.0) + variant
var mode: StringName = &"idle"
if staff and state == StaffRuntime.State.INCAPACITATED:
mode = &"collapsed"
elif receiving and activity in [&"standard_room", &"premium_room"]:
mode = &"sleep"
elif moving:
mode = &"carry_walk" if carrying else &"walk"
elif carrying:
mode = &"carry"
elif staff and state == StaffRuntime.State.WORKING and not riding:
mode = activity if activity in [&"clean", &"idle", &"work"] else &"work"
elif receiving and activity in [&"cafeteria", &"tavern"]:
mode = &"eat"
elif _queue_positions.has(key) or (not staff and state == GuestRuntime.State.QUEUING):
mode = &"wait"
var at := (center + Vector2(-8 * p, _cell_dimensions().y * 0.5 - 3 * world_pixel - 17 * p)).round()
draw_rect(Rect2(at + Vector2(5, 17) * p, Vector2(8, 1) * p), Color("303c40", 0.2))
People.draw(self, at, p, mode, frame, variant, staff, float(track.get(&"direction", 1.0)) < 0.0)
func _draw_excavation_jobs() -> void:
@@ -990,9 +1354,10 @@ func _draw_map_caption(_map_rect: Rect2) -> void:
var caption := "世界樹の宿 / お客様のフロア" if layer_mode==LayerMode.FRONT else "世界樹の宿 / 従業員と物流"
draw_rect(Rect2(14,12,244,26),Color("29483d",0.93))
draw_string(font,Vector2(24,30),caption,HORIZONTAL_ALIGNMENT_LEFT,-1,13,Color("f0e2bd"))
var status := "表示 %d%% · G マス目%s" % [int(zoom_level*100), " ON" if show_grid else ""]
draw_rect(Rect2(size.x-214,12,200,26),Color("29483d",0.93))
draw_string(font,Vector2(size.x-204,30),status,HORIZONTAL_ALIGNMENT_LEFT,-1,12,Color("f0e2bd"))
var status := "表示 %d%% · %s · G マス目%s" % [int(zoom_level*100), "裏層:半透明" if layer_mode == LayerMode.FRONT else "表層:輪郭", " ON" if show_grid else ""]
var status_width := font.get_string_size(status,HORIZONTAL_ALIGNMENT_LEFT,-1,12).x + 20.0
draw_rect(Rect2(size.x-status_width-14,12,status_width,26),Color("29483d",0.93))
draw_string(font,Vector2(size.x-status_width-4,30),status,HORIZONTAL_ALIGNMENT_LEFT,-1,12,Color("f0e2bd"))
func _draw_center_message(message: String) -> void:
@@ -1085,7 +1450,7 @@ func _on_mouse_exited() -> void:
_set_hovered_cell(null)
func _on_snapshot_published(_snapshot: Dictionary, _digest: String) -> void:
func _on_snapshot_published(_snapshot: Dictionary = {}, _digest: String = "") -> void:
queue_redraw()
_update_build_preview()
_update_excavation_preview()
@@ -1094,29 +1459,38 @@ func _on_snapshot_published(_snapshot: Dictionary, _digest: String) -> void:
func _connect_runtime() -> void:
if _runtime == null or not _runtime is Object or not _runtime.has_signal(&"snapshot_published"):
return
var notification: StringName = &"state_updated" if _runtime.has_signal(&"state_updated") else &"snapshot_published"
var callback := Callable(self, "_on_snapshot_published")
if not _runtime.is_connected(&"snapshot_published", callback):
_runtime.connect(&"snapshot_published", callback)
if not _runtime.is_connected(notification, callback):
_runtime.connect(notification, callback)
func _disconnect_runtime() -> void:
if _runtime == null or not _runtime is Object or not _runtime.has_signal(&"snapshot_published"):
return
var notification: StringName = &"state_updated" if _runtime.has_signal(&"state_updated") else &"snapshot_published"
var callback := Callable(self, "_on_snapshot_published")
if _runtime.is_connected(&"snapshot_published", callback):
_runtime.disconnect(&"snapshot_published", callback)
if _runtime.is_connected(notification, callback):
_runtime.disconnect(notification, callback)
func _service(property_name: StringName) -> Variant:
if _runtime == null or not _runtime is Object:
return null
if _drawing and _draw_cache.has(property_name):
return _draw_cache[property_name]
for property: Dictionary in _runtime.get_property_list():
if StringName(property.get(&"name", &"")) == property_name:
return _runtime.get(property_name)
var value = _runtime.get(property_name)
if _drawing:
_draw_cache[property_name] = value
return value
return null
func _world_bounds() -> Dictionary:
if _drawing and _draw_cache.has(&"bounds"):
return _draw_cache[&"bounds"]
var world: Variant = _service(&"world_service")
if world == null or not world.has_method(&"get_bounds"):
return {}
@@ -1126,13 +1500,17 @@ func _world_bounds() -> Dictionary:
for key: StringName in [&"min_x", &"max_x", &"min_y", &"max_y"]:
if not result.has(key) and not result.has(String(key)):
return {}
return {
var result_value = {
&"min_x": int(result.get(&"min_x", result.get("min_x", 0))),
&"max_x": int(result.get(&"max_x", result.get("max_x", -1))),
&"min_y": int(result.get(&"min_y", result.get("min_y", 0))),
&"max_y": int(result.get(&"max_y", result.get("max_y", -1))),
}
if _drawing:
_draw_cache[&"bounds"] = result_value
return result_value
func _cells_from_serialized(value: Variant) -> Array[Vector3i]:
var result: Array[Vector3i] = []
@@ -1155,3 +1533,37 @@ func _serialize_cells(cells: Array[Vector3i]) -> Array[Array]:
func _normalized_rotation(value: int) -> int:
return posmod(value, 360) / 90 * 90
func _rescue_treatment_position(patient_id: StringName, fallback: Vector2) -> Vector2:
var facility_id: StringName = _treated_patients[patient_id]
var world: Variant = _service(&"world_service")
var cells: Array[Vector3i] = world.get_entity_cells(facility_id) if world != null else []
if cells.is_empty(): return fallback
var data: Dictionary = _room_presentations.get(facility_id, {})
var slot := (data.get(&"people", []) as Array).find(patient_id)
var p := _cell_dimensions().x/16.0
var anchors := RoomPresentation.slots(_cell_bounds_rect(cells), p, &"infirmary")
if slot < 0 or slot >= anchors.size(): return Vector2(INF,INF)
return anchors[slot]+Vector2(0,-2*p-_cell_dimensions().y*0.5)
func _resting_staff_position(staff_id: StringName, fallback: Vector2) -> Vector2:
var facility_id: StringName = _resting_staff[staff_id]
var world: Variant = _service(&"world_service")
var cells: Array[Vector3i] = world.get_entity_cells(facility_id) if world != null else []
if cells.is_empty(): return fallback
var data: Dictionary = _room_presentations.get(facility_id, {})
var slot := (data.get(&"people", []) as Array).find(staff_id)
var anchors := RoomPresentation.slots(_cell_bounds_rect(cells), _cell_dimensions().x/16.0, &"staff_waiting_room")
if slot < 0 or slot >= anchors.size(): return Vector2(INF,INF)
return anchors[slot]+Vector2(0,-_cell_dimensions().y*0.5)
func _can_drop_data(_position: Vector2, data: Variant) -> bool:
return data is Dictionary and data.get(&"kind", &"") == &"staff_assignment" and data.get(&"staff_id", &"") is StringName
func _drop_data(position: Vector2, data: Variant) -> void:
if _can_drop_data(position, data):
staff_assignment_dropped.emit(data, facility_at_canvas(position))