Skip to content

Commit

Permalink
Use switch expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Graicc committed Feb 12, 2024
1 parent 033c247 commit 3181cd3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 39 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,34 @@ public class ExamplePlugin : BaseUnityPlugin {}

public class MyGameManager : GorillaGameManager
{
// the game calls this when this is the gamemode for the room.
// The game calls this when this is the gamemode for the room.
public override void StartPlaying()
{
// base needs to run for base GorillaGamanger functionality to run.
// Base needs to run for base GorillaGamanger functionality to run.
base.StartPlaying();
}

// called by game when you leave a room or gamemode is changed.
// Called by game when you leave a room or gamemode is changed.
public override void StopPlaying()
{
// base needs to run for the game mode stop base GorillaGameManager functionality from running.
// Base needs to run for the game mode stop base GorillaGameManager functionality from running.
base.StopPlaying();
}

// called by the game when you leave a room after StopPlaying, use this for all important clean up and resetting the state of your game mode.
// Called by the game when you leave a room after StopPlaying, use this for all important clean up and resetting the state of your game mode.
public override void Reset()
{
}

// gamemode names must not have spaces and must not contain "CASUAL", "INFECTION", "HUNT", or "BATTLE".
// names that contain the name of other custom gamemodes will confilict.
// Gamemode names must not have spaces and must not contain "CASUAL", "INFECTION", "HUNT", or "BATTLE".
// Names that contain the name of other custom gamemodes will confilict.
public override string GameModeName()
{
return "CUSTOM";
}

// GameModeType is an enum which is really an int, so any int value will work.
// make sure to use a unique value not taken by other game modes.
// Make sure to use a unique value not taken by other game modes.
public override GameModeType GameType()
{
return (GameModeType)765;
Expand Down
42 changes: 11 additions & 31 deletions Utilla/GamemodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,38 +296,18 @@ void AddGamemodeToPrefabPool(Gamemode gamemode)
Type gmType = gamemode.GameManager;
if (gmType == null || !gmType.IsSubclassOf(typeof(GorillaGameManager)))
{
GameModeType gmKey;
switch(gamemode.BaseGamemode)
GameModeType? gmKey = gamemode.BaseGamemode switch
{
case BaseGamemode.Casual:
{
gmKey = GameModeType.Casual;
break;
}

case BaseGamemode.Infection:
{
gmKey = GameModeType.Infection;
break;
}

case BaseGamemode.Hunt:
{
gmKey = GameModeType.Hunt;
break;
}

case BaseGamemode.Paintbrawl:
{
gmKey = GameModeType.Battle;
break;
}

default:
{
return;
break;
}
BaseGamemode.Casual => GameModeType.Casual,
BaseGamemode.Infection => GameModeType.Infection,
BaseGamemode.Hunt => GameModeType.Hunt,
BaseGamemode.Paintbrawl => GameModeType.Battle,
_ => null
};

if (gmKey == null)
{
return;
}

gtGameModeKeyByName[gamemode.GamemodeString] = (int)gmKey;
Expand Down
1 change: 1 addition & 0 deletions Utilla/Utilla.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 3181cd3

Please sign in to comment.