Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main to dev #108

Merged
merged 9 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[*.cs]

# UNT0023: Coalescing assignment on Unity objects
dotnet_diagnostic.UNT0023.severity = error

# UNT0022: Inefficient position/rotation assignment
dotnet_diagnostic.UNT0022.severity = error

# UNT0007: Null coalescing on Unity objects
dotnet_diagnostic.UNT0007.severity = error

# UNT0008: Null propagation on Unity objects
dotnet_diagnostic.UNT0008.severity = error
9 changes: 7 additions & 2 deletions SaberFactory.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
# Visual Studio Version 17
VisualStudioVersion = 17.1.31911.260
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaberFactory", "SaberFactory\SaberFactory.csproj", "{C287398D-B333-4DFE-9C7E-9518D9D09745}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SaberFactory.Unity", "SaberFactory.Unity\SaberFactory.Unity.csproj", "{42D12C91-86D3-4006-8D15-0291488970B6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2B173B38-BE01-4606-9F77-D09B360CBC69}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
1 change: 1 addition & 0 deletions SaberFactory/DataStore/MainAssetStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using SaberFactory.Loaders;
using SaberFactory.Models;
using SaberFactory.Models.CustomSaber;
using SiraUtil.Logging;
using SiraUtil.Tools;

namespace SaberFactory.DataStore
Expand Down
13 changes: 12 additions & 1 deletion SaberFactory/DataStore/TextureAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ namespace SaberFactory.DataStore
{
internal class TextureAsset : IDisposable
{
public Sprite Sprite => _cachedSprite ??= CreateSprite();
public Sprite Sprite
{
get
{
if (_cachedSprite == null)
{
_cachedSprite = CreateSprite();
}
return _cachedSprite;
}
}

public bool IsInUse;
public string Name;
public EAssetOrigin Origin;
Expand Down
9 changes: 9 additions & 0 deletions SaberFactory/Editor/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using SaberFactory.Models;
using SaberFactory.UI;
using SaberFactory.UI.Lib;
using SiraUtil.Logging;
using SiraUtil.Tools;
using UnityEngine;
using Zenject;
Expand Down Expand Up @@ -92,6 +93,7 @@ public async void Initialize()
// Create Pedestal
var pos = new Vector3(0.3f, 0, 0.9f);
await _pedestal.Instantiate(pos, Quaternion.Euler(0, 25, 0));
SetupGlobalShaderVars();
}

public async void Open()
Expand Down Expand Up @@ -183,5 +185,12 @@ private async void OnModelCompositionSet(ModelComposition composition)
await AnimationHelper.AsyncAnimation(0.3f, CancellationToken.None, t => { parent.localScale = new Vector3(t, t, t); });
}
}

private void SetupGlobalShaderVars()
{
var scheme = _playerDataModel.playerData.colorSchemesSettings.GetSelectedColorScheme();
Shader.SetGlobalColor(MaterialProperties.UserColorLeft, scheme.saberAColor);
Shader.SetGlobalColor(MaterialProperties.UserColorRight, scheme.saberBColor);
}
}
}
1 change: 1 addition & 0 deletions SaberFactory/Editor/EditorInstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SaberFactory.Instances;
using SaberFactory.Models;
using SaberFactory.Serialization;
using SiraUtil.Logging;
using SiraUtil.Tools;
using UnityEngine;

Expand Down
4 changes: 2 additions & 2 deletions SaberFactory/Editor/Pedestal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public async Task Instantiate(Vector3 pos, Quaternion rot)
SaberContainerTransform.localPosition += new Vector3(0, 1, 0);
SaberContainerTransform.localEulerAngles = new Vector3(-90, 0, 0);

_rootTransform.position = pos;
_rootTransform.rotation = rot;
_rootTransform.SetPositionAndRotation(pos, rot);


IsVisible = false;
}
Expand Down
12 changes: 10 additions & 2 deletions SaberFactory/Editor/SaberGrabController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public void ShowHandle()
}

_isHandleVisisble = true;
_menuPlayerController.leftController?.transform.Find("MenuHandle")?.gameObject.SetActive(_isHandleVisisble);

if (_menuPlayerController.leftController != null && _menuPlayerController.leftController.transform.Find("MenuHandle") is { } handle)
{
handle.gameObject.SetActive(_isHandleVisisble);
}
}

public void HideHandle()
Expand All @@ -44,7 +48,11 @@ public void HideHandle()
}

_isHandleVisisble = false;
_menuPlayerController.leftController?.transform.Find("MenuHandle")?.gameObject.SetActive(_isHandleVisisble);

if (_menuPlayerController != null && _menuPlayerController.leftController.transform.Find("MenuHandle") is { } handle)
{
handle.gameObject.SetActive(_isHandleVisisble);
}
}
}
}
1 change: 1 addition & 0 deletions SaberFactory/EmbeddedAssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using SaberFactory.Helpers;
using SiraUtil.Logging;
using SiraUtil.Tools;
using UnityEngine;
using Object = UnityEngine.Object;
Expand Down
7 changes: 6 additions & 1 deletion SaberFactory/Game/AFHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public async Task InitPosition(Transform transform, float xPos)

private async Task<GameObject> GetThruster()
{
return _thruster ??= await _assetLoader.LoadAsset<GameObject>("Thruster");
if (_thruster == null)
{
_thruster = await _assetLoader.LoadAsset<GameObject>("Thruster");
}

return _thruster;
}
}
}
10 changes: 9 additions & 1 deletion SaberFactory/Game/EventPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using IPA.Utilities;
using ModestTree;
using SaberFactory.Configuration;
using SaberFactory.Models;
using UnityEngine;
Expand All @@ -18,11 +19,14 @@ internal class EventPlayer : IDisposable

[Inject] private readonly GameEnergyCounter _energyCounter = null;

[Inject] private readonly ObstacleSaberSparkleEffectManager _obstacleSaberSparkleEffectManager = null;
[InjectOptional] private ObstacleSaberSparkleEffectManager _obstacleSaberSparkleEffectManager;

[Inject] private readonly PluginConfig _pluginConfig = null;

[Inject] private readonly ScoreController _scoreController = null;

[Inject] private readonly MonoKernel _monoKernel = null;

private bool _didInit;

[Inject(Id = "LastNoteId")] private float _lastNoteTime;
Expand Down Expand Up @@ -64,6 +68,10 @@ public void SetPartEventList(List<PartEvents> partEventsList, SaberType saberTyp
_beatmapObjectManager.noteWasMissedEvent += OnNoteMiss;

// Sabers clashing
if (_obstacleSaberSparkleEffectManager == null)
{
_obstacleSaberSparkleEffectManager = _monoKernel.GetComponentInChildren<ObstacleSaberSparkleEffectManager>();
}
_obstacleSaberSparkleEffectManager.sparkleEffectDidStartEvent += SaberStartCollide;
_obstacleSaberSparkleEffectManager.sparkleEffectDidEndEvent += SaberEndCollide;

Expand Down
7 changes: 6 additions & 1 deletion SaberFactory/Game/SFSaberModelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SaberFactory.Instances;
using SaberFactory.Models;
using SiraUtil.Interfaces;
using SiraUtil.Logging;
using SiraUtil.Tools;
using UnityEngine;
using Zenject;
Expand All @@ -27,7 +28,11 @@ public void SetColor(Color color)
_saberInstance.SetColor(color);
}

public Color Color => _saberColor.GetValueOrDefault();
public Color Color
{
get => _saberColor.GetValueOrDefault();
set => SetColor(value);
}

public override async void Init(Transform parent, Saber saber)
{
Expand Down
10 changes: 5 additions & 5 deletions SaberFactory/Game/SFSaberProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace SaberFactory.Game
{
public class SFSaberProvider : IModelProvider
{
public Type Type => typeof(SfSaberModelController);
public int Priority => 300;
}
//public class SFSaberProvider : IModelProvider
//{
// public Type Type => typeof(SfSaberModelController);
// public int Priority => 300;
//}
}
6 changes: 3 additions & 3 deletions SaberFactory/Game/SaberMovementTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ internal class SaberMovementTester : IInitializable
{
private readonly AudioTimeSyncController _audioController;
private readonly InitData _initData;
private readonly SiraSaber.Factory _saberFactory;
private readonly SiraSaberFactory _saberFactory;

private Transform _movementContainer;
private SiraSaber _saber;

private SaberMovementTester(InitData initData, SiraSaber.Factory saberFactory, AudioTimeSyncController audioController)
private SaberMovementTester(InitData initData, SiraSaberFactory saberFactory, AudioTimeSyncController audioController)
{
_initData = initData;
_saberFactory = saberFactory;
Expand All @@ -35,7 +35,7 @@ public async void Initialize()

_movementContainer = new GameObject("SaberTester").transform;
_movementContainer.localPosition = new Vector3(0, 1.5f, 0);
_saber = _saberFactory.Create();
_saber = _saberFactory.Spawn(SaberType.SaberA);
_saber.transform.SetParent(_movementContainer, false);

SharedCoroutineStarter.instance.StartCoroutine(AnimationCoroutine());
Expand Down
1 change: 0 additions & 1 deletion SaberFactory/Helpers/DebugMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class DebugMenu : MonoBehaviour

private void Start()
{
Debug.LogWarning("Hello");
}

private void OnGUI()
Expand Down
1 change: 1 addition & 0 deletions SaberFactory/Helpers/DebugTimer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using SiraUtil.Logging;
using SiraUtil.Tools;
using Debug = UnityEngine.Debug;

Expand Down
3 changes: 3 additions & 0 deletions SaberFactory/Helpers/MaterialProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ internal static class MaterialProperties
public static readonly int CustomColors = Shader.PropertyToID("_CustomColors");
public static readonly int Glow = Shader.PropertyToID("_Glow");
public static readonly int Bloom = Shader.PropertyToID("_Bloom");

public static readonly int UserColorLeft = Shader.PropertyToID("_UserColorLeft");
public static readonly int UserColorRight = Shader.PropertyToID("_UserColorRight");
}
}
2 changes: 1 addition & 1 deletion SaberFactory/Helpers/ShaderPropertyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public override void FromJson(JToken token, Material mat, params object[] args)
public override JToken ToJson(Material mat)
{
var tex = (Texture)GetValue(mat);
return JToken.FromObject(tex?.name??"");
return JToken.FromObject(tex != null ? tex.name : "");
}
}

Expand Down
2 changes: 1 addition & 1 deletion SaberFactory/Installers/PluginAppInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override void InstallBindings()
Container.Bind<PluginDirectories>().AsSingle();

Container.BindInstance(_metadata).WithId(nameof(SaberFactory)).AsCached();
Container.BindLoggerAsSiraLogger(_logger);
//Container.BindLoggerAsSiraLogger(_logger);
Container.BindInstance(_config).AsSingle();
Container.Bind<PluginManager>().AsSingle();

Expand Down
4 changes: 3 additions & 1 deletion SaberFactory/Installers/PluginGameInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SaberFactory.Helpers;
using SaberFactory.Models;
using SiraUtil.Interfaces;
using SiraUtil.Sabers;
using Zenject;

namespace SaberFactory.Installers
Expand All @@ -32,7 +33,8 @@ public override void InstallBindings()

//Container.BindInterfacesAndSelfTo<AFHandler>().AsSingle();
Container.BindInterfacesAndSelfTo<GameSaberSetup>().AsSingle();
Container.Bind<IModelProvider>().To<SFSaberProvider>().AsSingle();
//Container.Bind<IModelProvider>().To<SFSaberProvider>().AsSingle();
Container.BindInstance(SaberModelRegistration.Create<SfSaberModelController>());


#if DEBUG && TEST_TRAIL
Expand Down
1 change: 1 addition & 0 deletions SaberFactory/Instances/CustomSaber/CustomSaberInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using SaberFactory.Instances.Trail;
using SaberFactory.Models;
using SaberFactory.Models.CustomSaber;
using SiraUtil.Logging;
using SiraUtil.Tools;
using UnityEngine;

Expand Down
1 change: 1 addition & 0 deletions SaberFactory/Instances/InstanceFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using SaberFactory.Models;
using SiraUtil.Logging;
using SiraUtil.Tools;
using Zenject;

Expand Down
1 change: 1 addition & 0 deletions SaberFactory/Instances/SaberInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SaberFactory.Instances.PostProcessors;
using SaberFactory.Instances.Trail;
using SaberFactory.Models;
using SiraUtil.Logging;
using SiraUtil.Tools;
using UnityEngine;
using Zenject;
Expand Down
7 changes: 6 additions & 1 deletion SaberFactory/Instances/Trail/SFTrail.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using SaberFactory.Helpers;
using TMPro;
using UnityEngine;

namespace SaberFactory.Instances.Trail
Expand Down Expand Up @@ -115,7 +116,11 @@ public override float GetTrailWidth(BladeMovementDataElement lastAddedData)
public void SetMaterial(Material newMaterial)
{
_customMaterial = newMaterial;
_trailRenderer?.Cast<SFTrailRenderer>().SetMaterial(_customMaterial);

if (_trailRenderer != null)
{
_trailRenderer.Cast<SFTrailRenderer>().SetMaterial(_customMaterial);
}
}
}
}
5 changes: 2 additions & 3 deletions SaberFactory/Misc/VertexPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class VertexPool
{
public const int BlockSize = 108;

public Mesh MyMesh => _meshFilter?.sharedMesh;
public Mesh MyMesh => _meshFilter != null ? _meshFilter.sharedMesh : null;

public float BoundsScheduleTime = 1f;
public bool ColorChanged;
Expand Down Expand Up @@ -73,8 +73,7 @@ private void CreateMeshObj(AltTrail owner, Material material)
_meshFilter = _gameObject.AddComponent<MeshFilter>();
var meshrenderer = _gameObject.AddComponent<MeshRenderer>();

_gameObject.transform.position = Vector3.zero;
_gameObject.transform.rotation = Quaternion.identity;
_gameObject.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);

meshrenderer.shadowCastingMode = ShadowCastingMode.Off;
meshrenderer.receiveShadows = false;
Expand Down
Loading