diff --git a/src/components/level_system/LevelPatterns.gd b/src/components/level_system/LevelPatterns.gd new file mode 100644 index 0000000..eae1387 --- /dev/null +++ b/src/components/level_system/LevelPatterns.gd @@ -0,0 +1,21 @@ +extends RefCounted +class_name LevelPatterns + +const patterns: Dictionary = { + 0: [19, 18], + 1: [17, 18], + 2: [19, 17], + 3: [17, 17, 17], + 4: [19, 19], +} + +const levels: Dictionary = { + 0: { + level_patterns = [0, 1, 2], + random = false, + }, + 1: { + level_patterns = [3, 4], + random = true, + } +} diff --git a/src/components/level_system/LevelQueue.gd b/src/components/level_system/LevelQueue.gd index 3e416c4..8dff1cd 100644 --- a/src/components/level_system/LevelQueue.gd +++ b/src/components/level_system/LevelQueue.gd @@ -1,22 +1,22 @@ extends Node class_name LevelQueue -var items: Array[Dictionary] = [] +var items: Array[int] = [] var length: int: get: return len(items) -func next_item() -> Dictionary: +func next_item() -> int: if len(items) < 1: push_error("out of items") - return {} + return ERR_DOES_NOT_EXIST return items.pop_back() -func add_item(new_item: Dictionary): +func add_item(new_item: int): items.push_front(new_item) -func add_items(new_items: Array[Dictionary]): +func add_items(new_items: Array[int]): items.append_array(new_items) func print_members(): diff --git a/src/components/level_system/PatternGen.gd b/src/components/level_system/PatternGen.gd index 8bf972d..4c16476 100644 --- a/src/components/level_system/PatternGen.gd +++ b/src/components/level_system/PatternGen.gd @@ -1,19 +1,19 @@ extends Node class_name PatternGen -var level_queue: LevelQueue - -var patterns_struct: Dictionary = {} +var level_queue := LevelQueue.new() const MAX_LEVEL := 10 -var level := 0: +enum SpawnMode {TUTORIAL, DEBUG, QUEUE} + +@export var level := 0: set(val): level = clamp(0, MAX_LEVEL, val) func _ready(): - add_pattern() + add_patterns() func upgrade_level(): level += 1 @@ -21,25 +21,25 @@ func upgrade_level(): func downgrade_level(): level -= 1 -func next_pattern() -> Dictionary: +func next_pattern() -> int: + if level_queue.length <= 0: + add_patterns() return level_queue.next_item() -func initialize_patterns(): - # Example initialization of patterns_struct - patterns_struct = { - 1: [ {name = "Easy Pattern", difficulty = 1}], - 2: [ {name = "Medium Pattern", difficulty = 2}, {name = "Another Medium Pattern", difficulty = 2}], - # Add more levels and patterns as needed - } -func add_pattern(): - var current_level_patterns = patterns_struct[level] - if current_level_patterns != null: - for pattern in current_level_patterns: - level_queue.add_item(pattern) +func add_patterns(): + var current_level: Dictionary = LevelPatterns.levels[level] + if current_level.get("random"): + var p: int = current_level.level_patterns.pick_random() + for i in LevelPatterns.patterns[p]: + level_queue.add_item(i) + else: + for pattern in current_level.level_patterns: + for type in LevelPatterns.patterns[pattern]: + level_queue.add_item(type) func update_patterns_based_on_level(): # Clear the queue to avoid mixing patterns from different levels level_queue.items_queue.clear() # Add patterns corresponding to the current level - add_pattern() + add_patterns() diff --git a/src/models/icosahedron/components/MeshIcosahedron.gd b/src/models/icosahedron/components/MeshIcosahedron.gd index b25b014..7529bd1 100644 --- a/src/models/icosahedron/components/MeshIcosahedron.gd +++ b/src/models/icosahedron/components/MeshIcosahedron.gd @@ -56,19 +56,22 @@ func set_color(c: Vector3): ShaderUtils.set_shader_param(self, "color", c, i) func set_type(type: int): - var variant: Vector4 = IcosahedronVarints.figure_variants_v2[type] + var variant: Vector4 = IcosahedronVarints.figure_variants_v2.get(type, Vector4()) + var variant_color: Array = TwTheme.figure_variants_v2.get(type, []) + if not variant or not variant_color: + push_warning("type ", type, " not found") + set_default_type() + return + ShaderUtils.apply_shaders(applied_shaders, self) if show_face_numbers: self.material_overlay = MATERIAL_002 - ShaderUtils.apply_shaders(applied_shaders, self) - ShaderUtils.set_shader_param(self, "cutplane_visible", 0, 0) set_cutplane(variant) - var variant_color: Array = TwTheme.figure_variants_v2[type] set_color(Op.v3(variant_color)) func set_default_type(): if show_face_numbers: self.material_overlay = MATERIAL_002 ShaderUtils.apply_shaders(default_shaders, self) - + ShaderUtils.set_shader_param(self, "cutplane_visible", false, 0) var variant_color: Array = TwTheme.T.figure_variants.default set_color(Op.v3(variant_color)) diff --git a/src/models/icosahedron/components/Variants.gd b/src/models/icosahedron/components/Variants.gd index 0f0a31b..8f8c211 100644 --- a/src/models/icosahedron/components/Variants.gd +++ b/src/models/icosahedron/components/Variants.gd @@ -43,9 +43,18 @@ const figure_variants = { }, } +const a := 0.577 +const b := 0.358 +const c := 0.934 # TDOO: make in sync w/ UV map from discrete_control.tscn static var figure_variants_v2 := { - 0: Vector4( -0.577, 0.577, 0.577, dst), - 1: Vector4( -0.577, 0.577, -0.577, dst), + 0: Vector4( c, b, 0, dst), + 1: Vector4( a, a, -a, dst), + 4: Vector4( a, a, a, dst), + 11: Vector4( a, -a, -a, dst), + 9: Vector4( a, -a, a, dst), + 17: Vector4( -a, a, -a, dst), + 18: Vector4( -c, b, 0, dst), + 19: Vector4( -a, a, a, dst), # ... } diff --git a/src/models/icosahedron/test/variant_test.gd b/src/models/icosahedron/test/variant_test.gd index 596d185..3a555bd 100644 --- a/src/models/icosahedron/test/variant_test.gd +++ b/src/models/icosahedron/test/variant_test.gd @@ -3,32 +3,52 @@ extends Node3D const IcosahedronScene = preload('res://src/models/icosahedron/Icosahedron.tscn') var controlledNode +@onready var pattern_gen: PatternGen = $PatternGen + @export var ROTATION_SPEED: float = G.settings.ROTATION_SPEED @export_category("variant settings") @export var show_face_numbers: bool = true -@export_range(0, 19) var variant_type: int = 0 +#@export_range(0, 19) var variant_type: int = 0 +@export_enum("zero:0", "mid_left:17", "mid:18", "mid_right:19") var variant_type: int = 0 @export var use_default := false # Called when the node enters the scene tree for the first time. func _ready() -> void: + get_next() + +func get_next(): + remove_current() + # if spawn type random + #var next_type := randi_range(17, 19) + var next_type := pattern_gen.next_pattern() + print_debug("Spawinig next figure woth type: ", next_type) + spawn_next(next_type) + +func remove_current(): + for i in get_children(): + if i is Icosahedron: + i.queue_free() + +# TODO mb generalize and move to another module to reuse +func spawn_next(_type: int): var new_figure if use_default: new_figure = IcosahedronScene.instantiate() else: new_figure = IcosahedronScene.instantiate()\ - .with_type(variant_type)\ + .with_type(_type)\ .with_face_numbers(show_face_numbers) - add_child(new_figure) controlledNode = new_figure.mesh_icosahedron - # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: if not controlledNode: return if Input.is_action_just_pressed('ui_accept'): controlledNode.transform.basis = Basis(Quaternion()).orthonormalized() + if Input.is_action_just_pressed('ui_focus_next'): + get_next() var rs := ROTATION_SPEED / 10. * delta FreeSpin.handle_free_spin_input(controlledNode, rs) diff --git a/src/models/icosahedron/test/variant_test.tscn b/src/models/icosahedron/test/variant_test.tscn index e4f88af..ece8da2 100644 --- a/src/models/icosahedron/test/variant_test.tscn +++ b/src/models/icosahedron/test/variant_test.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=10 format=3 uid="uid://cd21bp42ng8gy"] +[gd_scene load_steps=11 format=3 uid="uid://cd21bp42ng8gy"] [ext_resource type="Script" path="res://src/models/icosahedron/test/variant_test.gd" id="1_4av47"] [ext_resource type="Shader" path="res://src/shaders/LoopSceneSky.gdshader" id="2_78ays"] [ext_resource type="Shader" path="res://src/shaders/MenuSceneSky_v2.gdshader" id="3_ty025"] [ext_resource type="ArrayMesh" uid="uid://o7rlauuvnfp6" path="res://assets/build/skybox/icosahedron_Solid_Sky.res" id="4_ayq7c"] [ext_resource type="Script" path="res://src/components/sky/SkyIcosahedron.gd" id="5_pg1rd"] +[ext_resource type="Script" path="res://src/components/level_system/PatternGen.gd" id="6_d5fsa"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_tb2j1"] shader = ExtResource("2_78ays") @@ -24,7 +25,7 @@ shader_parameter/bg_color = Color(0.729, 0.902, 0.992, 1) [node name="VariantTest" type="Node3D"] script = ExtResource("1_4av47") -use_default = true +variant_type = 19 [node name="Environment" type="Node3D" parent="."] @@ -43,3 +44,7 @@ material_override = SubResource("ShaderMaterial_0smox") mesh = ExtResource("4_ayq7c") skeleton = NodePath("../..") script = ExtResource("5_pg1rd") + +[node name="PatternGen" type="Node" parent="."] +script = ExtResource("6_d5fsa") +level = 1 diff --git a/src/themes/TwTheme.gd b/src/themes/TwTheme.gd index 888ab34..bcee1da 100644 --- a/src/themes/TwTheme.gd +++ b/src/themes/TwTheme.gd @@ -22,5 +22,9 @@ const figure_variants_v2 := { 0: TwColors.tw.blue._700, 1: TwColors.tw.green._700, 2: TwColors.tw.sky._700, + 3: TwColors.tw.sky._700, + 17: TwColors.tw.orange._700, + 18: TwColors.tw.green._700, + 19: TwColors.tw.purple._700, # ... TODO: color for 0-19 edge from UV map }