Skip to content

Commit

Permalink
Styles: Rework internal structure of styles (#2402)
Browse files Browse the repository at this point in the history
This is a big rewrite of how styles are stored in layers with the main goal of identifying styles not by their index but by an identifier. This solves a big issue that inherited styles previously had, where moving the layers of the base style was allowed but would break sub-styles.

This also includes some code which auto-updates existing styles, but I'd like to remove this code again before we enter the beta phase (or at least for stable).
  • Loading branch information
Jowan-Spooner authored Oct 23, 2024
1 parent a85fb36 commit b35dd01
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 239 deletions.
25 changes: 12 additions & 13 deletions addons/dialogic/Modules/Character/node_portrait_container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func update_portrait_transforms() -> void:
func get_local_portrait_transform(portrait_rect:Rect2, character_scale:=1.0) -> Rect2:
var transform := Rect2()
transform.position = _get_origin_position()

# Mode that ignores the containers size
if size_mode == SizeModes.KEEP:
transform.size = Vector2(1,1) * character_scale
Expand Down Expand Up @@ -183,12 +183,12 @@ func _update_debug_portrait_scene() -> void:
for child in get_children():
if child != debug_origin:
child.free()

# Get character
var character := _get_debug_character()
if not character is DialogicCharacter or character.portraits.is_empty():
return

# Determine portrait
var debug_portrait := debug_character_portrait
if debug_portrait.is_empty():
Expand All @@ -198,34 +198,33 @@ func _update_debug_portrait_scene() -> void:
debug_portrait = portrait_prefix+debug_portrait
if not debug_portrait in character.portraits:
debug_portrait = character.default_portrait

var portrait_info: Dictionary = character.get_portrait_info(debug_portrait)

# Determine scene
var portrait_scene_path: String = portrait_info.get('scene', default_portrait_scene)
if portrait_scene_path.is_empty():
if portrait_scene_path.is_empty():
portrait_scene_path = default_portrait_scene

debug_character_scene_node = load(portrait_scene_path).instantiate()

if !is_instance_valid(debug_character_scene_node):
return

# Load portrait
DialogicUtil.apply_scene_export_overrides(debug_character_scene_node, character.portraits[debug_portrait].get('export_overrides', {}))
debug_character_scene_node._update_portrait(character, debug_portrait)

# Add character node
if !is_instance_valid(debug_character_holder_node):
debug_character_holder_node = Node2D.new()
add_child(debug_character_holder_node)
print(debug_character_holder_node)


# Add portrait node
debug_character_holder_node.add_child(debug_character_scene_node)
move_child(debug_character_holder_node, 0)
debug_character_scene_node._set_mirror(character.mirror != mirrored != portrait_info.get('mirror', false))

_update_debug_portrait_transform()


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="DialogicStyle" load_steps=17 format=3 uid="uid://dgkmuyvy5qc35"]
[gd_resource type="Resource" script_class="DialogicStyle" load_steps=18 format=3 uid="uid://dgkmuyvy5qc35"]

[ext_resource type="PackedScene" uid="uid://c1k5m0w3r40xf" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_FullBackground/full_background_layer.tscn" id="1_sde84"]
[ext_resource type="Script" path="res://addons/dialogic/Resources/dialogic_style_layer.gd" id="2_i34tx"]
Expand All @@ -10,45 +10,59 @@
[ext_resource type="PackedScene" uid="uid://lx24i8fl6uo" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_History/history_layer.tscn" id="8_00chv"]
[ext_resource type="Script" path="res://addons/dialogic/Resources/dialogic_style.gd" id="9_sdr6x"]

[sub_resource type="Resource" id="Resource_35sbo"]
[sub_resource type="Resource" id="Resource_1cyj6"]
script = ExtResource("2_i34tx")
overrides = {}

[sub_resource type="Resource" id="Resource_jk75o"]
script = ExtResource("2_i34tx")
scene = ExtResource("1_sde84")
overrides = {}

[sub_resource type="Resource" id="Resource_x576n"]
[sub_resource type="Resource" id="Resource_l2hgc"]
script = ExtResource("2_i34tx")
scene = ExtResource("4_8y2vo")
overrides = {}

[sub_resource type="Resource" id="Resource_gc1b5"]
[sub_resource type="Resource" id="Resource_iqsmu"]
script = ExtResource("2_i34tx")
scene = ExtResource("3_epko4")
overrides = {}

[sub_resource type="Resource" id="Resource_otikm"]
[sub_resource type="Resource" id="Resource_axty6"]
script = ExtResource("2_i34tx")
scene = ExtResource("5_ll78j")
overrides = {}

[sub_resource type="Resource" id="Resource_w8ec6"]
[sub_resource type="Resource" id="Resource_xh5pc"]
script = ExtResource("2_i34tx")
scene = ExtResource("6_36eid")
overrides = {}

[sub_resource type="Resource" id="Resource_qmo1y"]
[sub_resource type="Resource" id="Resource_ytmk0"]
script = ExtResource("2_i34tx")
scene = ExtResource("7_hx5el")
overrides = {}

[sub_resource type="Resource" id="Resource_legp8"]
[sub_resource type="Resource" id="Resource_yjxtw"]
script = ExtResource("2_i34tx")
scene = ExtResource("8_00chv")
overrides = {}

[resource]
script = ExtResource("9_sdr6x")
name = "Speaker Textbox Style"
base_overrides = {
"global_bg_color": "Color(0.298039, 0.2, 0.113725, 0.901961)"
layer_list = Array[String](["10", "11", "12", "13", "14", "15", "16"])
layer_info = {
"": SubResource("Resource_1cyj6"),
"10": SubResource("Resource_jk75o"),
"11": SubResource("Resource_l2hgc"),
"12": SubResource("Resource_iqsmu"),
"13": SubResource("Resource_axty6"),
"14": SubResource("Resource_xh5pc"),
"15": SubResource("Resource_ytmk0"),
"16": SubResource("Resource_yjxtw")
}
layers = Array[ExtResource("2_i34tx")]([SubResource("Resource_35sbo"), SubResource("Resource_x576n"), SubResource("Resource_gc1b5"), SubResource("Resource_otikm"), SubResource("Resource_w8ec6"), SubResource("Resource_qmo1y"), SubResource("Resource_legp8")])
base_overrides = {}
layers = Array[ExtResource("2_i34tx")]([])
metadata/_latest_layer = ""
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
[gd_resource type="Resource" script_class="DialogicStyle" load_steps=8 format=3 uid="uid://b0sbwssin2kuk"]
[gd_resource type="Resource" script_class="DialogicStyle" load_steps=9 format=3 uid="uid://b0sbwssin2kuk"]

[ext_resource type="PackedScene" uid="uid://syki6k0e6aac" path="res://addons/dialogic/Modules/DefaultLayoutParts/Base_TextBubble/text_bubble_base.tscn" id="1_a7s28"]
[ext_resource type="Script" path="res://addons/dialogic/Resources/dialogic_style.gd" id="1_q3xp1"]
[ext_resource type="PackedScene" uid="uid://d2it0xiap3gnt" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_Textbubble/text_bubble_layer.tscn" id="2_ctkoo"]
[ext_resource type="Script" path="res://addons/dialogic/Resources/dialogic_style_layer.gd" id="3_3a5cc"]
[ext_resource type="PackedScene" uid="uid://cn674foxwedqu" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_Input/full_advance_input_layer.tscn" id="4_rr4hm"]

[sub_resource type="Resource" id="Resource_xt3fr"]
[sub_resource type="Resource" id="Resource_u2jf8"]
script = ExtResource("3_3a5cc")
scene = ExtResource("1_a7s28")
overrides = {}

[sub_resource type="Resource" id="Resource_ajt4g"]
script = ExtResource("3_3a5cc")
scene = ExtResource("4_rr4hm")
overrides = {}

[sub_resource type="Resource" id="Resource_inc2n"]
[sub_resource type="Resource" id="Resource_phvdv"]
script = ExtResource("3_3a5cc")
scene = ExtResource("2_ctkoo")
overrides = {}

[resource]
script = ExtResource("1_q3xp1")
name = "Textbubble Style"
base_scene = ExtResource("1_a7s28")
layer_list = Array[String](["10", "11"])
layer_info = {
"": SubResource("Resource_u2jf8"),
"10": SubResource("Resource_ajt4g"),
"11": SubResource("Resource_phvdv")
}
base_overrides = {}
layers = Array[ExtResource("3_3a5cc")]([SubResource("Resource_xt3fr"), SubResource("Resource_inc2n")])
layers = Array[ExtResource("3_3a5cc")]([])
metadata/_latest_layer = ""
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="DialogicStyle" load_steps=19 format=3 uid="uid://8t1mr302tmqs"]
[gd_resource type="Resource" script_class="DialogicStyle" load_steps=20 format=3 uid="uid://8t1mr302tmqs"]

[ext_resource type="Script" path="res://addons/dialogic/Resources/dialogic_style.gd" id="1_mvpc0"]
[ext_resource type="Script" path="res://addons/dialogic/Resources/dialogic_style_layer.gd" id="2_3b8ue"]
Expand All @@ -11,48 +11,65 @@
[ext_resource type="PackedScene" uid="uid://cvgf4c6gg0tsy" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_TextInput/text_input_layer.tscn" id="9_tufw5"]
[ext_resource type="PackedScene" uid="uid://lx24i8fl6uo" path="res://addons/dialogic/Modules/DefaultLayoutParts/Layer_History/history_layer.tscn" id="10_8v8jj"]

[sub_resource type="Resource" id="Resource_x8thn"]
[sub_resource type="Resource" id="Resource_3dixn"]
script = ExtResource("2_3b8ue")
overrides = {}

[sub_resource type="Resource" id="Resource_gen8e"]
script = ExtResource("2_3b8ue")
scene = ExtResource("2_dtgi6")
overrides = {}

[sub_resource type="Resource" id="Resource_g5yti"]
[sub_resource type="Resource" id="Resource_nit0s"]
script = ExtResource("2_3b8ue")
scene = ExtResource("4_q1t5h")
overrides = {}

[sub_resource type="Resource" id="Resource_eqyxb"]
[sub_resource type="Resource" id="Resource_1ak3n"]
script = ExtResource("2_3b8ue")
scene = ExtResource("6_j6olx")
overrides = {}

[sub_resource type="Resource" id="Resource_adxfb"]
[sub_resource type="Resource" id="Resource_05bhv"]
script = ExtResource("2_3b8ue")
scene = ExtResource("5_o6sv8")
overrides = {}

[sub_resource type="Resource" id="Resource_nmutb"]
[sub_resource type="Resource" id="Resource_pvwog"]
script = ExtResource("2_3b8ue")
scene = ExtResource("7_vw5f4")
overrides = {}

[sub_resource type="Resource" id="Resource_dwo52"]
[sub_resource type="Resource" id="Resource_spe5r"]
script = ExtResource("2_3b8ue")
scene = ExtResource("8_tc6v1")
overrides = {}

[sub_resource type="Resource" id="Resource_by0l6"]
[sub_resource type="Resource" id="Resource_jf1ol"]
script = ExtResource("2_3b8ue")
scene = ExtResource("9_tufw5")
overrides = {}

[sub_resource type="Resource" id="Resource_fd6co"]
[sub_resource type="Resource" id="Resource_gs5pl"]
script = ExtResource("2_3b8ue")
scene = ExtResource("10_8v8jj")
overrides = {}

[resource]
script = ExtResource("1_mvpc0")
name = "Visual Novel Style"
layer_list = Array[String](["10", "11", "12", "13", "14", "15", "16", "17"])
layer_info = {
"": SubResource("Resource_3dixn"),
"10": SubResource("Resource_gen8e"),
"11": SubResource("Resource_nit0s"),
"12": SubResource("Resource_1ak3n"),
"13": SubResource("Resource_05bhv"),
"14": SubResource("Resource_pvwog"),
"15": SubResource("Resource_spe5r"),
"16": SubResource("Resource_jf1ol"),
"17": SubResource("Resource_gs5pl")
}
base_overrides = {}
layers = Array[ExtResource("2_3b8ue")]([SubResource("Resource_x8thn"), SubResource("Resource_g5yti"), SubResource("Resource_eqyxb"), SubResource("Resource_adxfb"), SubResource("Resource_nmutb"), SubResource("Resource_dwo52"), SubResource("Resource_by0l6"), SubResource("Resource_fd6co")])
layers = Array[ExtResource("2_3b8ue")]([])
metadata/_latest_layer = "17"
16 changes: 9 additions & 7 deletions addons/dialogic/Modules/Style/subsystem_styles.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ func load_style(style_name := "", parent: Node = null, is_base_style := true, st

# If this has the same scene setup, just apply the new overrides
elif previous_layout.get_meta('style') == style.get_inheritance_root():
DialogicUtil.apply_scene_export_overrides(previous_layout, style.get_layer_inherited_info(-1).overrides)
DialogicUtil.apply_scene_export_overrides(previous_layout, style.get_layer_inherited_info("").overrides)
var index := 0
for layer in previous_layout.get_layers():
DialogicUtil.apply_scene_export_overrides(layer, style.get_layer_inherited_info(index).overrides)
DialogicUtil.apply_scene_export_overrides(
layer,
style.get_layer_inherited_info(style.get_layer_id_at_index(index)).overrides)
index += 1

previous_layout.set_meta('style', style)
Expand All @@ -74,7 +76,7 @@ func load_style(style_name := "", parent: Node = null, is_base_style := true, st
# Preserve process_mode on style changes
if previous_layout:
new_layout.process_mode = previous_layout.process_mode

new_layout.ready.connect(reload_current_info_into_new_style)

style_changed.emit(signal_info)
Expand All @@ -96,11 +98,11 @@ func create_layout(style: DialogicStyle, parent: Node = null) -> DialogicLayoutB
base_scene.name = "DialogicLayout_"+style.name.to_pascal_case()

# Apply base scene overrides
DialogicUtil.apply_scene_export_overrides(base_scene, style.get_layer_inherited_info(-1).overrides)
DialogicUtil.apply_scene_export_overrides(base_scene, style.get_layer_inherited_info("").overrides)

# Load layers
for layer_idx in range(style.get_layer_count()):
var layer := style.get_layer_inherited_info(layer_idx)
for layer_id in style.get_layer_inherited_list():
var layer := style.get_layer_inherited_info(layer_id)

if not ResourceLoader.exists(layer.path):
continue
Expand Down Expand Up @@ -152,7 +154,7 @@ func has_active_layout_node() -> bool:
)


func get_layout_node() -> Node:
func get_layout_node() -> DialogicLayoutBase:
if has_active_layout_node():
return get_tree().get_meta('dialogic_layout_node')
return null
Expand Down
Loading

0 comments on commit b35dd01

Please sign in to comment.