Skip to content

Commit

Permalink
Merge pull request #122 from ToniMacaroni/development
Browse files Browse the repository at this point in the history
2.5.0
  • Loading branch information
ToniMacaroni authored Jan 28, 2022
2 parents e887cd7 + 47ee155 commit e1f8604
Show file tree
Hide file tree
Showing 60 changed files with 1,093 additions and 115 deletions.
19 changes: 16 additions & 3 deletions SaberFactory.Unity/SaberFactory.Unity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY</DefineConstants>
<DefineConstants>DEBUG;TRACE;UNITY;UNITY_EDITOR</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DefineConstants>TRACE;UNITY</DefineConstants>
<DefineConstants>TRACE;UNITY;UNITY_EDITOR</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(DefineConstants.Contains('CIBuild')) OR '$(NCrunch)' == '1'">
<DisableCopyToPlugins>True</DisableCopyToPlugins>
Expand All @@ -47,6 +47,9 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.AudioModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.AudioModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
Expand All @@ -56,7 +59,7 @@
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.JSONSerializeModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.JSONSerializeModule.dll</HintPath>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.JSONSerializeModule.dll</HintPath>
</Reference>
</ItemGroup>

Expand All @@ -77,12 +80,22 @@
<Compile Include="..\SaberFactory\ProjectComponents\SaberModifierCollection.cs">
<Link>SaberModifierCollection.cs</Link>
</Compile>
<Compile Include="..\SaberFactory\ProjectComponents\SFSaberSound.cs" Link="SFSaberSound.cs" />
<Compile Include="..\SaberFactory\ProjectComponents\TransformModifier.cs">
<Link>TransformModifier.cs</Link>
</Compile>
<Compile Include="..\SaberFactory\ProjectComponents\VisibilityModifier.cs">
<Link>VisibilityModifier.cs</Link>
</Compile>
<Compile Include="..\SaberFactory\ProjectComponents\SFBurnmarks.cs">
<Link>SFBurnMarks.cs</Link>
</Compile>
<Compile Include="..\SaberFactory\ProjectComponents\SFClashEffect.cs">
<Link>SFClashEffect.cs</Link>
</Compile>
<Compile Include="..\SaberFactory\ProjectComponents\HelpAttribute.cs">
<Link>HelpAttribute.cs</Link>
</Compile>
</ItemGroup>

</Project>
16 changes: 15 additions & 1 deletion SaberFactory/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using IPA.Config.Stores;
using IPA.Config.Stores.Attributes;
using IPA.Config.Stores.Converters;
using JetBrains.Annotations;

[assembly: InternalsVisibleTo(GeneratedStore.AssemblyVisibilityTarget)]

namespace SaberFactory.Configuration
{
internal class PluginConfig
internal class PluginConfig : INotifyPropertyChanged
{
public bool Enabled { get; set; } = true;

Expand Down Expand Up @@ -49,6 +51,10 @@ internal class PluginConfig

public bool ReloadOnSaberUpdate { get; set; } = false;

public float SwingSoundVolume { get; set; } = 1;

public bool EnableCustomBurnmarks { get; set; } = true;

// How many threads to spawn when loading all sabers
// ! Not used as of right now !
[Ignore] public int LoadingThreads { get; set; } = 2;
Expand Down Expand Up @@ -94,5 +100,13 @@ public bool IsFavorite(string path)
{
return Favorites.Contains(path);
}

public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
6 changes: 3 additions & 3 deletions SaberFactory/DataStore/MainAssetStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace SaberFactory.DataStore
/// <summary>
/// Class for managing store assets ie. parts and custom sabers
/// </summary>
internal class MainAssetStore : IDisposable, ILoadingTask
public class MainAssetStore : IDisposable, ILoadingTask
{
public List<string> AdditionalCustomSaberFolders { get; } = new List<string>();

Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task<ModelComposition> GetCompositionByMeta(PreloadMetaData meta)
return await this[PathTools.ToRelativePath(meta.AssetMetaPath.Path)];
}

public async Task LoadAllMetaAsync(EAssetTypeConfiguration assetType)
internal async Task LoadAllMetaAsync(EAssetTypeConfiguration assetType)
{
await LoadAllCustomSaberMetaDataAsync();
}
Expand Down Expand Up @@ -210,7 +210,7 @@ private async Task LoadAllMetaDataForLoader(AssetBundleLoader loader, bool creat
sw.Print(_logger);
}

public async Task<ModelComposition> CreateMetaData(AssetMetaPath assetMetaPath)
internal async Task<ModelComposition> CreateMetaData(AssetMetaPath assetMetaPath)
{
var relativePath = assetMetaPath.RelativePath+".meta";
if (_metaData.TryGetValue(relativePath, out _))
Expand Down
2 changes: 1 addition & 1 deletion SaberFactory/DataStore/StoreAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SaberFactory.DataStore
/// <summary>
/// Keeps information about the origin of the asset
/// </summary>
internal class StoreAsset
public class StoreAsset
{
public readonly AssetBundle AssetBundle;
public readonly string Extension;
Expand Down
3 changes: 2 additions & 1 deletion SaberFactory/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
<Copy SourceFiles="$(OutputAssemblyName).dll" DestinationFiles="$(ArtifactDestination)\Plugins\$(AssemblyName).dll"/>
<Message Text="PluginVersion: $(PluginVersion), AssemblyVersion: $(AssemblyVersion), GameVersion: $(GameVersion)" Importance="high"/>
<Delete Files="@(OldZips)" TreatErrorsAsWarnings="true" ContinueOnError="true"/>
<ZipDir SourceDirectory="$(ArtifactDestination)" DestinationFile="$(DestinationDirectory)$(ArtifactName).zip"/>
<ZipDir Condition="!$(DefineConstants.Contains(PAT))" SourceDirectory="$(ArtifactDestination)" DestinationFile="$(DestinationDirectory)$(ArtifactName).zip"/>
<ZipDir Condition="$(DefineConstants.Contains(PAT))" SourceDirectory="$(ArtifactDestination)" DestinationFile="$(DestinationDirectory)$(ArtifactName)_Patreon.zip"/>
</Target>
<!--Copies the assembly and pdb to the Beat Saber folder.-->
<Target Name="CopyToPlugins" AfterTargets="Build" Condition="'$(DisableCopyToPlugins)' != 'True' AND '$(ContinuousIntegrationBuild)' != 'True'">
Expand Down
30 changes: 28 additions & 2 deletions SaberFactory/Editor/Editor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using IPA.Loader;
using SaberFactory.Configuration;
using SaberFactory.HarmonyPatches;
using SaberFactory.Helpers;
Expand All @@ -10,6 +11,7 @@
using SaberFactory.UI.Lib;
using SiraUtil.Logging;
using SiraUtil.Tools;
using Tweening;
using UnityEngine;
using Zenject;

Expand Down Expand Up @@ -49,6 +51,8 @@ public bool IsSaberInHand
private bool _isFirstActivation = true;
private bool _isSaberInHand;
private SaberInstance _spawnedSaber;
private readonly PluginMetadata _metaData;
private readonly TimeTweeningManager _tweeningManager;

private Editor(
SiraLog logger,
Expand All @@ -60,9 +64,13 @@ private Editor(
PlayerDataModel playerDataModel,
SaberGrabController saberGrabController,
MenuSaberProvider menuSaberProvider,
PluginDirectories pluginDirs)
PluginDirectories pluginDirs,
[Inject(Id = nameof(SaberFactory))]PluginMetadata metadata,
TimeTweeningManager tweeningManager)
{
_logger = logger;
_metaData = metadata;
_tweeningManager = tweeningManager;
_pluginConfig = pluginConfig;
_baseUiComposition = baseUiComposition;
_editorInstanceManager = editorInstanceManager;
Expand All @@ -71,7 +79,7 @@ private Editor(
_saberGrabController = saberGrabController;
_menuSaberProvider = menuSaberProvider;

_pedestal = new Pedestal(embeddedAssetLoader, pluginDirs.SaberFactoryDir.GetFile("pedestal"));
_pedestal = new Pedestal(pluginDirs.SaberFactoryDir.GetFile("pedestal"));
_sfLogoAnim = new SFLogoAnim(embeddedAssetLoader);

Instance = this;
Expand All @@ -93,6 +101,10 @@ public async void Initialize()
// Create Pedestal
var pos = new Vector3(0.3f, 0, 0.9f);
await _pedestal.Instantiate(pos, Quaternion.Euler(0, 25, 0));
SetPedestalText(1, "<color=#ffffff70>SF v"+_metaData.HVersion+"</color>");
#if PAT
SetPedestalText(2, "<color=#ffffff80>Patreon ♥</color>");
#endif
SetupGlobalShaderVars();
}

Expand Down Expand Up @@ -155,6 +167,20 @@ public void Close(bool instant)
_menuSaberProvider.RequestSaberVisiblity(true);
}

public void SetPedestalText(int line, string text)
{
_pedestal.SetText(line, text);
}

public void FlashPedestal(Color color)
{
_tweeningManager.KillAllTweens(_pedestal.SaberContainerTransform);
_tweeningManager.AddTween(new FloatTween(1, 0, f =>
{
_pedestal.SetLedColor(color.ColorWithAlpha(f));
}, 1, EaseType.InCubic), _pedestal.SaberContainerTransform);
}

private async void OnModelCompositionSet(ModelComposition composition)
{
_spawnedSaber?.Destroy();
Expand Down
56 changes: 50 additions & 6 deletions SaberFactory/Editor/Pedestal.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using SaberFactory.Helpers;
using SaberFactory.Loaders;
using TMPro;
using UnityEngine;
using Object = UnityEngine.Object;

namespace SaberFactory.Editor
{
internal class Pedestal
{
private static readonly string PedestalPath = String.Join(".", nameof(SaberFactory), "Resources", "pedestal");

public bool IsVisible
{
set
Expand All @@ -29,13 +34,15 @@ public Vector3 Position
public Transform SaberContainerTransform { get; private set; }
private readonly FileInfo _customPedestalFile;

private readonly EmbeddedAssetLoader _embeddedAssetLoader;

private Transform _rootTransform;
private TextMeshPro _textMeshPro;
private Material _ledMat;

private readonly string[] _lines = new string[3];
private static readonly int LedColor = Shader.PropertyToID("_LedColor");

public Pedestal(EmbeddedAssetLoader embeddedAssetLoader, FileInfo customPedestalFile)
public Pedestal(FileInfo customPedestalFile)
{
_embeddedAssetLoader = embeddedAssetLoader;
_customPedestalFile = customPedestalFile;
}

Expand All @@ -54,7 +61,20 @@ public async Task Instantiate(Vector3 pos, Quaternion rot)
return;
}

Object.Instantiate(prefab, _rootTransform, false);
var instantiated = Object.Instantiate(prefab, _rootTransform, false);
_textMeshPro = instantiated.GetComponentsInChildren<TextMeshPro>()
.FirstOrDefault(x => x.name == "Pedestal_Display");
var leds = instantiated.GetComponentsInChildren<MeshRenderer>().FirstOrDefault(x => x.name == "Leds");

if (_textMeshPro)
{
_textMeshPro.alignment = TextAlignmentOptions.Center;
}

if (leds)
{
_ledMat = leds.sharedMaterial;
}

SaberContainerTransform = _rootTransform.CreateGameObject("SaberContainer").transform;
SaberContainerTransform.localPosition += new Vector3(0, 1, 0);
Expand All @@ -66,6 +86,17 @@ public async Task Instantiate(Vector3 pos, Quaternion rot)
IsVisible = false;
}

public void SetText(int line, string text)
{
if (!_textMeshPro)
{
return;
}

_lines[line] = text;
_textMeshPro.text = string.Join("\n", _lines);
}

private async Task<GameObject> GetPedestalAsset()
{
if (_customPedestalFile.Exists)
Expand All @@ -82,7 +113,10 @@ private async Task<GameObject> GetPedestalAsset()
}
}

return await _embeddedAssetLoader.LoadAsset<GameObject>("Pedestal");
var data = await Readers.ReadResourceAsync(PedestalPath);
var bundle = await Readers.LoadAssetFromAssetBundleAsync<GameObject>(data, "Pedestal");
bundle.Item2.Unload(false);
return bundle.Item1;
}

public void Destroy()
Expand All @@ -92,5 +126,15 @@ public void Destroy()
_rootTransform.gameObject.TryDestroy();
}
}

public void SetLedColor(Color color)
{
if (!_ledMat)
{
return;
}

_ledMat.SetColor(LedColor, color);
}
}
}
24 changes: 13 additions & 11 deletions SaberFactory/Game/SFSaberModelController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using HarmonyLib;
using SaberFactory.Helpers;
using SaberFactory.Instances;
using SaberFactory.Misc;
using SaberFactory.Models;
using SiraUtil.Interfaces;
using SiraUtil.Logging;
Expand All @@ -12,12 +16,12 @@ namespace SaberFactory.Game
{
internal class SfSaberModelController : SaberModelController, IColorable
{
[InjectOptional] private readonly AFHandler _afHandler = null;
[InjectOptional] private readonly EventPlayer _eventPlayer = null;
[Inject] private readonly GameSaberSetup _gameSaberSetup = null;
[Inject] private readonly SiraLog _logger = null;
[Inject] private readonly SaberInstance.Factory _saberInstanceFactory = null;
[Inject] private readonly SaberSet _saberSet = null;
[Inject] private readonly List<ICustomizer> _customizers = null;
private Color? _saberColor;

private SaberInstance _saberInstance;
Expand All @@ -43,19 +47,17 @@ public override async void Init(Transform parent, Saber saber)
var saberModel = saber.saberType == SaberType.SaberA ? _saberSet.LeftSaber : _saberSet.RightSaber;

_saberInstance = _saberInstanceFactory.Create(saberModel);

if (saber.saberType == SaberType.SaberA)
{
_customizers.Do(x=>x.SetSaber(_saberInstance));
}

_saberInstance.SetParent(transform);
_saberInstance.CreateTrail(false, _saberTrail);
SetColor(_saberColor ?? _colorManager.ColorForSaberType(_saberInstance.Model.SaberSlot.ToSaberType()));

if (_afHandler != null && AFHandler.IsValid && AFHandler.ShouldFire)
{
await Task.Delay(4000);
await _afHandler.Shoot(this, saber.saberType);
}
else
{
_eventPlayer?.SetPartEventList(_saberInstance.Events, saber.saberType);
}
_eventPlayer?.SetPartEventList(_saberInstance.Events, saber.saberType);

_logger.Info("Instantiated Saber");
}
Expand Down
Loading

0 comments on commit e1f8604

Please sign in to comment.