Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
XtraCube committed Sep 1, 2024
2 parents 56c2d9c + 5ec9181 commit 0aa164d
Show file tree
Hide file tree
Showing 66 changed files with 1,869 additions and 1,014 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ jobs:
files: MiraAPI/bin/Release/net6.0/MiraAPI.dll

- name: Push NuGet package
if: github.repository == 'All-Of-Us-Mods/MiraAPI' && github.ref == 'refs/heads/master' && github.ref_type == 'tag'
if: github.repository == 'All-Of-Us-Mods/MiraAPI' && github.ref == 'refs/heads/master'
run: |
dotnet nuget push {MiraAPI/bin/Release/AllOfUs.MiraAPI.*.nupkg} --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
7 changes: 6 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>

<VersionPrefix>0.1.3</VersionPrefix>
<VersionPrefix>0.1.4</VersionPrefix>
<VersionSuffix>dev</VersionSuffix>

<Authors>All Of Us, XtraCube, Angxl</Authors>
Expand All @@ -33,6 +33,11 @@
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="all" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)\stylecop.json" Link="stylecop.json" Visible="false" />

<PackageReference Include="SonarAnalyzer.CSharp" Version="9.32.0.97167">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)\stylecop.ruleset</CodeAnalysisRuleSet>
Expand Down
11 changes: 5 additions & 6 deletions MiraAPI.Example/Buttons/Freezer/FreezeButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@ protected override void OnClick()
Target?.RpcAddModifier<FreezeModifier>();
}

public override PlayerControl GetTarget()
public override PlayerControl? GetTarget()
{
return PlayerControl.LocalPlayer.Data.Role.FindClosestTarget();
return PlayerControl.LocalPlayer.GetClosestPlayer(true, Distance, false);
}

public override void SetOutline(bool active)
{
Target?.cosmetics.SetOutline(active, new Il2CppSystem.Nullable<Color>(Palette.Blue));
}

public override bool IsTargetValid(PlayerControl target)
public override bool IsTargetValid(PlayerControl? target)
{
return true;
}

public override bool Enabled(RoleBehaviour role)
public override bool Enabled(RoleBehaviour? role)
{
return role is FreezerRole;
}

}
}
7 changes: 4 additions & 3 deletions MiraAPI.Example/Buttons/MeetingButton.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using MiraAPI.Example;
using MiraAPI.Example.Modifiers;
using MiraAPI.Example.Modifiers;
using MiraAPI.Hud;
using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
using UnityEngine;

namespace MiraAPI.Example.Buttons;

[RegisterButton]
public class MeetingButton : CustomActionButton
{
Expand All @@ -18,7 +19,7 @@ public class MeetingButton : CustomActionButton

public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;

public override bool Enabled(RoleBehaviour role)
public override bool Enabled(RoleBehaviour? role)
{
return PlayerControl.LocalPlayer.HasModifier<CaptainModifier>();
}
Expand Down
3 changes: 1 addition & 2 deletions MiraAPI.Example/ExamplePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ public partial class ExamplePlugin : BasePlugin, IMiraPlugin
public override void Load()
{
Harmony.PatchAll();
AddComponent<MiraDebugWindow>();
}
}
}
8 changes: 3 additions & 5 deletions MiraAPI.Example/MiraDebugWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using MiraAPI.Example.Modifiers;
using MiraAPI.Utilities;
using Reactor.Utilities.Attributes;
using Reactor.Utilities.Attributes;
using Reactor.Utilities.ImGui;
using System;
using UnityEngine;
Expand All @@ -21,11 +19,11 @@ public class MiraDebugWindow(IntPtr ptr) : MonoBehaviour(ptr)
}
})
{
Enabled = true
Enabled = true,
};

public void OnGUI()
{
DebuggingWindow.OnGUI();
}
}
}
3 changes: 2 additions & 1 deletion MiraAPI.Example/Modifiers/CaptainModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace MiraAPI.Example.Modifiers;
public class CaptainModifier : GameModifier
{
public override string ModifierName => "Captain";

public override int GetAmountPerGame()
{
return 1;
Expand All @@ -16,4 +17,4 @@ public override int GetAssignmentChance()
{
return 100;
}
}
}
19 changes: 16 additions & 3 deletions MiraAPI.Example/Modifiers/Freezer/FreezeModifier.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using MiraAPI.Modifiers;
using Il2CppSystem;
using MiraAPI.Example.Roles;
using MiraAPI.Modifiers;
using MiraAPI.Modifiers.Types;
using UnityEngine;

namespace MiraAPI.Example.Modifiers.Freezer;

Expand All @@ -14,15 +17,25 @@ public class FreezeModifier : TimedModifier

public override void OnActivate()
{
if (Player.AmOwner)
if (Player?.AmOwner == true)
{
Player.moveable = false;
}
}

public override void FixedUpdate()
{
base.FixedUpdate();

if (Player?.AmOwner == true || PlayerControl.LocalPlayer.Data.Role is FreezerRole)
{
Player?.cosmetics.SetOutline(true, new Nullable<Color>(Palette.LightBlue));
}
}

public override void OnTimerComplete()
{
if (Player.AmOwner)
if (Player?.AmOwner == true)
{
Player.moveable = true;
}
Expand Down
13 changes: 5 additions & 8 deletions MiraAPI.Example/Options/ExampleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ public class ExampleOptions : AbstractOptionGroup
[ModdedNumberOption("Number Opt", min: 0, max: 10, suffixType: MiraNumberSuffixes.Percent)]
public float NumberOpt { get; set; } = 4f;

[ModdedStringOption("String Opt", ["Hello", "Hey", "Bye"])]
public int StringOpt { get; set; } = 2;

[ModdedEnumOption("Best API", typeof(BestApiEnum), ["Mira API", "Mitochondria", "Reactor"])]
public BestApiEnum EnumOpt { get; set; } = BestApiEnum.MiraAPI;
[ModdedEnumOption("Best API", typeof(BestApi), ["Mira API", "Mitochondria", "Reactor"])]
public BestApi Opt { get; set; } = BestApi.MiraAPI;
}

public enum BestApiEnum
public enum BestApi
{
MiraAPI,
Mitochondria,
Reactor
}
Reactor,
}
16 changes: 9 additions & 7 deletions MiraAPI.Example/Options/ExampleOptions2.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MiraAPI.GameOptions;
using MiraAPI.GameOptions.OptionTypes;
using Reactor.Utilities;

namespace MiraAPI.Example.Options;

Expand All @@ -11,17 +12,18 @@ public class ExampleOptions2 : AbstractOptionGroup

public ModdedToggleOption ToggleOpt2 { get; } = new("Toggle Option 2", false)
{
Visible = () => OptionGroupSingleton<ExampleOptions2>.Instance.ToggleOpt1.Value
Visible = () => OptionGroupSingleton<ExampleOptions2>.Instance.ToggleOpt1.Value,
};

public ModdedStringOption StringOpt { get; } = new("String Opt", 0, ["Choice 1", "Choice 2", "Choice 3"]);

public ModdedEnumOption EnumOpt { get; } = new("Enum Opt", 0, typeof(TestingEnum));
public ModdedEnumOption EnumOpt { get; } = new("Enum Opt", 0, typeof(TestingData))
{
ChangedEvent = x => Logger<ExamplePlugin>.Info($"changed Enum Opt to {x}"),
};
}

public enum TestingEnum
public enum TestingData
{
Happy,
Sad,
Neutral
}
Neutral,
}
2 changes: 1 addition & 1 deletion MiraAPI.Example/Options/Roles/TeleporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public class TeleporterOptions : AbstractOptionGroup

[ModdedNumberOption("Zoom Distance", 4, 15)]
public float ZoomDistance { get; set; } = 6;
}
}
6 changes: 4 additions & 2 deletions MiraAPI.Example/Roles/FreezerRole.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MiraAPI.Roles;
using Il2CppInterop.Runtime.Attributes;
using MiraAPI.Roles;
using MiraAPI.Utilities.Assets;
using UnityEngine;

Expand All @@ -12,6 +13,7 @@ public class FreezerRole : ImpostorRole, ICustomRole
public string RoleDescription => RoleLongDescription;
public Color RoleColor => Palette.Blue;
public ModdedRoleTeams Team => ModdedRoleTeams.Impostor;
[HideFromIl2Cpp]
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
public int MaxPlayers => 2;
}
}
7 changes: 4 additions & 3 deletions MiraAPI.Example/Roles/TeleporterRole.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MiraAPI.Roles;
using Il2CppInterop.Runtime.Attributes;
using MiraAPI.Roles;
using MiraAPI.Utilities.Assets;
using UnityEngine;

Expand All @@ -12,6 +13,6 @@ public class TeleporterRole : CrewmateRole, ICustomRole
public string RoleDescription => RoleLongDescription;
public Color RoleColor => new Color32(221, 176, 152, 255);
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
[HideFromIl2Cpp]
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;

}
}
23 changes: 22 additions & 1 deletion MiraAPI/Colors/CustomColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,42 @@
using UnityEngine;

namespace MiraAPI.Colors;

/// <summary>
/// Represents a custom color with a main color and a shadow color.
/// </summary>
/// <param name="name">The name of the option.</param>
/// <param name="mainColor">The main color.</param>
/// <param name="shadowColor">The shadow color.</param>
public sealed class CustomColor(StringNames name, Color32 mainColor, Color32 shadowColor)
{
/// <summary>
/// Gets the main color.
/// </summary>
public Color32 MainColor { get; } = mainColor;

/// <summary>
/// Gets the shadow color.
/// </summary>
public Color32 ShadowColor { get; } = shadowColor;

/// <summary>
/// Gets the name of the color.
/// </summary>
public StringNames Name { get; } = name;

/// <inheritdoc />
public CustomColor(StringNames name, Color32 mainColor) : this(name, mainColor, mainColor.GetShadowColor(60))
{
}

/// <inheritdoc />
public CustomColor(string name, Color32 mainColor) : this(name, mainColor, mainColor.GetShadowColor(60))
{
}

/// <inheritdoc />
public CustomColor(string name, Color32 mainColor, Color32 shadowColor) : this(CustomStringName.CreateAndRegister(name), mainColor, shadowColor)
{
}
}
}
35 changes: 23 additions & 12 deletions MiraAPI/Colors/PaletteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@

namespace MiraAPI.Colors;

internal static class PaletteManager
/// <summary>
/// Used to register and track custom colors.
/// </summary>
public static class PaletteManager
{
public static readonly List<CustomColor> CustomColors = [];

public static void RegisterAllColors()
/// <summary>
/// Gets all registered custom colors.
/// </summary>
public static CustomColor[] RegisteredColors => [.. CustomColors];

internal static readonly List<CustomColor> CustomColors = [];

internal static void RegisterAllColors()
{
var colors = CustomColors.Select(x => x.MainColor);
var shadowColors = CustomColors.Select(x => x.ShadowColor);
var stringNames = CustomColors.Select(x => x.Name);
var colors = CustomColors.Select(x => x.MainColor).ToArray();
var shadowColors = CustomColors.Select(x => x.ShadowColor).ToArray();
var stringNames = CustomColors.Select(x => x.Name).ToArray();

Palette.PlayerColors = Palette.PlayerColors.ToArray().AddRangeToArray(colors);
Palette.ShadowColors = Palette.ShadowColors.ToArray().AddRangeToArray(shadowColors);
Palette.ColorNames = Palette.ColorNames.ToArray().AddRangeToArray(stringNames);

Palette.PlayerColors = Palette.PlayerColors.ToArray().AddRangeToArray(colors.ToArray());
Palette.ShadowColors = Palette.ShadowColors.ToArray().AddRangeToArray(shadowColors.ToArray());
Palette.ColorNames = Palette.ColorNames.ToArray().AddRangeToArray(stringNames.ToArray());
}
}
Palette.TextColors = Palette.TextColors.ToArray().AddRangeToArray(colors);
Palette.TextOutlineColors = Palette.TextOutlineColors.ToArray().AddRangeToArray(shadowColors);
}
}
5 changes: 4 additions & 1 deletion MiraAPI/Colors/RegisterCustomColorsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

namespace MiraAPI.Colors;

/// <summary>
/// Used to mark a class for custom colors registration.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class RegisterCustomColorsAttribute : Attribute;
public class RegisterCustomColorsAttribute : Attribute;
Loading

0 comments on commit 0aa164d

Please sign in to comment.