@@ -18,6 +18,26 @@ func _ready() -> void:
1818 _update_content ()
1919
2020
21+ func add_imported_level (level_name : String ) -> void :
22+ _placeholder_buttons [- 1 ].queue_free ()
23+ _placeholder_buttons .remove_at (_placeholder_buttons .size () - 1 )
24+
25+ var level_button := LevelButton .new ()
26+ level_button .on_delete_level_button .connect (_update_last_level )
27+ _level_buttons .append (level_button )
28+ level_grid .add_child (level_button )
29+
30+ var progress = LevelProgress .new ()
31+ progress .move_left = - 1000
32+ progress .is_unlocked = true
33+ progress .is_completed = true
34+
35+ level_button .construct (level_name , progress , GlobalConst .LevelGroup .CUSTOM )
36+ level_grid .move_child (level_button , _level_buttons .size () - 1 )
37+ # Show next page button if there are no placeholder buttons
38+ _update_buttons (_placeholder_buttons .size () == 0 )
39+
40+
2141func _on_state_change (new_state : GlobalConst .GameState ) -> void :
2242 match new_state :
2343 GlobalConst .GameState .MAIN_MENU :
@@ -46,7 +66,11 @@ func _update_content() -> void:
4666 var levels_progress : Dictionary
4767 # get extra level for test next page
4868 levels_progress = GameManager .get_page_levels (_world , first_level , last_level + 1 )
49- _update_buttons (levels_progress .size () > PAGE_SIZE )
69+ match _world :
70+ GlobalConst .LevelGroup .MAIN :
71+ _update_buttons (levels_progress .size () > PAGE_SIZE )
72+ GlobalConst .LevelGroup .CUSTOM :
73+ _update_buttons (levels_progress .size () > PAGE_SIZE - 1 )
5074
5175 var max_level_btn := mini (levels_progress .size (), PAGE_SIZE )
5276 # remove excess level button
@@ -101,7 +125,12 @@ func _update_last_level(ref: LevelButton) -> void:
101125 var levels_progress : Dictionary
102126 # get extra level for test next page
103127 levels_progress = GameManager .get_page_levels (_world , last_level , last_level + 1 )
104- _update_buttons (levels_progress .size () > 1 )
128+
129+ match _world :
130+ GlobalConst .LevelGroup .MAIN :
131+ _update_buttons (levels_progress .size () > 1 )
132+ GlobalConst .LevelGroup .CUSTOM :
133+ _update_buttons (levels_progress .size () > 0 )
105134
106135 if levels_progress .size () > 0 :
107136 # add level button
@@ -154,3 +183,7 @@ func _on_custom_btn_pressed() -> void:
154183 _world = GlobalConst .LevelGroup .CUSTOM
155184 _current_page = 1
156185 _update_content ()
186+
187+
188+ func _add_empty_page () -> void :
189+ pass
0 commit comments