Skip to content

Commit

Permalink
temp: fix PatternGen
Browse files Browse the repository at this point in the history
  • Loading branch information
akorzunin committed Aug 25, 2024
1 parent b8d13d0 commit a6a1350
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 37 deletions.
21 changes: 21 additions & 0 deletions src/components/level_system/LevelPatterns.gd
Original file line number Diff line number Diff line change
@@ -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,
}
}
10 changes: 5 additions & 5 deletions src/components/level_system/LevelQueue.gd
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
38 changes: 19 additions & 19 deletions src/components/level_system/PatternGen.gd
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
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

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()
13 changes: 8 additions & 5 deletions src/models/icosahedron/components/MeshIcosahedron.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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))
13 changes: 11 additions & 2 deletions src/models/icosahedron/components/Variants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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),
# ...
}
28 changes: 24 additions & 4 deletions src/models/icosahedron/test/variant_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 7 additions & 2 deletions src/models/icosahedron/test/variant_test.tscn
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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="."]

Expand All @@ -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
4 changes: 4 additions & 0 deletions src/themes/TwTheme.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a6a1350

Please sign in to comment.