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

SiraUtil 3 Migration #2

Merged
merged 7 commits into from
Dec 30, 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
44 changes: 44 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build

on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- 'TakeMeToResults.sln'
- 'TakeMeToResults/**'
- '.github/workflows/master.yml'

jobs:
Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Download SIRA References
uses: ProjectSIRA/download-sira-stripped@1.0.0
with:
manifest: ${{github.workspace}}/TakeMeToResults/manifest.json
sira-server-code: ${{ secrets.SIRA_SERVER_CODE }}
- name: Download Mod Dependencies
uses: Goobwabber/download-beatmods-deps@1.2
with:
manifest: ${{github.workspace}}/TakeMeToResults/manifest.json
- name: Build
id: Build
run: dotnet build --configuration Release
- name: GitStatus
run: git status
- name: Echo Filename
run: echo $BUILDTEXT \($ASSEMBLYNAME\)
env:
BUILDTEXT: Filename=${{ steps.Build.outputs.filename }}
ASSEMBLYNAME: AssemblyName=${{ steps.Build.outputs.assemblyname }}
- name: Upload Artifact
uses: actions/upload-artifact@v1
with:
name: "TakeMeToResults"
path: ${{ steps.Build.outputs.artifactpath }}
42 changes: 42 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: PR Build

on:
pull_request:
branches: [ master ]
paths:
- 'TakeMeToResults/**'
- '.github/workflows/**.yml'

jobs:
Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Download SIRA References
uses: ProjectSIRA/download-sira-stripped@1.0.0
with:
manifest: ${{github.workspace}}/TakeMeToResults/manifest.json
sira-server-code: ${{ secrets.SIRA_SERVER_CODE }}
- name: Download Mod Dependencies
uses: Goobwabber/download-beatmods-deps@1.2
with:
manifest: ${{github.workspace}}/TakeMeToResults/manifest.json
- name: Build
id: Build
run: dotnet build --configuration Release
- name: GitStatus
run: git status
- name: Echo Filename
run: echo $BUILDTEXT \($ASSEMBLYNAME\)
env:
BUILDTEXT: Filename=${{ steps.Build.outputs.filename }}
ASSEMBLYNAME: AssemblyName=${{ steps.Build.outputs.assemblyname }}
- name: Upload Artifact
uses: actions/upload-artifact@v1
with:
name: "TakeMeToResults"
path: ${{ steps.Build.outputs.artifactpath }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A simple mod that adds a button which takes you to the results screen.

## Download
Download the latest version of the mod (v1.0.2) [here](https://github.com/rithik-b/TakeMeToResults/releases/tag/1.0.2 "here").
Download the latest version of the mod (v1.1.0) [here](https://github.com/rithik-b/TakeMeToResults/releases/tag/1.1.0 "here").
To install, move the dll to your Plugins folder.

**BeatSaberMarkupLanguage (BSML)** and **SiraUtil** are required for this mod, so please download the latest version from ModAssistant.
Expand Down
17 changes: 17 additions & 0 deletions TakeMeToResults/AffinityPatches/PresentFlowCoordinatorPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using HMUI;
using SiraUtil.Affinity;
using System;

namespace TakeMeToResults.AffinityPatches
{
internal class PresentFlowCoordinatorPatch : IAffinity
{
public event Action FlowCoordinatorChanged;

[AffinityPatch(typeof(FlowCoordinator), "PresentFlowCoordinator")]
private void PresentFlowCoordinator()
{
FlowCoordinatorChanged?.Invoke();
}
}
}

This file was deleted.

13 changes: 0 additions & 13 deletions TakeMeToResults/Installers/TakeMeToResultsMenuInstaller.cs

This file was deleted.

60 changes: 7 additions & 53 deletions TakeMeToResults/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
using IPA;
using IPA.Config;
using IPA.Config.Stores;
using SiraUtil.Zenject;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using TakeMeToResults.Installers;
using UnityEngine;
using TakeMeToResults.AffinityPatches;
using TakeMeToResults.UI;
using IPALogger = IPA.Logging.Logger;

namespace TakeMeToResults
{
[Plugin(RuntimeOptions.DynamicInit)]
public class Plugin
{
public const string HarmonyId = "com.github.rithik-b.TakeMeToResults";
internal static readonly HarmonyLib.Harmony harmony = new HarmonyLib.Harmony(HarmonyId);

internal static Plugin Instance { get; private set; }
internal static IPALogger Log { get; private set; }

Expand All @@ -33,7 +22,11 @@ public Plugin(IPALogger logger, Zenjector zenjector)
{
Instance = this;
Plugin.Log = logger;
zenjector.OnMenu<TakeMeToResultsMenuInstaller>();
zenjector.Install(Location.Menu, Container =>
{
Container.BindInterfacesTo<ResultsButtonController>().AsSingle();
Container.BindInterfacesAndSelfTo<PresentFlowCoordinatorPatch>().AsSingle();
});
}

#region BSIPA Config
Expand All @@ -57,7 +50,6 @@ public void InitWithConfig(Config conf)
[OnEnable]
public void OnEnable()
{
ApplyHarmonyPatches();
}

/// <summary>
Expand All @@ -68,7 +60,6 @@ public void OnEnable()
[OnDisable]
public void OnDisable()
{
RemoveHarmonyPatches();
}

/*
Expand All @@ -84,42 +75,5 @@ public async Task OnDisableAsync()
}
*/
#endregion

// Uncomment the methods in this section if using Harmony
#region Harmony
/// <summary>
/// Attempts to apply all the Harmony patches in this assembly.
/// </summary>
internal static void ApplyHarmonyPatches()
{
try
{
Plugin.Log?.Debug("Applying Harmony patches.");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
catch (Exception ex)
{
Plugin.Log?.Error("Error applying Harmony patches: " + ex.Message);
Plugin.Log?.Debug(ex);
}
}

/// <summary>
/// Attempts to remove all the Harmony patches that used our HarmonyId.
/// </summary>
internal static void RemoveHarmonyPatches()
{
try
{
// Removes all patches with this HarmonyId
harmony.UnpatchAll(HarmonyId);
}
catch (Exception ex)
{
Plugin.Log?.Error("Error removing Harmony patches: " + ex.Message);
Plugin.Log?.Debug(ex);
}
}
#endregion
}
}
4 changes: 0 additions & 4 deletions TakeMeToResults/TakeMeToResults.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
</PropertyGroup>

<ItemGroup>
<Reference Include="0Harmony">
<HintPath>$(BeatSaberDir)\Libs\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
Expand Down
28 changes: 10 additions & 18 deletions TakeMeToResults/UI/ViewControllers/ResultsButtonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
using System;
using System.ComponentModel;
using System.Reflection;
using TakeMeToResults.HarmonyPatches;
using TakeMeToResults.AffinityPatches;
using UnityEngine;
using Zenject;

namespace TakeMeToResults.UI.ViewControllers
namespace TakeMeToResults.UI
{
internal class ResultsButtonController : IInitializable, IDisposable, INotifyPropertyChanged
{
private readonly TitleViewController titleViewController;
private readonly ResultsViewController resultsViewController;
private readonly MainFlowCoordinator mainFlowCoordinator;
private readonly PresentFlowCoordinatorPatch presentFlowCoordinatorPatch;

private ViewController leftScreenViewController;
private ViewController rightScreenViewController;
Expand All @@ -30,12 +31,14 @@ internal class ResultsButtonController : IInitializable, IDisposable, INotifyPro
[UIComponent("results-button")]
private readonly RectTransform resultsButtonTransform;

public ResultsButtonController(HierarchyManager hierarchyManager, ResultsViewController resultsViewController, MainFlowCoordinator mainFlowCoordinator)
public ResultsButtonController(HierarchyManager hierarchyManager, ResultsViewController resultsViewController, MainFlowCoordinator mainFlowCoordinator,
PresentFlowCoordinatorPatch presentFlowCoordinatorPatch)
{
ScreenSystem screenSystem = hierarchyManager.GetField<ScreenSystem, HierarchyManager>("_screenSystem");
titleViewController = screenSystem.titleViewController;
this.resultsViewController = resultsViewController;
this.mainFlowCoordinator = mainFlowCoordinator;
this.presentFlowCoordinatorPatch = presentFlowCoordinatorPatch;
ShowOther = ShowOtherViewControllers;
}

Expand All @@ -44,18 +47,18 @@ public void Initialize()
BSMLParser.instance.Parse(Utilities.GetResourceContent(Assembly.GetExecutingAssembly(), "TakeMeToResults.UI.Views.ResultsButton.bsml"), titleViewController.gameObject, this);
resultsButtonTransform.gameObject.name = "TakeMeToResults";
resultsViewController.continueButtonPressedEvent += GetViewControllers;
FlowCoordinator_PresentFlowCoordinator.FlowCoordinatorChanged += UpdateFlowAndButtonState;
presentFlowCoordinatorPatch.FlowCoordinatorChanged += UpdateFlowAndButtonState;
}

public void Dispose()
{
resultsViewController.continueButtonPressedEvent -= GetViewControllers;
FlowCoordinator_PresentFlowCoordinator.FlowCoordinatorChanged -= UpdateFlowAndButtonState;
presentFlowCoordinatorPatch.FlowCoordinatorChanged -= UpdateFlowAndButtonState;
}

private void GetViewControllers(ResultsViewController resultsViewController)
{
deepestChildFlowCoordinator = DeepestChildFlowCoordinator(mainFlowCoordinator);
deepestChildFlowCoordinator = mainFlowCoordinator.YoungestChildFlowCoordinatorOrSelf();

leftScreenViewController = deepestChildFlowCoordinator.GetField<ViewController, FlowCoordinator>("_leftScreenViewController");
rightScreenViewController = deepestChildFlowCoordinator.GetField<ViewController, FlowCoordinator>("_rightScreenViewController");
Expand All @@ -68,7 +71,7 @@ private void GetViewControllers(ResultsViewController resultsViewController)

private void UpdateFlowAndButtonState()
{
deepestChildFlowCoordinator = DeepestChildFlowCoordinator(mainFlowCoordinator);
deepestChildFlowCoordinator = mainFlowCoordinator.YoungestChildFlowCoordinatorOrSelf();
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ButtonActive)));
}

Expand Down Expand Up @@ -109,17 +112,6 @@ private void ShowOtherViewControllers()
}
}

private FlowCoordinator DeepestChildFlowCoordinator(FlowCoordinator root)
{
var flow = root.childFlowCoordinator;
if (flow == null) return root;
if (flow.childFlowCoordinator == null || flow.childFlowCoordinator == flow)
{
return flow;
}
return DeepestChildFlowCoordinator(flow);
}

[UIValue("button-active")]
private bool ButtonActive => mainScreenViewController != null && deepestChildFlowCoordinator is SinglePlayerLevelSelectionFlowCoordinator;
}
Expand Down
18 changes: 11 additions & 7 deletions TakeMeToResults/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
{
"$schema": "https://raw.githubusercontent.com/bsmg/BSIPA-MetadataFileSchema/master/Schema.json",
"id": "TakeMeToResults",
"name": "TakeMeToResults",
"author": "PixelBoom",
"version": "1.0.2",
"version": "1.1.0",
"description": "A simple mod that adds a button which takes you to the results screen.",
"gameVersion": "1.16.1",
"gameVersion": "1.19.0",
"dependsOn": {
"BSIPA": "^4.1.6",
"BeatSaberMarkupLanguage": "^1.5.3",
"SiraUtil": "^2.5.5"
}
"BSIPA": "^4.2.1",
"BeatSaberMarkupLanguage": "^1.6.0",
"SiraUtil": "^3.0.0"
},
"links": {
"project-source": "https://github.com/rithik-b/TakeMeToResults",
"donate": "https://ko-fi.com/pixelboom"
}
}