P23-03: 生活の観察
This commit is contained in:
@@ -637,6 +637,7 @@ func _build_life_observation() -> Dictionary:
|
||||
&"at": rect.position + Vector2(2, 16), &"requests": requests,
|
||||
&"text": RoomPresentation.supply_label(requests)})
|
||||
model[&"badges"] = badges
|
||||
_resolve_observation_labels(model)
|
||||
var obstacles: Array[Rect2] = []
|
||||
for cabin: Dictionary in model[&"cabins"]:
|
||||
obstacles.append(cabin[&"rect"])
|
||||
@@ -691,6 +692,39 @@ func _traffic_segments(band: Rect2, cell: Rect2, obstacles: Array[Rect2]) -> Arr
|
||||
return []
|
||||
|
||||
|
||||
func _resolve_observation_labels(model: Dictionary) -> void:
|
||||
var placed: Array[Dictionary] = []
|
||||
for i: int in model[&"cabins"].size():
|
||||
var cabin: Dictionary = model[&"cabins"][i]
|
||||
placed.append({&"id": "cabin/%d/rect" % i, &"rect": cabin[&"rect"]})
|
||||
placed.append({&"id": "cabin/%d/badge" % i, &"rect": cabin[&"badge_rect"]})
|
||||
for kind: String in ["business", "supply", "landing", "aggregation"]:
|
||||
var collection: Array = model[&"badges"] if kind in ["business", "supply"] else model[&"landing_badges"] if kind == "landing" else model.get(&"actor_aggregations", [])
|
||||
for i: int in collection.size():
|
||||
var badge: Dictionary = collection[i]
|
||||
if kind in ["business", "supply"] and badge[&"kind"] != kind:
|
||||
continue
|
||||
var anchor: Vector2 = badge[&"at"]
|
||||
var at := anchor
|
||||
var displaced_by: Array[String] = []
|
||||
# Each collision advances to an existing right edge. Positive widths
|
||||
# guarantee termination; touching edges are allowed.
|
||||
while true:
|
||||
var blocker: Dictionary = {}
|
||||
for previous: Dictionary in placed:
|
||||
if _readable_badge_rect(at, badge[&"text"]).intersection(previous[&"rect"]).has_area():
|
||||
blocker = previous
|
||||
break
|
||||
if blocker.is_empty():
|
||||
break
|
||||
displaced_by.append(blocker[&"id"])
|
||||
at.x = (blocker[&"rect"] as Rect2).end.x
|
||||
badge[&"anchor"] = anchor
|
||||
badge[&"at"] = at
|
||||
badge[&"displaced_by"] = displaced_by.duplicate(true)
|
||||
placed.append({&"id": "%s/%d" % [kind, i], &"rect": _readable_badge_rect(at, badge[&"text"])})
|
||||
|
||||
|
||||
func _draw_life_badges(canvas: CanvasItem) -> void:
|
||||
for badge: Dictionary in _life_observation.get(&"badges", []):
|
||||
_draw_readable_badge(badge[&"at"], badge[&"text"], canvas)
|
||||
|
||||
Reference in New Issue
Block a user