|
| 1 | +/* |
| 2 | + * PROJECT: Cult of the Lamb Multiplayer Mod |
| 3 | + * LICENSE: MIT (https://spdx.org/licenses/MIT) |
| 4 | + * PURPOSE: Setting callbacks methods |
| 5 | + * COPYRIGHT: Copyright 2025 GeoB99 <[email protected]> |
| 6 | + */ |
| 7 | + |
| 8 | +/* IMPORTS ********************************************************************/ |
| 9 | + |
| 10 | +using COTLMP; |
| 11 | +using COTLMP.Debug; |
| 12 | +using COTLMP.Api; |
| 13 | +using BepInEx; |
| 14 | +using BepInEx.Configuration; |
| 15 | +using HarmonyLib; |
| 16 | +using System; |
| 17 | +using UnityEngine; |
| 18 | +using UnityEngine.Assertions; |
| 19 | + |
| 20 | +/* CLASSES & CODE *************************************************************/ |
| 21 | + |
| 22 | +/* |
| 23 | + * @brief |
| 24 | + * Contains the classes and code for the mod game related stuff. |
| 25 | + * |
| 26 | + * @class Callbacks |
| 27 | + * The callbacks class which contains callback methods for the |
| 28 | + * mod game settings. |
| 29 | + */ |
| 30 | +namespace COTLMP.Game |
| 31 | +{ |
| 32 | + internal static class Callbacks |
| 33 | + { |
| 34 | + /* |
| 35 | + * @brief |
| 36 | + * A callback that gets called when the Toggle Mod |
| 37 | + * setting's value has changed. |
| 38 | + * |
| 39 | + * @param[in] Value |
| 40 | + * A boolean value representing the value of the setting |
| 41 | + * that has changed. |
| 42 | + */ |
| 43 | + public static void ModToggleCallback(bool Value) |
| 44 | + { |
| 45 | + string Section; |
| 46 | + ConfigDefinition Definition; |
| 47 | + ConfigEntry<bool> SettingEntry; |
| 48 | + |
| 49 | + /* Retrieve the section name for the setting */ |
| 50 | + Section = COTLMP.Api.Configuration.GetSectionName(CONFIGURATION_SECTION.ModSettings); |
| 51 | + |
| 52 | + /* Get the Mod Toggle setting */ |
| 53 | + Definition = new ConfigDefinition(Section, "Toggle Mod"); |
| 54 | + SettingEntry = COTLMP.Api.Configuration.GetSettingEntry<bool>(Definition); |
| 55 | + Assert.IsNotNull(SettingEntry); |
| 56 | + |
| 57 | + /* Cache the new value to the globals store */ |
| 58 | + Plugin.Globals.EnableMod = Value; |
| 59 | + |
| 60 | + /* FIXME: Enable/Disable mod execution here */ |
| 61 | + |
| 62 | + /* Overwrite the current value of the setting and flush it */ |
| 63 | + SettingEntry.BoxedValue = Value; |
| 64 | + COTLMP.Api.Configuration.FlushSettings(); |
| 65 | + } |
| 66 | + |
| 67 | + /* |
| 68 | + * @brief |
| 69 | + * A callback that gets called when the Game Mode |
| 70 | + * setting's value has changed. |
| 71 | + * |
| 72 | + * @param[in] Value |
| 73 | + * An integer value representing the value of the |
| 74 | + * setting that has changed. |
| 75 | + */ |
| 76 | + public static void GameModeCallback(int Value) |
| 77 | + { |
| 78 | + string Section; |
| 79 | + string GameMode; |
| 80 | + ConfigDefinition Definition; |
| 81 | + ConfigEntry<string> SettingEntry; |
| 82 | + |
| 83 | + /* Retrieve the section name for the setting */ |
| 84 | + Section = COTLMP.Api.Configuration.GetSectionName(CONFIGURATION_SECTION.ServerSettings); |
| 85 | + |
| 86 | + /* Get the Game Mode setting */ |
| 87 | + Definition = new ConfigDefinition(Section, "Game Mode"); |
| 88 | + SettingEntry = COTLMP.Api.Configuration.GetSettingEntry<string>(Definition); |
| 89 | + Assert.IsNotNull(SettingEntry); |
| 90 | + |
| 91 | + /* FIXME: This is a placeholder code, the game modes should be declared in a dedicated enum */ |
| 92 | + switch (Value) |
| 93 | + { |
| 94 | + case 0: |
| 95 | + { |
| 96 | + GameMode = "Standard"; |
| 97 | + break; |
| 98 | + } |
| 99 | + |
| 100 | + case 1: |
| 101 | + { |
| 102 | + GameMode = "Boss Fight"; |
| 103 | + break; |
| 104 | + } |
| 105 | + |
| 106 | + case 2: |
| 107 | + { |
| 108 | + GameMode = "Deathmatch"; |
| 109 | + break; |
| 110 | + } |
| 111 | + |
| 112 | + case 3: |
| 113 | + { |
| 114 | + GameMode = "Zombies!"; |
| 115 | + break; |
| 116 | + } |
| 117 | + |
| 118 | + /* Always default the game mode to Standard on bogus values */ |
| 119 | + default: |
| 120 | + { |
| 121 | + GameMode = "Standard"; |
| 122 | + break; |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + /* Cache the new value to the globals store */ |
| 127 | + Plugin.Globals.GameMode = GameMode; |
| 128 | + |
| 129 | + /* Overwrite the current value of the setting and flush it */ |
| 130 | + SettingEntry.BoxedValue = GameMode; |
| 131 | + COTLMP.Api.Configuration.FlushSettings(); |
| 132 | + } |
| 133 | + |
| 134 | + /* |
| 135 | + * @brief |
| 136 | + * A callback that gets called when the Max Players |
| 137 | + * Count setting's value has changed. |
| 138 | + * |
| 139 | + * @param[in] Value |
| 140 | + * An integer value representing the value of the |
| 141 | + * setting that has changed. |
| 142 | + */ |
| 143 | + public static void PlayerCountCallback(int Value) |
| 144 | + { |
| 145 | + string Section; |
| 146 | + ConfigDefinition Definition; |
| 147 | + ConfigEntry<int> SettingEntry; |
| 148 | + |
| 149 | + /* Retrieve the section name for the setting */ |
| 150 | + Section = COTLMP.Api.Configuration.GetSectionName(CONFIGURATION_SECTION.ServerSettings); |
| 151 | + |
| 152 | + /* Get the Max Players Count setting */ |
| 153 | + Definition = new ConfigDefinition(Section, "Max Players"); |
| 154 | + SettingEntry = COTLMP.Api.Configuration.GetSettingEntry<int>(Definition); |
| 155 | + Assert.IsNotNull(SettingEntry); |
| 156 | + |
| 157 | + /* |
| 158 | + * Cache the new value to the globals store. |
| 159 | + * The horizontal selector begins its first element at index of 0 |
| 160 | + * which is which why we increment the value by one to make up the |
| 161 | + * real count of max number of players. |
| 162 | + */ |
| 163 | + Plugin.Globals.MaxNumPlayers = Value + 1; |
| 164 | + |
| 165 | + /* Overwrite the current value of the setting and flush it */ |
| 166 | + SettingEntry.BoxedValue = Value + 1; |
| 167 | + COTLMP.Api.Configuration.FlushSettings(); |
| 168 | + } |
| 169 | + |
| 170 | + /* |
| 171 | + * @brief |
| 172 | + * A callback that gets called when the Toggle Voice |
| 173 | + * Chat setting's value has changed. |
| 174 | + * |
| 175 | + * @param[in] Value |
| 176 | + * A boolean value representing the value of the |
| 177 | + * setting that has changed. |
| 178 | + */ |
| 179 | + public static void VoiceChatCallback(bool Value) |
| 180 | + { |
| 181 | + string Section; |
| 182 | + ConfigDefinition Definition; |
| 183 | + ConfigEntry<bool> SettingEntry; |
| 184 | + |
| 185 | + /* Retrieve the section name for the setting */ |
| 186 | + Section = COTLMP.Api.Configuration.GetSectionName(CONFIGURATION_SECTION.ServerSettings); |
| 187 | + |
| 188 | + /* Get the Voice Chat Toggle setting */ |
| 189 | + Definition = new ConfigDefinition(Section, "Toggle Voice Chat"); |
| 190 | + SettingEntry = COTLMP.Api.Configuration.GetSettingEntry<bool>(Definition); |
| 191 | + Assert.IsNotNull(SettingEntry); |
| 192 | + |
| 193 | + /* Cache the new value to the globals store */ |
| 194 | + Plugin.Globals.EnableVoiceChat = Value; |
| 195 | + |
| 196 | + /* FIXME: Enable/Disable the voice chat subsystem here */ |
| 197 | + |
| 198 | + /* Overwrite the current value of the setting and flush it */ |
| 199 | + SettingEntry.BoxedValue = Value; |
| 200 | + COTLMP.Api.Configuration.FlushSettings(); |
| 201 | + } |
| 202 | + } |
| 203 | +} |
| 204 | + |
| 205 | +/* EOF */ |
0 commit comments