Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Commit

Permalink
show cube points (#9)
Browse files Browse the repository at this point in the history
show cube cut points
reuse audiostreamplayer from points objects
limit point objects and cutted pieces
collision with floor reenabled
reduce lag when updating playlist with many songs (still need work)
replaced buttons on menus for itemlists
set lights on when song has no events, prevent preview play double
small improvements to event driver
  • Loading branch information
leandrodreamer authored Feb 6, 2021
1 parent 6591fe3 commit 64288d3
Show file tree
Hide file tree
Showing 22 changed files with 300 additions and 408 deletions.
Binary file modified game/BeepCube_new_material.material
Binary file not shown.
187 changes: 56 additions & 131 deletions game/BeepSaberMainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ export(NodePath) var keyboard;

var _playlists

var PlaylistButton = preload("res://game/PlaylistButton.tscn")

func _load_playlists():
var Playlists = $PlaylistMenu/Playlists

_playlists = [];

Expand Down Expand Up @@ -66,8 +63,7 @@ func _load_playlists():
for b in $SongsMenu/Songs.get_children():
b.queue_free()
return false;



if (_playlists.size() == 0):
_set_cur_playlist([])
else:
Expand Down Expand Up @@ -95,33 +91,31 @@ func _autogen_playlists(seek_path,name):
if songlist:
_playlists.append({"Name":name,"Description":"Autogenerated","Songs":songlist});

var SongButton = preload("res://game/SongButton.tscn")

func _set_cur_playlist(pl):
var current_id = $SongsMenu.get_selected_items()

var Songs = $SongsMenu/Songs

for song in Songs.get_children():
song.queue_free()
$SongsMenu.clear()

var info
var to_select = true
if pl.has("Songs"):
for dat in pl["Songs"]:
to_select = _wire_song_dat(dat,to_select);

func _wire_song_dat(dat, to_select):
var Songs = $SongsMenu/Songs
var newSongButton = SongButton.instance();
newSongButton.id = dat;
newSongButton.info = _load_song_info(_song_path(dat));
newSongButton.texture = _load_cover(_song_path(dat), newSongButton.info._coverImageFilename)
newSongButton.connect("pressed_id", self, "_select_song");
Songs.add_child(newSongButton)
if newSongButton.info and to_select:
_select_song(dat)
to_select = false
return to_select;
_wire_song_dat(dat);

#whait a frame between every cover load to prevent frezzing
yield(get_tree(),"idle_frame")
for b in range(0,$SongsMenu.get_item_count()):
$SongsMenu.set_item_icon(b,_load_cover(_song_path($SongsMenu.get_item_metadata(b)["id"]), $SongsMenu.get_item_metadata(b)["info"]._coverImageFilename))
yield(get_tree(),"idle_frame")

if current_id.size() > 0:
_select_song(current_id[0])

func _wire_song_dat(dat):
var current_song_data = {
id=dat,
info=_load_song_info(_song_path(dat))
}
$SongsMenu.add_item("%s - %s" % [current_song_data.info._songAuthorName, current_song_data.info._songName])
$SongsMenu.set_item_metadata($SongsMenu.get_item_count()-1,current_song_data)

func _song_path(dat):
if dat.has("source"): #if a source is specified then it's either in the applicable downloads folder or a subfolder
Expand Down Expand Up @@ -153,21 +147,12 @@ func _load_cover(cover_path, filename):
if not (filename.ends_with(".jpg") or filename.ends_with(".png")):
print("wrong format");
return;
if (cover_path.begins_with("res://")):
return load(cover_path+filename)
else:
var tex = ImageTexture.new();
var img = Image.new();
#var uncompressed = vr.try_zipdata(cover_path, filename);
#if uncompressed: #in case it's in an archive (too slow on Quest though)
# if filename.ends_with(".jpg"):
# img.load_jpg_from_buffer(uncompressed);
# elif filename.ends_with(".png"):
# img.load_png_from_buffer(uncompressed);
#else:
img.load(cover_path+filename);
tex.create_from_image(img); #instead of loading from resources, load form file
return tex;
var tex = ImageTexture.new();
var img = Image.new();

img.load(cover_path+filename);
tex.create_from_image(img); #instead of loading from resources, load form file
return tex;


# a loaded beat map will have an info dictionary; this is a global variable here
Expand All @@ -176,10 +161,11 @@ var _map_id = null;
var _map_info = null;
var _map_path = null;

var DifficultyButton = preload("res://game/DifficultyButton.tscn")


func _select_song(id):
if id is int:
$SongsMenu.select(id)
$SongsMenu.ensure_current_is_visible()
id = $SongsMenu.get_item_metadata(id)["id"]
_map_id = id;
_map_path = _song_path(id);
$Delete_Button.disabled = false;
Expand All @@ -190,48 +176,39 @@ func _select_song(id):

$cover.texture = _load_cover(_song_path(id), _map_info._coverImageFilename);

var Songs = $SongsMenu/Songs
for song in Songs.get_children():
if song.id == id:
song.modulate = Color(1, 0.5, 0.5)
else:
song.modulate = Color(1, 1, 1)

var Difficulties = $DifficultyMenu/Playlists
for difficulty in Difficulties.get_children():
difficulty.queue_free()
$DifficultyMenu.clear()
for ii_dif in range(_map_info._difficultyBeatmapSets[0]._difficultyBeatmaps.size()):
var newDifficultyButton = DifficultyButton.instance()
newDifficultyButton.id = ii_dif
var current_dif_data = {
id = ii_dif,
Name = _map_info._difficultyBeatmapSets[0]._difficultyBeatmaps[ii_dif]._difficulty
}
var BMPS = _map_info._difficultyBeatmapSets[0]._difficultyBeatmaps
newDifficultyButton.Name = _map_info._difficultyBeatmapSets[0]._difficultyBeatmaps[ii_dif]._difficulty
newDifficultyButton.connect("pressed_id", self, "_select_difficulty")
Difficulties.add_child(newDifficultyButton)
$DifficultyMenu.add_item(current_dif_data.Name)
$DifficultyMenu.set_item_metadata($DifficultyMenu.get_item_count()-1,current_dif_data)

_select_difficulty(0)

#preview song
$song_prev.stop()
var snd_file = File.new()
snd_file.open(_map_info._path + _map_info._songFilename, File.READ) #works whether it's a resource or a file
var stream = AudioStreamOGGVorbis.new()
stream.data = snd_file.get_buffer(snd_file.get_len())
snd_file.close()
$song_prev.stream = stream;
$song_prev.play()
if not _beepsaber.song_player.playing:
var snd_file = File.new()
snd_file.open(_map_info._path + _map_info._songFilename, File.READ) #works whether it's a resource or a file
var stream = AudioStreamOGGVorbis.new()
stream.data = snd_file.get_buffer(snd_file.get_len())
snd_file.close()
$song_prev.stream = stream;
$song_prev.play()


var _map_difficulty = 0
var _map_difficulty_name = ""
var _map_difficulty_noteJumpMovementSpeed = 9.0

func _select_difficulty(id):
_map_difficulty = id
var Difficulties = $DifficultyMenu/Playlists
for difficulty in Difficulties.get_children():
difficulty.modulate = Color(1, 1, 1)
Difficulties.get_child(id).modulate = Color(1, 0.5, 0.5)
_map_difficulty_name = Difficulties.get_child(id).text
var item_meta = $DifficultyMenu.get_item_metadata(id)
_map_difficulty = item_meta["id"]
_map_difficulty_name = item_meta["Name"]
$DifficultyMenu.select(id)


func _load_map_and_start():
Expand Down Expand Up @@ -350,51 +327,6 @@ func _check_and_request_permission():
return true;



# Note (19.10.2020): downloading of unknown songs is currently disabled
# as this will need special handling also on the quest
#
#var download_id = ""
#func _download_song_id(id):
# download_id = id
# $HTTPRequest.request("https://beatsaver.com/api/download/key/"+id)
# return null

#func extract_file(zip_file, fileName, destination):
# var gdunzip = load('res://addons/gdunzip/gdunzip.gd').new()
# var loaded = gdunzip.load(zip_file)
# var file = File.new()
# var uncompressed = gdunzip.uncompress(fileName)
# file.open(destination+"/"+fileName, File.WRITE)
# file.store_buffer(uncompressed)
# file.close()
# print("DECOMPRESSED: "+fileName)
#
#
#func unzip(zip_file, destination):
# var gdunzip = load('res://addons/gdunzip/gdunzip.gd').new()
# var loaded = gdunzip.load(zip_file)
# if !loaded:
# return false
# for f in gdunzip.files:
# # extract_file(zip_file, f, destination) # NOT WORKING PROPERLY
# print(f)
#
#
#func _on_HTTPRequest_request_completed(result, response_code, headers, body):
# var directory = Directory.new()
# if response_code == 200:
# print("Downloaded song: "+download_id)
# directory.make_dir("res://game/data/maps/Songs/"+download_id)
# var file = File.new()
# file.open("res://game/data/maps/Songs/"+download_id+"/temp.zip", File.WRITE)
# file.store_buffer(body)
# file.close()
# unzip("res://game/data/maps/Songs/"+download_id+"/temp.zip", "res://game/data/maps/Songs/"+download_id)
# else:
# print("Failed to download song: "+download_id)


func _on_LoadPlaylists_Button_pressed():
# Note: this call is non-blocking; so a user has to click again after
# granting the permissions; we need to find a solutio for this
Expand All @@ -420,21 +352,14 @@ func _text_input_changed():
_clean_search()
return
var most_similar = 0.0
var results = false
for song in $SongsMenu/Songs.get_children():
var similarity = song.text.similarity(text)
song.visible = similarity != 0
if song.visible:
if similarity > most_similar:
most_similar = similarity
$SongsMenu/Songs.move_child(song,0)
results = true
if not results:
_clean_search()
for song in range(0,$SongsMenu.get_item_count()):
var similarity = $SongsMenu.get_item_text(song).similarity(text)
if similarity > most_similar:
most_similar = similarity
$SongsMenu.move_item(song,0)

func _clean_search():
for song in $SongsMenu/Songs.get_children():
song.visible = true
$SongsMenu.sort_items_by_text()
$Search_Button/Label.text = ""


Expand Down
69 changes: 37 additions & 32 deletions game/BeepSaberMainMenu.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=17 format=2]

[ext_resource path="res://OQ_Toolkit/OQ_UI2D/theme/oq_ui2d_standard.theme" type="Theme" id=1]
[ext_resource path="res://game/data/beepsaber_logo.png" type="Texture" id=2]
[ext_resource path="res://game/BeepSaberMainMenu.gd" type="Script" id=3]
[ext_resource path="res://game/data/maps/Songs/TheFatRat_Timelapse/cover.jpg" type="Texture" id=4]
[ext_resource path="res://OQ_Toolkit/OQ_UI2D/theme/RobotoMono-Medium.ttf" type="DynamicFontData" id=5]
[ext_resource path="res://game/vr_slider.gd" type="Script" id=6]

[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0, 0, 0, 1 )
Expand Down Expand Up @@ -45,14 +47,28 @@ border_width_right = 5
border_width_bottom = 5
border_color = Color( 1, 1, 1, 1 )

[sub_resource type="StyleBoxFlat" id=6]
[sub_resource type="DynamicFont" id=6]
size = 35
font_data = ExtResource( 5 )

[sub_resource type="Theme" id=7]
default_font = SubResource( 6 )

[sub_resource type="StyleBoxFlat" id=8]
bg_color = Color( 0, 0, 0, 1 )
border_width_left = 3
border_width_top = 3
border_width_right = 3
border_width_bottom = 3
border_width_left = 4
border_width_top = 4
border_width_right = 4
border_width_bottom = 4
border_color = Color( 1, 1, 1, 1 )

[sub_resource type="DynamicFont" id=9]
size = 28
font_data = ExtResource( 5 )

[sub_resource type="Theme" id=10]
default_font = SubResource( 9 )

[node name="BeepSaberMainMenu" type="Panel"]
margin_right = 1408.0
margin_bottom = 640.0
Expand Down Expand Up @@ -154,48 +170,35 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="SongsMenu" type="ScrollContainer" parent="."]
[node name="SongsMenu" type="ItemList" parent="."]
margin_left = 16.0
margin_top = 64.0
margin_right = 848.0
margin_bottom = 560.0
custom_styles/bg = SubResource( 6 )
scroll_deadzone = 90
theme = SubResource( 7 )
custom_styles/bg = SubResource( 8 )
custom_colors/font_color_selected = Color( 1, 0.494118, 0.494118, 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
fixed_icon_size = Vector2( 60, 60 )
script = ExtResource( 6 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Songs" type="VBoxContainer" parent="SongsMenu"]
margin_left = 3.0
margin_top = 3.0
margin_right = 3.0
margin_bottom = 3.0
size_flags_horizontal = 2

[node name="DifficultyMenu" type="ScrollContainer" parent="."]
[node name="DifficultyMenu" type="ItemList" parent="."]
margin_left = 864.0
margin_top = 64.0
margin_right = 1040.0
margin_bottom = 320.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_styles/bg = SubResource( 6 )
follow_focus = true
scroll_horizontal_enabled = false
scroll_vertical_enabled = false
scroll_deadzone = 140
theme = SubResource( 10 )
custom_styles/bg = SubResource( 8 )
custom_colors/font_color_selected = Color( 1, 0.494118, 0.494118, 1 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
script = ExtResource( 6 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Playlists" type="VBoxContainer" parent="DifficultyMenu"]
margin_left = 3.0
margin_top = 3.0
margin_right = 173.0
margin_bottom = 253.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="HTTPRequest" type="HTTPRequest" parent="."]
download_chunk_size = 65536
timeout = 4
Expand Down Expand Up @@ -242,5 +245,7 @@ __meta__ = {
[connection signal="button_up" from="Delete_Button" to="." method="_on_Delete_Button_button_up"]
[connection signal="pressed" from="Exit_Button" to="." method="_on_Exit_Button_pressed"]
[connection signal="button_up" from="Search_Button" to="." method="_on_Search_Button_button_up"]
[connection signal="item_selected" from="SongsMenu" to="." method="_select_song"]
[connection signal="item_selected" from="DifficultyMenu" to="." method="_select_difficulty"]
[connection signal="request_completed" from="HTTPRequest" to="." method="_on_HTTPRequest_request_completed"]
[connection signal="pressed" from="LoadPlaylists_Button" to="." method="_on_LoadPlaylists_Button_pressed"]
Loading

0 comments on commit 64288d3

Please sign in to comment.