From b17d57cbc701ff6efb61e6a6520bbd099889623e Mon Sep 17 00:00:00 2001 From: akorzunin Date: Wed, 11 Sep 2024 16:56:29 +0300 Subject: [PATCH] temp: level select UI --- project.godot | 5 ++ src/components/DiscordStatus.gd | 36 ++++++++++---- src/components/EndRay.gd | 2 +- src/components/GameProgress.gd | 7 +-- src/components/controls/CommonControls.gd | 11 +++++ src/components/controls/MenuControls.gd | 11 +++++ src/components/gui/menu/MenuActions.gd | 7 +++ src/components/gui/menu/MenuStruct.gd | 4 +- src/components/level_system/LevelPatterns.gd | 44 +++++++++++++++-- src/components/level_system/PatternGen.gd | 9 +++- src/components/settings/Config.gd | 5 ++ src/components/settings/DefaultConfig.gd | 3 +- src/components/timers/LoopTimer.gd | 12 +++-- src/components/timers/ScaleTimer.gd | 6 ++- src/globals.gd | 3 ++ .../icosahedron/components/Icosahedron.gd | 3 +- .../icosahedron/shaders/outline_v1.gdshader | 5 +- .../icosahedron/test/game_speed_test.gd | 48 +++++++++++++++++++ src/models/icosahedron/test/variant_test.gd | 6 +-- src/models/icosahedron/test/variant_test.tscn | 2 +- 20 files changed, 193 insertions(+), 36 deletions(-) create mode 100755 src/models/icosahedron/test/game_speed_test.gd diff --git a/project.godot b/project.godot index dbcccdb..b3f7293 100644 --- a/project.godot +++ b/project.godot @@ -96,6 +96,11 @@ ui_pause={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null) ] } +ui_reload={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":82,"location":0,"echo":false,"script":null) +] +} [input_devices] diff --git a/src/components/DiscordStatus.gd b/src/components/DiscordStatus.gd index 7f9c6d2..cb9d8df 100644 --- a/src/components/DiscordStatus.gd +++ b/src/components/DiscordStatus.gd @@ -3,14 +3,34 @@ class_name DiscordStatus func _ready(): DiscordRPC.app_id = ENV.DISCORD_APP_ID # Application ID - DiscordRPC.details = "Main menu" - DiscordRPC.state = "Checkpoint 23/23" + DiscordRPC.details = init_state.details + DiscordRPC.state = init_state.desc DiscordRPC.large_image = 'icon' # Image key from "Art Assets" - DiscordRPC.large_image_text = "Try it now!" - DiscordRPC.small_image = 'icon' # Image key from "Art Assets" - DiscordRPC.small_image_text = "Fighting the end boss! D:" + DiscordRPC.refresh() - DiscordRPC.start_timestamp = int(Time.get_unix_time_from_system()) # "02:46 elapsed" - # DiscordRPC.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 # +1 hour in unix time / "01:00:00 remaining" +const init_state := { + details = "Main menu", + desc = "Chilling", +} - DiscordRPC.refresh() # Always refresh after changing the values! +const loop_state := { + details = "In Game", + desc = "Level: %s", +} + +func set_state(details: String, desc: String, with_time: bool = false): + DiscordRPC.details = details + DiscordRPC.state = desc + if with_time: + DiscordRPC.start_timestamp = int(Time.get_unix_time_from_system()) # "02:46 elapsed" + DiscordRPC.refresh() + +func set_menu_state(): + set_state(init_state.details, init_state.desc) + +func set_loop_state(level := 0): + set_state( + loop_state.details, + loop_state.desc % level if level else "tutorial", + true + ) diff --git a/src/components/EndRay.gd b/src/components/EndRay.gd index e1c5ce2..d923aa2 100644 --- a/src/components/EndRay.gd +++ b/src/components/EndRay.gd @@ -41,7 +41,7 @@ enum AngleType {ANGLE_WRONG, ANGLE_OK, ANGLE_GOOD} func check_angle(v: Vector3) -> AngleType: var a = AngleType - if pass_vec.angle_to(v) < 0.2: + if pass_vec.angle_to(v) < 0.22: return a.ANGLE_GOOD if pass_vec.angle_to(v) < 0.5: return a.ANGLE_OK diff --git a/src/components/GameProgress.gd b/src/components/GameProgress.gd index 5e4fd60..015926c 100644 --- a/src/components/GameProgress.gd +++ b/src/components/GameProgress.gd @@ -14,15 +14,10 @@ var time_passed_formated: String: return loop_timer.get_elapsed_time() var max_reached_level := 0 -static func is_level_up(nodes: int, level: int) -> bool: - match level: - 0: return nodes > 10 - #1: return nodes > 20 - _: return false func add_one(): figures_passed += 1 - if is_level_up(figures_passed, pattern_gen.level): + if LevelPatterns.is_level_up(figures_passed, pattern_gen.level): G.level_changed.emit(pattern_gen.level + 1) func reset(): diff --git a/src/components/controls/CommonControls.gd b/src/components/controls/CommonControls.gd index 654b1aa..c5e9b97 100644 --- a/src/components/controls/CommonControls.gd +++ b/src/components/controls/CommonControls.gd @@ -19,3 +19,14 @@ func _unhandled_input(event: InputEvent) -> void: toggle_debug_stats.emit(state) config._on_debug_stats_state(state) get_viewport().set_input_as_handled() + if event.is_action_pressed('ui_reload'): + G.reload_settings.emit() + +func _notification(what: int): + if what == NOTIFICATION_WM_GO_BACK_REQUEST: + var p := Utils.get_platform() + if p == Utils.Platform.MOBILE: + # Back button on android + InputEmit.new().emit({ + action = 'ui_cancel' + }) diff --git a/src/components/controls/MenuControls.gd b/src/components/controls/MenuControls.gd index 715b922..7606f02 100644 --- a/src/components/controls/MenuControls.gd +++ b/src/components/controls/MenuControls.gd @@ -29,6 +29,9 @@ func get_controlled_node() -> Node3D: return menuSpawner.get_node("Anchor") return null + + + ## Get selected menu intem and execute action that item meant to do func call_menu_action(): var selected = menu_selector.get_selected_item() @@ -37,8 +40,16 @@ func call_menu_action(): var action = selected.get("action") if action == "menu_start_game": sfx_player.on_action_select.emit() + G.data.level = selected.items.level else: sfx_player.on_section_select.emit() + if action == "menu_level_select": + menuSpawner.open_menu_section( + controlledNode, + {items = LevelPatterns.get_menu_levels(G.settings.MAX_LEVEL)} + ) + return + if action != "placeholder_action": actions.call(selected.action) return diff --git a/src/components/gui/menu/MenuActions.gd b/src/components/gui/menu/MenuActions.gd index e3f0ed6..8c28f59 100644 --- a/src/components/gui/menu/MenuActions.gd +++ b/src/components/gui/menu/MenuActions.gd @@ -15,6 +15,13 @@ func menu_start_game(): return Utils.set_scene(self, 'LoopScene') +func menu_level_select(): + #if G.settings.MAX_LEVEL == 0: + #start_tutorial() + #return + #show_avaliable_levels() + return + func settings_fps_counter_on(): config.set_fps_counter_state.emit(true) diff --git a/src/components/gui/menu/MenuStruct.gd b/src/components/gui/menu/MenuStruct.gd index b5a3907..74906e3 100644 --- a/src/components/gui/menu/MenuStruct.gd +++ b/src/components/gui/menu/MenuStruct.gd @@ -135,7 +135,7 @@ static var menu_items := { items = { 1: { name = "start", - action = "menu_start_game", + action = "menu_level_select", }, 2: { name = "settings", @@ -165,7 +165,7 @@ static var menu_items_emoji := { items = { 1: { 'name': "🎮", - 'action': "menu_start_game", + 'action': "menu_level_select", }, 2: { 'name': "⚙️", diff --git a/src/components/level_system/LevelPatterns.gd b/src/components/level_system/LevelPatterns.gd index eae1387..76f6855 100644 --- a/src/components/level_system/LevelPatterns.gd +++ b/src/components/level_system/LevelPatterns.gd @@ -5,8 +5,14 @@ const patterns: Dictionary = { 0: [19, 18], 1: [17, 18], 2: [19, 17], - 3: [17, 17, 17], - 4: [19, 19], + # level 1 + 3: [17, 19, 14], # 1 motion + 4: [2, 3], # 2 simple motions + 5: [13, 7], # 2 motions + # level 2 + 6: [15, 1, 2], + 7: [12, 8], + 8: [6, 16], } const levels: Dictionary = { @@ -15,7 +21,39 @@ const levels: Dictionary = { random = false, }, 1: { - level_patterns = [3, 4], + level_patterns = [3, 4, 5], random = true, + # game_speed = 20, + }, + 2: { + level_patterns = [6, 7, 8], + random = true, + # game_speed = 10, } } + +static func is_level_up(nodes: int, level: int) -> bool: + match level: + 0: return nodes > 10 + 1: return nodes > 20 + _: return false + +const tutorial_item := { + name = "tutorial", + action = "menu_start_game", + level = 0, +} + +static func get_menu_levels(max_level: int): + if max_level == 0: + return {1: tutorial_item } + var menu_entries = {} + for i in range(max_level, 0, -1): + menu_entries[max_level - i + 1] = { + name = "level %s" % i, + action = "menu_start_game", + level = i, + } + menu_entries[6] = tutorial_item + + return menu_entries diff --git a/src/components/level_system/PatternGen.gd b/src/components/level_system/PatternGen.gd index cbc4d24..6a2420a 100644 --- a/src/components/level_system/PatternGen.gd +++ b/src/components/level_system/PatternGen.gd @@ -4,7 +4,7 @@ class_name PatternGen const MAX_LEVEL := 10 enum SpawnMode {TUTORIAL, DEBUG, QUEUE} -@export var level: int = G.settings.DEFAULT_LEVEL: +@export var level: int = 0: set(val): level = clamp(0, MAX_LEVEL, val) @@ -12,9 +12,16 @@ var level_queue := LevelQueue.new() func _ready(): G.level_changed.connect(_on_level_changed) + var l = G.data.get("level") + if l: + level = l add_patterns() func _on_level_changed(new_level: int): + var new_gs = LevelPatterns.levels[new_level].get("game_speed") + if new_gs: + G.settings.GAME_SPEED = new_gs + G.reload_settings.emit() level = new_level func next_pattern() -> int: diff --git a/src/components/settings/Config.gd b/src/components/settings/Config.gd index 2b79f14..e88c0f2 100644 --- a/src/components/settings/Config.gd +++ b/src/components/settings/Config.gd @@ -28,6 +28,11 @@ func _init() -> void: func _ready() -> void: set_fps_counter_state.connect(_on_fps_counter_state) set_debug_stats_state.connect(_on_debug_stats_state) + G.reload_settings.connect(_on_reload_settings) + +func _on_reload_settings(): + var gs = SettingsConfig.load_gs(config) + G.settings = gs func _on_fps_counter_state(state: bool): G.settings.FPS_COUNTER_ENABLED = state diff --git a/src/components/settings/DefaultConfig.gd b/src/components/settings/DefaultConfig.gd index f773b43..abc4480 100644 --- a/src/components/settings/DefaultConfig.gd +++ b/src/components/settings/DefaultConfig.gd @@ -6,6 +6,8 @@ const settings = { SPAWN_MODE=2, DESPAWNER_MODE=16633, SCALE_FACTOR=10, + SPAWN_SPEED=10, + GAME_SPEED=10, ROTATION_SPEED=12, MAX_LEVEL=0, }, @@ -18,6 +20,5 @@ const settings = { VSYNC_ENABLED=true, CONTROL_TYPE="FREE_SPIN", IS_CONTROL_INVERTED=false, - DEFAULT_LEVEL=0, } } diff --git a/src/components/timers/LoopTimer.gd b/src/components/timers/LoopTimer.gd index f3bc47a..0e948f5 100644 --- a/src/components/timers/LoopTimer.gd +++ b/src/components/timers/LoopTimer.gd @@ -6,15 +6,17 @@ var time_start: int # Called when the node enters the scene tree for the first time. func _ready() -> void: game_state_manager.game_state_changed.connect(_on_game_state_changed) + G.reload_settings.connect(_on_reload_settings) -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass +func _on_reload_settings(): + await timeout + stop() + start(100. / (G.settings.SPAWN_SPEED * G.settings.GAME_SPEED)) func _on_game_state_changed(old_state: GameStateManager.GameState, new_state: GameStateManager.GameState) -> void: var gs = GameStateManager.GameState if new_state == gs.GAME_ACTIVE: - start(10. / G.settings.get("SPAWN_SPEED", 10)) + start(100. / (G.settings.SPAWN_SPEED * G.settings.GAME_SPEED)) time_start = Time.get_ticks_msec() if new_state in [gs.GAME_END, gs.GAME_MENU]: stop() @@ -35,7 +37,7 @@ func get_elapsed_time() -> String: return "000:000" return format_time(raw_time) -func format_time(time: int) -> String: +static func format_time(time: int) -> String: var ms := time % 1000 var sec := float(time) / 1000 return "%d:%03d" % [sec, ms] diff --git a/src/components/timers/ScaleTimer.gd b/src/components/timers/ScaleTimer.gd index 2a9edbb..80c7eae 100644 --- a/src/components/timers/ScaleTimer.gd +++ b/src/components/timers/ScaleTimer.gd @@ -3,12 +3,14 @@ class_name ScaleTimer @onready var game_state_manager: GameStateManager = %GameStateManager +# 10 ms +const tick_dur := int(10. / 1000. ) + # Called when the node enters the scene tree for the first time. func _ready() -> void: game_state_manager.game_state_changed.connect(_on_game_state) autostart = true - # 10 ms - wait_time = 10. / 1000. + wait_time = tick_dur func _on_game_state(old_state: GameStateManager.GameState, new_state: GameStateManager.GameState): var gs = GameStateManager.GameState diff --git a/src/globals.gd b/src/globals.gd index 6026abf..7d85aeb 100644 --- a/src/globals.gd +++ b/src/globals.gd @@ -18,3 +18,6 @@ signal font_changed(new_font: FontType) @warning_ignore("unused_signal") signal level_changed(new_level: int) + +@warning_ignore("unused_signal") +signal reload_settings() diff --git a/src/models/icosahedron/components/Icosahedron.gd b/src/models/icosahedron/components/Icosahedron.gd index 3c46f2a..d280aac 100644 --- a/src/models/icosahedron/components/Icosahedron.gd +++ b/src/models/icosahedron/components/Icosahedron.gd @@ -34,7 +34,8 @@ func _ready() -> void: func _on_scale_tick() -> void: if scaling_enabled: - var sf: float = (G.settings.SCALE_FACTOR + 1000.) / 1000. + var sf: float = 1. + (G.settings.SCALE_FACTOR / 1000. ) \ + * (0.5 + (G.settings.GAME_SPEED / (10. + G.settings.GAME_SPEED))) scale_object_local(Vector3(sf, sf, sf)) func despawn(): diff --git a/src/models/icosahedron/shaders/outline_v1.gdshader b/src/models/icosahedron/shaders/outline_v1.gdshader index 0ea998c..ded4fd9 100644 --- a/src/models/icosahedron/shaders/outline_v1.gdshader +++ b/src/models/icosahedron/shaders/outline_v1.gdshader @@ -23,8 +23,9 @@ void vertex() { void fragment() { if (enable) { - ALBEDO = color.rgb; - ALPHA = 0.5; + //ALBEDO = color.rgb; + ALBEDO = vec3(0.); + ALPHA = 0.9; } else { ALPHA = 0.; } diff --git a/src/models/icosahedron/test/game_speed_test.gd b/src/models/icosahedron/test/game_speed_test.gd new file mode 100755 index 0000000..f887acc --- /dev/null +++ b/src/models/icosahedron/test/game_speed_test.gd @@ -0,0 +1,48 @@ +#!/usr/bin/env -S godot --headless -s --quit +extends SceneTree + +var G ={ + settings ={ + SPAWN_MODE=2, + DESPAWNER_MODE=16633, + ROTATION_SPEED=12, + MAX_LEVEL=0, + + SPAWN_SPEED=10, + SCALE_FACTOR=10, + GAME_SPEED=10, + } +} + +func gs_calc(x: int): + return 0.5 + (x / (10. + x)) + +func get_loop(): + return 100. / (G.settings.SPAWN_SPEED * G.settings.GAME_SPEED) + +func get_scale(): + # return 1. + ((G.settings.SCALE_FACTOR / 10.) * gs_calc(G.settings.GAME_SPEED)) / 100. + # return 1. + ( + # (G.settings.SCALE_FACTOR / 10.) + # * (0.5 + (G.settings.GAME_SPEED / (10. + G.settings.GAME_SPEED))) + # ) / 100. + return 1. + (G.settings.SCALE_FACTOR / 1000. ) * (0.5 + (G.settings.GAME_SPEED / (10. + G.settings.GAME_SPEED))) + +func main(): + print_debug(gs_calc(20)) + + print_debug("base loop: ", 1, " > ", get_loop()) + print_debug("base scale: ", 1.01, " > ", get_scale()) + G.settings.GAME_SPEED = 5 + print_debug("\nL2: gs=", G.settings.GAME_SPEED) + print_debug("loop: ", get_loop()) + print_debug("scale: ", get_scale()) + G.settings.GAME_SPEED = 20 + print_debug("\nL3: gs=", G.settings.GAME_SPEED) + print_debug("loop: ", get_loop()) + print_debug("scale: ", get_scale()) + pass + +func _init(): + main() + quit() diff --git a/src/models/icosahedron/test/variant_test.gd b/src/models/icosahedron/test/variant_test.gd index b1f85e3..c36b5ea 100644 --- a/src/models/icosahedron/test/variant_test.gd +++ b/src/models/icosahedron/test/variant_test.gd @@ -5,7 +5,7 @@ var controlledNode @onready var pattern_gen: PatternGen = $PatternGen -@export var ROTATION_SPEED: float = G.settings.ROTATION_SPEED +@export var ROTATION_SPEED: float = 12 @export_category("variant settings") @export var show_face_numbers: bool = true @@ -23,9 +23,9 @@ func get_next(): var next_type: int match spawn_type: 0: next_type = pattern_gen.next_pattern() - 1: next_type = randi_range(17, 19) + 1: next_type = randi_range(0, 19) 2: next_type = variant_type - print_debug("Spawinig next figure woth type: ", next_type) + print_debug("Spawinig next figure with type: ", next_type) spawn_next(next_type) func remove_current(): diff --git a/src/models/icosahedron/test/variant_test.tscn b/src/models/icosahedron/test/variant_test.tscn index dd89f5d..0124289 100644 --- a/src/models/icosahedron/test/variant_test.tscn +++ b/src/models/icosahedron/test/variant_test.tscn @@ -25,7 +25,7 @@ shader_parameter/bg_color = Color(0.729, 0.902, 0.992, 1) [node name="VariantTest" type="Node3D"] script = ExtResource("1_4av47") -spawn_type = 2 +spawn_type = 1 [node name="Environment" type="Node3D" parent="."]