Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion prefabs/map_info_container.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[ext_resource type="Theme" uid="uid://dhuhu3mmaew1a" path="res://themes/theme.tres" id="4_4d08m"]
[ext_resource type="Script" uid="uid://c1235cyjfh4rl" path="res://scripts/ui/LinkPopupButton.cs" id="4_dccrs"]
[ext_resource type="Texture2D" uid="uid://7px5v8ikildx" path="res://user/skins/default/ui/buttons/favorite.png" id="5_1m5pv"]
[ext_resource type="Texture2D" uid="uid://dkpbociv8fgfd" path="res://user/skins/default/ui/buttons/export.png" id="5_g02bu"]
[ext_resource type="Script" uid="uid://dy45uerqy0yd7" path="res://scripts/ui/FlatPreview.cs" id="5_svokg"]
[ext_resource type="Texture2D" uid="uid://degvlg4p0if70" path="res://user/skins/default/ui/buttons/add_video.png" id="6_g02bu"]
[ext_resource type="Texture2D" uid="uid://cgxbwx4f28lt2" path="res://user/skins/default/ui/buttons/copy.png" id="7_oibm8"]
Expand Down Expand Up @@ -175,7 +176,7 @@ outline_color = Color(0, 0, 0, 1)
shadow_size = 4
shadow_color = Color(0, 0, 0, 1)

[node name="MapInfoContainer" type="Panel" unique_id=150923669 node_paths=PackedStringArray("info", "dim", "coverBackground", "cover", "infoSubholder", "mainLabel", "extraLabel", "artistLink", "favoriteButton", "videoButton", "videoDialog", "copyButton", "copyDialog", "deleteButton", "actions", "preview", "speedHolder", "speedPresets", "playHolder", "startButton", "leaderboard", "lbScrollContainer", "lbContainer", "lbExpand", "lbHide")]
[node name="MapInfoContainer" type="Panel" unique_id=150923669 node_paths=PackedStringArray("info", "dim", "coverBackground", "cover", "infoSubholder", "mainLabel", "extraLabel", "artistLink", "exportButton", "favoriteButton", "videoButton", "videoDialog", "copyButton", "copyDialog", "deleteButton", "actions", "preview", "speedHolder", "speedPresets", "playHolder", "startButton", "leaderboard", "lbScrollContainer", "lbContainer", "lbExpand", "lbHide")]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
Expand All @@ -193,6 +194,7 @@ infoSubholder = NodePath("Info/ScrollContainer/HBoxContainer")
mainLabel = NodePath("Info/ScrollContainer/HBoxContainer/Subholder/Main")
extraLabel = NodePath("Info/ScrollContainer/HBoxContainer/Subholder/Extra")
artistLink = NodePath("Info/ScrollContainer/HBoxContainer/Background/ArtistLink")
exportButton = NodePath("Info/ScrollContainer/HBoxContainer/Subholder/Buttons/Export")
favoriteButton = NodePath("Info/ScrollContainer/HBoxContainer/Subholder/Buttons/Favorite")
videoButton = NodePath("Info/ScrollContainer/HBoxContainer/Subholder/Buttons/Video")
videoDialog = NodePath("Info/ScrollContainer/HBoxContainer/Subholder/Buttons/Video/VideoDialog")
Expand Down Expand Up @@ -357,6 +359,17 @@ grow_horizontal = 0
grow_vertical = 0
alignment = 2

[node name="Export" type="Button" parent="Info/ScrollContainer/HBoxContainer/Subholder/Buttons" unique_id=2033571562]
layout_mode = 2
tooltip_text = "Exports map into a .phxm file to share easily"
focus_mode = 0
mouse_default_cursor_shape = 2
theme = ExtResource("4_4d08m")
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_constants/icon_max_width = 24
icon = ExtResource("5_g02bu")
icon_alignment = 1

[node name="Favorite" type="Button" parent="Info/ScrollContainer/HBoxContainer/Subholder/Buttons" unique_id=1022164792]
layout_mode = 2
tooltip_text = "Favorite"
Expand Down Expand Up @@ -390,6 +403,7 @@ filters = PackedStringArray("*.mp4")
use_native_dialog = true

[node name="Copy" type="Button" parent="Info/ScrollContainer/HBoxContainer/Subholder/Buttons" unique_id=2053076461]
visible = false
layout_mode = 2
tooltip_text = "Copy"
focus_mode = 0
Expand Down
6 changes: 2 additions & 4 deletions scripts/SoundManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Godot;

Expand Down Expand Up @@ -221,7 +219,7 @@ public static void PlayJukebox(Map map, bool setRichPresence = true)

JukeboxIndex = MapManager.Maps.FindIndex(x => x.Id == map.Id);

Song.Stream = Util.Audio.LoadFromFile($"{MapUtil.MapsCacheFolder}/{map.Name}/audio.{map.AudioExt}");
Song.Stream = Util.Audio.LoadFromFile($"{MapUtil.MapsFolder}/{map.Name}/audio.{map.AudioExt}");
Song.Play();

Instance.JukeboxPlayed?.Invoke(map);
Expand Down Expand Up @@ -280,7 +278,7 @@ public static void StartMapSelectionPlayback(Map map, bool setRichPresence = tru
}
}

Song.Stream = Util.Audio.LoadFromFile($"{MapUtil.MapsCacheFolder}/{map.Name}/audio.{map.AudioExt}");
Song.Stream = Util.Audio.LoadFromFile($"{MapUtil.MapsFolder}/{map.Name}/audio.{map.AudioExt}");
Song.Play(0);

Instance.JukeboxPlayed?.Invoke(map);
Expand Down
10 changes: 6 additions & 4 deletions scripts/game/managers/ReplayManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using Godot;
Expand Down Expand Up @@ -28,7 +29,7 @@ public enum Mode
public string ReplayPath;
public Vector2 CursorPosition { get; private set; }

private FileAccess file;
private Godot.FileAccess file;
private ulong statusOffset, frameCountOffset;

public void NewReplay(Attempt attempt)
Expand All @@ -39,7 +40,7 @@ public void NewReplay(Attempt attempt)

ReplayPath = $"{Constants.USER_FOLDER}/replays/{attempt.ID}.phxr";

file = FileAccess.Open(ReplayPath, FileAccess.ModeFlags.Write);
file = Godot.FileAccess.Open(ReplayPath, Godot.FileAccess.ModeFlags.Write);

file.StoreString("phxr"); // sig
file.Store8(1); // replay file version
Expand Down Expand Up @@ -69,7 +70,8 @@ public void NewReplay(Attempt attempt)
}

string serializedMods = string.Join("_", mods);
string mapName = attempt.Map.FilePath.GetFile().GetBaseName();
// string mapName = attempt.Map.FilePath.GetFile().GetBaseName();
string mapName = Path.GetFileName(attempt.Map.FolderPath);
string player = "You";

void storeSizedString(string data)
Expand Down Expand Up @@ -126,7 +128,7 @@ public void SaveReplay(Attempt attempt)
file.Close();

// open replay to store hash
file = FileAccess.Open($"{Constants.USER_FOLDER}/replays/{attempt.ID}.phxr", FileAccess.ModeFlags.ReadWrite);
file = Godot.FileAccess.Open($"{Constants.USER_FOLDER}/replays/{attempt.ID}.phxr", Godot.FileAccess.ModeFlags.ReadWrite);
ulong length = file.GetLength();
byte[] hash = SHA256.HashData(file.GetBuffer((long)length));
file.StoreBuffer(hash);
Expand Down
2 changes: 1 addition & 1 deletion scripts/game/ui/PlaytestOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void UpdatePlaytestOverlay(bool show)
speedValue = speedDouble;
}

var map = MapParser.Decode(oldAttempt.Map.FilePath, Rhythia.AudioFilePath);
var map = MapParser.Decode(oldAttempt.Map.FolderPath, Rhythia.AudioFilePath);

Game.Attempt = new(map, speedValue, GetStartFrom(startFromEdit) * 1000, Rhythia.TempCam, Rhythia.TempMods);
SceneManager.ReloadCurrentScene();
Expand Down
28 changes: 18 additions & 10 deletions scripts/map/Map.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -17,15 +16,20 @@ public partial class Map : RefCounted
public int Id { get; set; }

public string Name { get; set; } = string.Empty;
public string LastModifiedMetadata { get; set; }
public string LastModifiedNotes { get; set; }

public string Hash { get; set; }
/// <summary>
/// The hash of the metadata.json, then the objects.phxmo in order
/// </summary>
public string MetadataObjectHash { get; set; }

public string Collection { get; set; } = string.Empty;

[Ignore]
public MapSet MapSet { get; set; }

public string FilePath { get; set; } = string.Empty;
public string FolderPath { get; set; } = string.Empty;

public bool Favorite { get; set; }

Expand Down Expand Up @@ -86,7 +90,7 @@ public Note[] TryParseNotes()
{
try
{
notes = MapParser.DecodePHXMO($"{MapUtil.MapsCacheFolder}/{Name}/objects.phxmo");
notes = MapParser.DecodePHXMO($"{MapUtil.MapsFolder}/{Name}/objects.phxmo");
return notes;
}
catch
Expand All @@ -97,7 +101,7 @@ public Note[] TryParseNotes()

private Texture2D getCover()
{
string path = $"{MapUtil.MapsCacheFolder}/{Name}";
string path = $"{MapUtil.MapsFolder}/{Name}";

if (cover == DefaultCover && File.Exists($"{path}/cover.png"))
{
Expand All @@ -115,10 +119,13 @@ private Texture2D getCover()

public Map() { }

public Map(string filePath, Note[] data = null, string id = null, string artist = "", string title = "", float rating = 0, string[] mappers = null, int difficulty = 0, string difficultyName = null, int? length = null, byte[] audioBuffer = null, byte[] coverBuffer = null, byte[] videoBuffer = null, bool ephemeral = false, string artistLink = "", string artistPlatform = "")
public Map(string folderPath, Note[] data = null, string id = null, string artist = "", string title = "", float rating = 0, string[] mappers = null, int difficulty = 0, string difficultyName = null, int? length = null, byte[] audioBuffer = null, byte[] coverBuffer = null, byte[] videoBuffer = null, bool ephemeral = false, string artistLink = "", string artistPlatform = "")
{
FilePath = filePath;
FolderPath = folderPath;
Ephemeral = ephemeral;
MetadataObjectHash = "";
LastModifiedMetadata = "";
LastModifiedNotes = "";
Artist = (artist ?? "").StripEscapes();
ArtistLink = artistLink;
ArtistPlatform = artistPlatform;
Expand All @@ -145,6 +152,7 @@ public Map(string filePath, Note[] data = null, string id = null, string artist

public string EncodeMeta()
{
string path = $"{MapUtil.MapsFolder}/{Name}";
return Json.Stringify(new Godot.Collections.Dictionary()
{
["ID"] = Name,
Expand All @@ -157,9 +165,9 @@ public string EncodeMeta()
["Difficulty"] = Difficulty,
["DifficultyName"] = DifficultyName,
["Length"] = Length,
["HasAudio"] = AudioBuffer != null,
["HasCover"] = CoverBuffer != null,
["HasVideo"] = VideoBuffer != null,
["HasAudio"] = AudioBuffer != null && File.Exists($"{path}/audio.{AudioExt}"),
["HasCover"] = CoverBuffer != null && File.Exists($"{path}/cover.png"),
["HasVideo"] = VideoBuffer != null && File.Exists($"{path}/video.mp4"),
["AudioExt"] = AudioExt
}, "\t");
}
Expand Down
Loading