change props logic
This commit is contained in:
@@ -193,6 +193,15 @@ func collect_all_propinfo(root: Node, list: Array[Node]) -> void:
|
||||
for child in root.get_children():
|
||||
collect_all_propinfo(child, list)
|
||||
|
||||
func collect_all_prop_markers(root: Node, list: Array[Node]) -> void:
|
||||
if root == null: return
|
||||
|
||||
if root is Marker3D and _is_prop_marker(root):
|
||||
list.append(root)
|
||||
|
||||
for child in root.get_children():
|
||||
collect_all_prop_markers(child, list)
|
||||
|
||||
func collect_all_entityinfo(root: Node, list: Array[Node]) -> void:
|
||||
if root == null: return
|
||||
|
||||
@@ -700,17 +709,29 @@ func _get_prop_scene_uniqueness(scene: PackedScene) -> int:
|
||||
prop_candidate_cache[key] = uniqueness
|
||||
return uniqueness
|
||||
|
||||
func _get_marker_prop_uniqueness(marker: Node) -> int:
|
||||
var uniqueness = _get_prop_uniqueness_from_info(marker)
|
||||
func _is_prop_marker(node: Node) -> bool:
|
||||
return node.is_in_group("prop_marker") or node.name.begins_with("Prop")
|
||||
|
||||
func _get_scene_prop_info(root: Node) -> Node:
|
||||
var prop_info_list: Array[Node] = []
|
||||
collect_all_propinfo(root, prop_info_list)
|
||||
|
||||
for info_node in prop_info_list:
|
||||
if not (info_node is Marker3D):
|
||||
return info_node
|
||||
return null
|
||||
|
||||
func _get_prop_config_uniqueness(prop_info: Node) -> int:
|
||||
var uniqueness = _get_prop_uniqueness_from_info(prop_info)
|
||||
if uniqueness == -1:
|
||||
return 0
|
||||
return uniqueness
|
||||
|
||||
func _pick_weighted_prop_scene(marker: Node) -> PackedScene:
|
||||
func _pick_weighted_prop_scene(prop_info: Node) -> PackedScene:
|
||||
var candidates = []
|
||||
var fallback_uniqueness = _get_marker_prop_uniqueness(marker)
|
||||
var fallback_uniqueness = _get_prop_config_uniqueness(prop_info)
|
||||
|
||||
for prop_scene in marker.available_props:
|
||||
for prop_scene in prop_info.available_props:
|
||||
if prop_scene == null:
|
||||
continue
|
||||
|
||||
@@ -729,17 +750,27 @@ func _pick_weighted_prop_scene(marker: Node) -> PackedScene:
|
||||
return _pick_weighted_candidate(candidates).scene
|
||||
|
||||
func _spawn_props_for_chunk(root: Node) -> void:
|
||||
var prop_markers: Array[Node] = []
|
||||
collect_all_propinfo(root, prop_markers)
|
||||
var scene_prop_info = _get_scene_prop_info(root)
|
||||
if scene_prop_info != null:
|
||||
var scene_prop_markers: Array[Node] = []
|
||||
collect_all_prop_markers(root, scene_prop_markers)
|
||||
|
||||
for marker in prop_markers:
|
||||
_spawn_prop_for_marker(marker)
|
||||
|
||||
func _spawn_prop_for_marker(marker: Node) -> void:
|
||||
if marker.available_props.is_empty():
|
||||
for marker in scene_prop_markers:
|
||||
_spawn_prop_for_marker(marker, scene_prop_info)
|
||||
return
|
||||
|
||||
var prop_scene = _pick_weighted_prop_scene(marker)
|
||||
var legacy_prop_markers: Array[Node] = []
|
||||
collect_all_propinfo(root, legacy_prop_markers)
|
||||
|
||||
for marker in legacy_prop_markers:
|
||||
if marker is Marker3D:
|
||||
_spawn_prop_for_marker(marker, marker)
|
||||
|
||||
func _spawn_prop_for_marker(marker: Node, prop_info: Node) -> void:
|
||||
if prop_info.available_props.is_empty():
|
||||
return
|
||||
|
||||
var prop_scene = _pick_weighted_prop_scene(prop_info)
|
||||
if prop_scene == null:
|
||||
return
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends Marker3D
|
||||
## Scene-level configuration for props spawned on Prop* markers.
|
||||
class_name PropInfo
|
||||
extends Node3D
|
||||
|
||||
@export var available_props: Array[PackedScene]
|
||||
@export_range(0, 5, 1) var uniqueness: int = 0 #0=common; 5=unique
|
||||
|
||||
Reference in New Issue
Block a user