Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
VolcanicArts committed May 9, 2023
2 parents 441afb3 + 29c8ac6 commit 96daec1
Show file tree
Hide file tree
Showing 113 changed files with 1,996 additions and 1,214 deletions.
4 changes: 2 additions & 2 deletions VRCOSC.Desktop/VRCOSC.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<ApplicationIcon>game.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>0.0.0</Version>
<FileVersion>2023.503.0</FileVersion>
<FileVersion>2023.509.0</FileVersion>
<Title>VRCOSC</Title>
<Authors>VolcanicArts</Authors>
<Company>VolcanicArts</Company>
<Nullable>enable</Nullable>
<AssemblyVersion>2023.503.0</AssemblyVersion>
<AssemblyVersion>2023.509.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\VRCOSC.Game\VRCOSC.Game.csproj" />
Expand Down
36 changes: 17 additions & 19 deletions VRCOSC.Game/ChatBox/Clips/Clip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using VRCOSC.Game.Managers;

namespace VRCOSC.Game.ChatBox.Clips;

Expand Down Expand Up @@ -36,12 +37,12 @@ public void InjectDependencies(ChatBoxManager chatBoxManager)
{
this.chatBoxManager = chatBoxManager;
AssociatedModules.BindCollectionChanged((_, e) => onAssociatedModulesChanged(e), true);
AssociatedModules.BindCollectionChanged((_, _) => chatBoxManager.Save());
Enabled.BindValueChanged(_ => chatBoxManager.Save());
Name.BindValueChanged(_ => chatBoxManager.Save());
Priority.BindValueChanged(_ => chatBoxManager.Save());
States.BindCollectionChanged((_, _) => chatBoxManager.Save());
Events.BindCollectionChanged((_, _) => chatBoxManager.Save());
AssociatedModules.BindCollectionChanged((_, _) => chatBoxManager.Serialise());
Enabled.BindValueChanged(_ => chatBoxManager.Serialise());
Name.BindValueChanged(_ => chatBoxManager.Serialise());
Priority.BindValueChanged(_ => chatBoxManager.Serialise());
States.BindCollectionChanged((_, _) => chatBoxManager.Serialise());
Events.BindCollectionChanged((_, _) => chatBoxManager.Serialise());

chatBoxManager.TimelineLength.BindValueChanged(_ =>
{
Expand Down Expand Up @@ -188,14 +189,11 @@ private void removeInvalidStates(List<ClipState> localStates)

public string GetFormattedText() => currentEvent is not null ? formatText(currentEvent.Value.Item1) : formatText(currentState!);

private string formatText(ClipState clipState) => formatText(clipState.Format.Value);
private string formatText(ClipEvent clipEvent) => formatText(clipEvent.Format.Value);

private string formatText(string text)
private string formatText(IProvidesFormat formatter)
{
var returnText = text;
var returnText = formatter.GetFormat();

AvailableVariables.ForEach(clipVariable =>
EnumerableExtensions.ForEach(AvailableVariables, clipVariable =>
{
if (!chatBoxManager.ModuleEnabledCache[clipVariable.Module]) return;

Expand Down Expand Up @@ -255,14 +253,14 @@ private void addStatesOfAddedModule(string moduleName)
localCurrentStatesCopy.ForEach(newStateLocal =>
{
newStateLocal.States.Add((moduleName, newStateName));
newStateLocal.Enabled.BindValueChanged(_ => chatBoxManager.Save());
newStateLocal.Format.BindValueChanged(_ => chatBoxManager.Save());
newStateLocal.Enabled.BindValueChanged(_ => chatBoxManager.Serialise());
newStateLocal.Format.BindValueChanged(_ => chatBoxManager.Serialise());
});

States.AddRange(localCurrentStatesCopy);
var singleState = new ClipState(newStateMetadata);
singleState.Enabled.BindValueChanged(_ => chatBoxManager.Save());
singleState.Format.BindValueChanged(_ => chatBoxManager.Save());
singleState.Enabled.BindValueChanged(_ => chatBoxManager.Serialise());
singleState.Format.BindValueChanged(_ => chatBoxManager.Serialise());
States.Add(singleState);
}
}
Expand Down Expand Up @@ -290,9 +288,9 @@ private void addEventsOfAddedModules(NotifyCollectionChangedEventArgs e)
foreach (var (_, metadata) in events)
{
var newEvent = new ClipEvent(metadata);
newEvent.Enabled.BindValueChanged(_ => chatBoxManager.Save());
newEvent.Format.BindValueChanged(_ => chatBoxManager.Save());
newEvent.Length.BindValueChanged(_ => chatBoxManager.Save());
newEvent.Enabled.BindValueChanged(_ => chatBoxManager.Serialise());
newEvent.Format.BindValueChanged(_ => chatBoxManager.Serialise());
newEvent.Length.BindValueChanged(_ => chatBoxManager.Serialise());
Events.Add(newEvent);
}
}
Expand Down
4 changes: 3 additions & 1 deletion VRCOSC.Game/ChatBox/Clips/ClipEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace VRCOSC.Game.ChatBox.Clips;

public class ClipEvent
public class ClipEvent : IProvidesFormat
{
public readonly string Module;
public readonly string Lookup;
Expand All @@ -32,6 +32,8 @@ public ClipEvent(ClipEventMetadata metadata)
Length.Value = metadata.DefaultLength;
Length.Default = metadata.DefaultLength;
}

public string GetFormat() => Format.Value;
}

public class ClipEventMetadata
Expand Down
4 changes: 3 additions & 1 deletion VRCOSC.Game/ChatBox/Clips/ClipState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace VRCOSC.Game.ChatBox.Clips;

public class ClipState
public class ClipState : IProvidesFormat
{
public List<(string, string)> States { get; private init; } = null!;

Expand Down Expand Up @@ -51,6 +51,8 @@ public ClipState(ClipStateMetadata metadata)
Format.Value = metadata.DefaultFormat;
Format.Default = metadata.DefaultFormat;
}

public string GetFormat() => Format.Value;
}

public class ClipStateMetadata
Expand Down
9 changes: 9 additions & 0 deletions VRCOSC.Game/ChatBox/Clips/IProvidesFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) VolcanicArts. Licensed under the GPL-3.0 License.
// See the LICENSE file in the repository root for full license text.

namespace VRCOSC.Game.ChatBox.Clips;

public interface IProvidesFormat
{
public string GetFormat();
}
29 changes: 23 additions & 6 deletions VRCOSC.Game/ChatBox/DefaultTimeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using VRCOSC.Game.ChatBox.Clips;
using VRCOSC.Game.Managers;

namespace VRCOSC.Game.ChatBox;

Expand All @@ -14,6 +15,7 @@ public static IEnumerable<Clip> GenerateDefaultTimeline(ChatBoxManager chatBoxMa
yield return generateHwsClip(chatBoxManager);
yield return generateWeatherClip(chatBoxManager);
yield return generateChatBoxTextClip(chatBoxManager);
yield return generateHeartrateClip(chatBoxManager);
yield return generateMediaClip(chatBoxManager);
yield return generateSpeechToTextClip(chatBoxManager);
}
Expand All @@ -22,7 +24,7 @@ private static Clip generateClockClip(ChatBoxManager chatBoxManager)
{
var clip = chatBoxManager.CreateClip();
clip.Name.Value = @"Clock";
clip.Priority.Value = 0;
clip.Priority.Value = chatBoxManager.PriorityCount.Value - 7;
clip.Start.Value = 0;
clip.End.Value = 60;
clip.AssociatedModules.Add(@"clockmodule");
Expand All @@ -35,7 +37,7 @@ private static Clip generateHwsClip(ChatBoxManager chatBoxManager)
{
var clip = chatBoxManager.CreateClip();
clip.Name.Value = @"Hardware Stats";
clip.Priority.Value = 1;
clip.Priority.Value = chatBoxManager.PriorityCount.Value - 6;
clip.Start.Value = 0;
clip.End.Value = 60;
clip.AssociatedModules.Add(@"hardwarestatsmodule");
Expand All @@ -48,7 +50,7 @@ private static Clip generateWeatherClip(ChatBoxManager chatBoxManager)
{
var clip = chatBoxManager.CreateClip();
clip.Name.Value = @"Weather";
clip.Priority.Value = 2;
clip.Priority.Value = chatBoxManager.PriorityCount.Value - 5;
clip.Start.Value = 0;
clip.End.Value = 60;
clip.AssociatedModules.Add(@"weathermodule");
Expand All @@ -61,7 +63,7 @@ private static Clip generateChatBoxTextClip(ChatBoxManager chatBoxManager)
{
var clip = chatBoxManager.CreateClip();
clip.Name.Value = @"ChatBox Text";
clip.Priority.Value = 3;
clip.Priority.Value = chatBoxManager.PriorityCount.Value - 4;
clip.Start.Value = 0;
clip.End.Value = 60;
clip.AssociatedModules.Add(@"chatboxtextmodule");
Expand All @@ -70,11 +72,26 @@ private static Clip generateChatBoxTextClip(ChatBoxManager chatBoxManager)
return clip;
}

private static Clip generateHeartrateClip(ChatBoxManager chatBoxManager)
{
var clip = chatBoxManager.CreateClip();
clip.Name.Value = @"Heartrate";
clip.Priority.Value = chatBoxManager.PriorityCount.Value - 3;
clip.Start.Value = 0;
clip.End.Value = 60;
clip.AssociatedModules.Add(@"hyperatemodule");
clip.AssociatedModules.Add(@"pulsoidmodule");
clip.GetStateFor(@"hyperatemodule", @"default")!.Enabled.Value = true;
clip.GetStateFor(@"pulsoidmodule", @"default")!.Enabled.Value = true;

return clip;
}

private static Clip generateMediaClip(ChatBoxManager chatBoxManager)
{
var clip = chatBoxManager.CreateClip();
clip.Name.Value = @"Media";
clip.Priority.Value = 4;
clip.Priority.Value = chatBoxManager.PriorityCount.Value - 2;
clip.Start.Value = 0;
clip.End.Value = 60;
clip.AssociatedModules.Add(@"mediamodule");
Expand All @@ -87,7 +104,7 @@ private static Clip generateSpeechToTextClip(ChatBoxManager chatBoxManager)
{
var clip = chatBoxManager.CreateClip();
clip.Name.Value = @"Speech To Text";
clip.Priority.Value = 5;
clip.Priority.Value = chatBoxManager.PriorityCount.Value - 1;
clip.Start.Value = 0;
clip.End.Value = 60;
clip.AssociatedModules.Add(@"speechtotextmodule");
Expand Down
12 changes: 0 additions & 12 deletions VRCOSC.Game/ChatBox/Serialisation/ITimelineSerialiser.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Framework.Extensions.IEnumerableExtensions;
using VRCOSC.Game.Managers;

namespace VRCOSC.Game.ChatBox.Serialisation.V1.Structures;

Expand Down
97 changes: 70 additions & 27 deletions VRCOSC.Game/ChatBox/Serialisation/V1/TimelineSerialiser.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,93 @@
// Copyright (c) VolcanicArts. Licensed under the GPL-3.0 License.
// See the LICENSE file in the repository root for full license text.

using System.IO;
using System.Text;
using Newtonsoft.Json;
using System;
using System.Collections.Immutable;
using System.Linq;
using osu.Framework.Platform;
using VRCOSC.Game.ChatBox.Serialisation.V1.Structures;
using VRCOSC.Game.Graphics.Notifications;
using VRCOSC.Game.Managers;
using VRCOSC.Game.Serialisation;

namespace VRCOSC.Game.ChatBox.Serialisation.V1;

public class TimelineSerialiser : ITimelineSerialiser
public class TimelineSerialiser : Serialiser<ChatBoxManager, SerialisableTimeline>
{
private const string file_name = @"chatbox.json";
private readonly Storage storage;
private readonly object saveLock = new();
protected override string FileName => @"chatbox.json";

public TimelineSerialiser(Storage storage)
public TimelineSerialiser(Storage storage, NotificationContainer notification, ChatBoxManager chatBoxManager)
: base(storage, notification, chatBoxManager)
{
this.storage = storage;
}

public void Serialise(ChatBoxManager chatBoxManager)
protected override SerialisableTimeline GetSerialisableData(ChatBoxManager chatBoxManager) => new(chatBoxManager);

protected override void ExecuteAfterDeserialisation(ChatBoxManager chatBoxManager, SerialisableTimeline data)
{
lock (saveLock)
chatBoxManager.Clips.Clear();

chatBoxManager.TimelineLength.Value = TimeSpan.FromTicks(data.Ticks);

data.Clips.ForEach(clip =>
{
var data = Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(new SerialisableTimeline(chatBoxManager)));
clip.AssociatedModules.ToImmutableList().ForEach(moduleName =>
{
if (!chatBoxManager.StateMetadata.ContainsKey(moduleName) && !chatBoxManager.EventMetadata.ContainsKey(moduleName))
{
clip.AssociatedModules.Remove(moduleName);

using var stream = storage.CreateFileSafely(file_name);
stream.Write(data);
}
}
clip.States.ToImmutableList().ForEach(clipState =>
{
clipState.States.RemoveAll(pair => pair.Module == moduleName);
});

public SerialisableTimeline? Deserialise()
{
lock (saveLock)
clip.Events.RemoveAll(clipEvent => clipEvent.Module == moduleName);

return;
}

clip.States.ToImmutableList().ForEach(clipState =>
{
clipState.States.RemoveAll(pair => !chatBoxManager.StateMetadata[pair.Module].ContainsKey(pair.Lookup));
});

clip.Events.RemoveAll(clipEvent => !chatBoxManager.EventMetadata[clipEvent.Module].ContainsKey(clipEvent.Lookup));
});
});

data.Clips.ForEach(clip =>
{
if (!storage.Exists(file_name)) return null;
var newClip = chatBoxManager.CreateClip();

newClip.Enabled.Value = clip.Enabled;
newClip.Name.Value = clip.Name;
newClip.Priority.Value = clip.Priority;
newClip.Start.Value = clip.Start;
newClip.End.Value = clip.End;

newClip.AssociatedModules.AddRange(clip.AssociatedModules);

try
clip.States.ForEach(clipState =>
{
return JsonConvert.DeserializeObject<SerialisableTimeline>(Encoding.Unicode.GetString(File.ReadAllBytes(storage.GetFullPath(file_name))));
}
catch // migration from UTF-8
var stateData = newClip.GetStateFor(clipState.States.Select(state => state.Module), clipState.States.Select(state => state.Lookup));
if (stateData is null) return;

stateData.Enabled.Value = clipState.Enabled;
stateData.Format.Value = clipState.Format;
});

clip.Events.ForEach(clipEvent =>
{
return JsonConvert.DeserializeObject<SerialisableTimeline>(File.ReadAllText(storage.GetFullPath(file_name)));
}
}
var eventData = newClip.GetEventFor(clipEvent.Module, clipEvent.Lookup);
if (eventData is null) return;

eventData.Enabled.Value = clipEvent.Enabled;
eventData.Format.Value = clipEvent.Format;
eventData.Length.Value = clipEvent.Length;
});

chatBoxManager.Clips.Add(newClip);
});
}
}
1 change: 1 addition & 0 deletions VRCOSC.Game/Graphics/About/AboutScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private void load()
});

versionBindable = configManager.GetBindable<string>(VRCOSCSetting.Version);

versionBindable.BindValueChanged(version =>
{
text.Clear();
Expand Down
2 changes: 1 addition & 1 deletion VRCOSC.Game/Graphics/ChatBox/Metadata/MetadataString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using VRCOSC.Game.ChatBox;
using VRCOSC.Game.Graphics.Themes;
using VRCOSC.Game.Graphics.UI.Text;
using VRCOSC.Game.Managers;

namespace VRCOSC.Game.Graphics.ChatBox.Metadata;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using VRCOSC.Game.ChatBox;
using VRCOSC.Game.Graphics.Themes;
using VRCOSC.Game.Graphics.UI;
using VRCOSC.Game.Managers;

namespace VRCOSC.Game.Graphics.ChatBox.Metadata;

Expand Down
Loading

0 comments on commit 96daec1

Please sign in to comment.