Skip to content

Commit

Permalink
Update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Oct 8, 2024
1 parent 14d216f commit 93e0638
Show file tree
Hide file tree
Showing 24 changed files with 891 additions and 436 deletions.
404 changes: 404 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

52 changes: 17 additions & 35 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,32 @@
name: build
name: Build

on:
push:
branches:
- main
- develop
- actions
tags:
- '*'
pull_request:
paths:
- .github/workflows/build.yml
- SmallMenu/**
- SmallMenu.sln

jobs:
build:
name: SmallMenu
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check out
uses: actions/checkout@v4

- name: Set up .NET Core
uses: actions/setup-dotnet@v1.7.2
- name: Set up Beat Saber
uses: nicoco007/setup-beat-saber@v1
with:
dotnet-version: 3.1.x

- name: Prepare Environment
run: .\prepare_environment.ps1 "Source\SmallMenu\manifest.json"

- name: Fetch Beat Saber Bindings
run: git clone https://nicoco007:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/nicoco007/BeatSaberBindings "BeatSaberBindings\Beat Saber_Data\Managed"

- name: Restore NuGet Packages
run: dotnet restore Source\SmallMenu\SmallMenu.csproj

- name: Build Debug
run: dotnet build --no-restore Source\SmallMenu\SmallMenu.csproj -c Debug -p:BeatSaberDir=..\..\BeatSaberBindings

- name: Upload Debug
uses: actions/upload-artifact@v2.2.0
with:
name: BeatSaberSmallMenu-${{ env.ZIP_VERSION }}-DEBUG
path: Source\SmallMenu\bin\Debug\netstandard2.0\publish
access-token: ${{ secrets.BEAT_SABER_REFERENCE_ASSEMBLIES_TOKEN }}
project-path: ${{ github.workspace }}\SmallMenu\SmallMenu.csproj

- name: Build Release
run: dotnet build --no-restore Source\SmallMenu\SmallMenu.csproj -c Release -p:BeatSaberDir=..\..\BeatSaberBindings
id: build-release
run: dotnet build ${{ github.workspace }}\SmallMenu\SmallMenu.csproj -c Release

- name: Upload Release
uses: actions/upload-artifact@v2.2.0
uses: actions/upload-artifact@v4
with:
name: BeatSaberSmallMenu-${{ env.ZIP_VERSION }}-RELEASE
path: Source\SmallMenu\bin\Release\netstandard2.0\publish
name: ${{ steps.build-release.outputs.artifact-name }}
path: ${{ steps.build-release.outputs.artifact-path }}
38 changes: 37 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore

# User-specific files
*.rsuser
Expand Down Expand Up @@ -90,6 +90,7 @@ StyleCopReport.xml
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
Expand Down Expand Up @@ -293,6 +294,17 @@ node_modules/
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw

# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp

# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp

# Visual Studio 6 technical files
*.ncb
*.aps

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
Expand Down Expand Up @@ -349,6 +361,9 @@ ASALocalRun/
# Local History for Visual Studio
.localhistory/

# Visual Studio History (VSHistory) files
.vshistory/

# BeatPulse healthcheck temp database
healthchecksdb

Expand All @@ -360,3 +375,24 @@ MigrationBackup/

# Fody - auto-generated XML schema
FodyWeavers.xsd

# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp

# JetBrains Rider
*.sln.iml
File renamed without changes.
66 changes: 66 additions & 0 deletions SmallMenu/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<AppendPlatformToOutputPath>False</AppendPlatformToOutputPath>
<BeatSaberOutputType>Plugin</BeatSaberOutputType>
<CopyDocumentationFileToArtifact>True</CopyDocumentationFileToArtifact>
<DebugSymbols>True</DebugSymbols>
<DebugType>portable</DebugType>
<DisableImplicitFrameworkReferences>True</DisableImplicitFrameworkReferences>
<GitTagFormat>v{0}</GitTagFormat>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<ImplicitlyExpandDesignTimeFacades>False</ImplicitlyExpandDesignTimeFacades>
<ImplicitlyExpandNETStandardFacades>False</ImplicitlyExpandNETStandardFacades>
<ImportBSMTTargets>False</ImportBSMTTargets>
<IncludeSourceRevisionInInformationalVersion>False</IncludeSourceRevisionInInformationalVersion>
<LangVersion>12</LangVersion>
<MarkPackageReferencesAsExternallyResolved>False</MarkPackageReferencesAsExternallyResolved>
<NoStdLib>True</NoStdLib>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(CI)' != ''">
<PathMap>$(MSBuildProjectDirectory)\$(IntermediateOutputPath)=$(MSBuildProjectName)</PathMap>
</PropertyGroup>

<ItemGroup>
<Reference Include="IPA.Loader">
<HintPath>$(BeatSaberDir)Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
<Private>False</Private>
</Reference>

<!-- Based on the DLLs included by default with .NET Framework 4.5+ -->
<Reference Include="mscorlib" />
<Reference Include="netstandard" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>

<ItemGroup>
<None Include="$(ProjectName).csproj.user" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BeatSaberModdingTools.Tasks" Version="2.0.0-beta7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.10.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Unity.Analyzers" Version="1.19.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
92 changes: 92 additions & 0 deletions SmallMenu/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<Project>
<PropertyGroup>
<!-- Normalize BeatSaberDir -->
<BeatSaberDir Condition="'$(BeatSaberDir)' != '' AND !($(BeatSaberDir.EndsWith('/')) OR $(BeatSaberDir.EndsWith('\')))">$(BeatSaberDir)\</BeatSaberDir>

<ManifestPath>$(IntermediateOutputPath)manifest.json</ManifestPath>
<ManifestPath Condition="'$(BeatSaberOutputType)' == 'Library'">$(TargetDir)$(TargetName).manifest</ManifestPath>

<!-- Set version to compare against tag (if applicable) -->
<GitTagVersion>$([System.String]::Format('$(GitTagFormat)', '$(Version)'))</GitTagVersion>

<!-- Set SemVer build metadata -->
<BuildMetadata Condition="'$(GITHUB_SHA)' == ''">dev</BuildMetadata>
<BuildMetadata Condition="'$(GITHUB_SHA)' != ''">bs.$(GameVersion)</BuildMetadata>
<BuildMetadata Condition="'$(GITHUB_SHA)' != '' AND '$(GITHUB_REF_TYPE)' != 'tag'">$(BuildMetadata).git.sha.$(GITHUB_SHA)</BuildMetadata>
<Version Condition="$(BuildMetadata) != ''">$(Version)+$(BuildMetadata)</Version>

<ArtifactDir>$(TargetDir)Artifact\</ArtifactDir>
<ArtifactTargetDir>$(ArtifactDir)Plugins\</ArtifactTargetDir>
<ArtifactTargetDir Condition="'$(BeatSaberOutputType)' == 'Library'">$(ArtifactDir)Libs\</ArtifactTargetDir>
</PropertyGroup>

<!-- If we're building for a tag in CI, make sure it matches the version defined here -->
<Target Name="ValidateTag" BeforeTargets="BeforeBuild">
<Error Condition="'$(GITHUB_REF_TYPE)' == 'tag' AND '$(GITHUB_REF_NAME)' != '$(GitTagVersion)'" Text="Tag '$(GITHUB_REF_NAME)' does not match version '$(GitTagVersion)'" />
</Target>

<!-- Default targets set TargetFrameworkDirectory to .NET Framework reference assemblies no matter what so we have to manually force it -->
<Target Name="OverrideTargetFrameworkDirectory" AfterTargets="GetReferenceAssemblyPaths">
<PropertyGroup>
<TargetFrameworkDirectory>$(BeatSaberDir)Beat Saber_Data\Managed\</TargetFrameworkDirectory>
</PropertyGroup>
</Target>

<Target Name="GenerateManifest" BeforeTargets="BeforeBuild">
<GenerateManifest ID="$(PackageId)" Name="$(Title)" Author="$(Authors)" Version="$(Version)" GameVersion="$(GameVersion)"
Description="$(Description)" Icon="$(PluginIcon)" DependsOn="@(DependsOn)" ConflictsWith="@(ConflictsWith)"
Files="@(RequiredFile)" LoadBefore="@(LoadBefore)" LoadAfter="@(LoadAfter)"
ProjectSource="$(RepositoryUrl)" ProjectHome="$(ProjectHome)" Donate="$(DonateUrl)"
Features="$(PluginFeatures)" Misc="$(PluginMisc)" PluginHint="$(PluginHint)"
TargetPath="$(ManifestPath)" />

<ItemGroup Condition="'$(BeatSaberOutputType)' != 'Library'">
<EmbeddedResource Include="$(IntermediateOutputPath)manifest.json" LogicalName="$(AssemblyName).manifest.json" />
</ItemGroup>
</Target>

<!-- Copy the assembly and PDB to the Artifact folder -->
<Target Name="CopyToArtifact" AfterTargets="AfterBuild">
<Message Text="$(MSBuildProjectName) -&gt; $(ArtifactDir)" Importance="high" />

<MakeDir Directories="$(ArtifactDir)" />
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(ArtifactTargetDir)" />
<Copy SourceFiles="$(TargetDir)$(TargetName).pdb" DestinationFolder="$(ArtifactTargetDir)" Condition="Exists('$(TargetDir)$(TargetName).pdb')" />
<Copy SourceFiles="$(TargetDir)$(TargetName).xml" DestinationFolder="$(ArtifactTargetDir)" Condition="Exists('$(TargetDir)$(TargetName).xml') AND '$(CopyDocumentationFileToArtifact)' == 'True'" />
<Copy SourceFiles="$(TargetDir)$(TargetName).manifest" DestinationFolder="$(ArtifactDir)Plugins" Condition="Exists('$(TargetDir)$(TargetName).manifest')" />

<Copy SourceFiles="@(AdditionalArtifactFiles)" DestinationFolder="$(ArtifactDir)%(AdditionalArtifactFiles.TargetDir)\%(AdditionalArtifactFiles.RecursiveDir)" />
</Target>

<!-- Copy the assembly and PDB to the Beat Saber folder -->
<Target Name="CopyToPlugins" AfterTargets="CopyToArtifact" Condition="'$(BeatSaberDir)' != '' AND '$(CI)' == '' AND '$(NCrunch)' != '1'">
<Message Text="$(MSBuildProjectName) -&gt; $(BeatSaberDir)" Importance="high" />

<ItemGroup>
<FilesToCopy Include="$(ArtifactDir)\**\*" />
</ItemGroup>

<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="$(BeatSaberDir)%(RecursiveDir)" />
</Target>

<!-- Set GitHub Actions output variables -->
<Target Name="SetGitHubActionsOutput" AfterTargets="CopyToArtifact" Condition="'$(GITHUB_ACTIONS)' == 'true'">
<Message Text="Writing to GitHub output" Importance="high" />

<PropertyGroup>
<ArtifactName>$(PackageId)-v$(Version)</ArtifactName>
</PropertyGroup>

<ItemGroup>
<LinesToWrite Include="artifact-name=$(ArtifactName)" />
<LinesToWrite Include="artifact-path=$(ArtifactDir)" />
</ItemGroup>

<WriteLinesToFile File="$(GITHUB_OUTPUT)" Lines="@(LinesToWrite)" />
</Target>

<!-- Clean up artifact files -->
<Target Name="CleanArtifact" AfterTargets="Clean">
<RemoveDir Directories="$(ArtifactDir)" />
</Target>
</Project>
10 changes: 10 additions & 0 deletions SmallMenu/MenuScale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SmallMenu;

internal enum MenuScale
{
Default,
Big,
Small,
Tiny,
Custom
}
77 changes: 77 additions & 0 deletions SmallMenu/MenuScaleController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using HMUI;
using System;
using System.ComponentModel;
using UnityEngine;
using Zenject;
using Logger = IPA.Logging.Logger;

namespace SmallMenu;

internal class MenuScaleController : IInitializable, IDisposable
{
private Logger _logger;
private Settings _settings;
private HierarchyManager _hierarchyManager;
private ScreenModeController _screenModeController;

private Transform _bottomScreen;

[Inject]
public void Construct(Logger logger, Settings settings, HierarchyManager hierarchyManager, ScreenModeController screenModeController)
{
_logger = logger;
_settings = settings;
_hierarchyManager = hierarchyManager;
_screenModeController = screenModeController;
}

public void Initialize()
{
_bottomScreen = _hierarchyManager.transform.Find("BottomScreen");

if (!_bottomScreen)
{
_logger.Error("BottomScreen transform not found!");
return;
}

_settings.PropertyChanged += OnSettingsPropertyChanged;

UpdateScale();
}

public void Dispose()
{
_settings.PropertyChanged -= OnSettingsPropertyChanged;
}

private void OnSettingsPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Settings.scale))
{
UpdateScale();
}
}

private void UpdateScale()
{
if (_settings.scale <= 0) return;

ScreenModeData screenModeData = _screenModeController._defaultModeData;

// menu screen (scale 1.0) was originally at y = 1.35 and at scale 1.5 it is at y = 0.85
// therefore, at scale 1.0, the screen system must be moved up by y += 0.5
float offset = Mathf.Max(0, 1.5f - 1f * _settings.scale);

screenModeData.position.y = offset;
screenModeData.scale = _settings.scale;

_screenModeController.SetDefaultMode();

if (!_bottomScreen) return;

Vector3 bottomScreenPosition = _bottomScreen.position;
bottomScreenPosition.y = 0.02f;
_bottomScreen.position = bottomScreenPosition;
}
}
Loading

0 comments on commit 93e0638

Please sign in to comment.