diff options
Diffstat (limited to 'GameData.cs')
| -rw-r--r-- | GameData.cs | 442 |
1 files changed, 435 insertions, 7 deletions
| diff --git a/GameData.cs b/GameData.cs index 87278ac..f131e85 100644 --- a/GameData.cs +++ b/GameData.cs | |||
| @@ -1,18 +1,446 @@ | |||
| 1 | using System.Collections.Generic; | 1 | using System.Collections.Generic; |
| 2 | using System.IO; | ||
| 3 | using YamlDotNet.Serialization; | ||
| 2 | 4 | ||
| 3 | namespace ManifoldGardenArchipelago | 5 | namespace ManifoldGardenArchipelago |
| 4 | { | 6 | { |
| 5 | public class GameData | 7 | public readonly struct SceneItemReference(string scene_arg, int index_arg) |
| 6 | { | 8 | { |
| 7 | public readonly struct ChainListenerReference(string scene_arg, int index_arg) | 9 | public readonly string scene = scene_arg; |
| 10 | public readonly int index = index_arg; | ||
| 11 | |||
| 12 | public override string ToString() | ||
| 13 | { | ||
| 14 | return $"({scene}, {index})"; | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | public readonly struct LocationDescription(string name_arg, Requirement requirement_arg) | ||
| 19 | { | ||
| 20 | public readonly string name = name_arg; | ||
| 21 | public readonly Requirement requirement = requirement_arg; | ||
| 22 | } | ||
| 23 | |||
| 24 | public class SceneDescription | ||
| 25 | { | ||
| 26 | public readonly List<LocationDescription> locations = []; | ||
| 27 | public readonly Dictionary<int, Requirement> doors = []; | ||
| 28 | public readonly Dictionary<int, Requirement> smokeWalls = []; | ||
| 29 | public readonly Dictionary<int, Requirement> worldGrows = []; | ||
| 30 | } | ||
| 31 | |||
| 32 | public class GameStateListeners | ||
| 33 | { | ||
| 34 | public readonly Dictionary<string, Requirement> locations = []; | ||
| 35 | public readonly Dictionary<SceneItemReference, Requirement> doors = []; | ||
| 36 | public readonly Dictionary<SceneItemReference, Requirement> smokeWalls = []; | ||
| 37 | public readonly Dictionary<SceneItemReference, Requirement> worldGrows = []; | ||
| 38 | } | ||
| 39 | |||
| 40 | public static class GameData | ||
| 41 | { | ||
| 42 | public static readonly Dictionary<string, SceneDescription> scenes = []; | ||
| 43 | |||
| 44 | public static readonly Dictionary<string, GameStateListeners> listenersByScene = []; | ||
| 45 | public static readonly Dictionary<SceneItemReference, GameStateListeners> listenersByButton = []; | ||
| 46 | public static readonly Dictionary<SceneItemReference, GameStateListeners> listenersBySocket = []; | ||
| 47 | public static readonly Dictionary<SceneItemReference, GameStateListeners> listenersByPad = []; | ||
| 48 | public static readonly Dictionary<SceneItemReference, GameStateListeners> listenersByWaterwheel = []; | ||
| 49 | public static readonly Dictionary<SceneItemReference, GameStateListeners> listenersBySphere = []; | ||
| 50 | public static readonly Dictionary<string, GameStateListeners> listenersByItem = []; | ||
| 51 | |||
| 52 | public static Requirement ParseRequirement(string scene, Dictionary<object, object> yamlReq) | ||
| 53 | { | ||
| 54 | List<Requirement> reqs = []; | ||
| 55 | |||
| 56 | if (yamlReq.ContainsKey("item")) | ||
| 57 | { | ||
| 58 | if (yamlReq["item"] is string itemName) | ||
| 59 | { | ||
| 60 | reqs.Add(new ItemRequirement(itemName)); | ||
| 61 | } | ||
| 62 | else if (yamlReq["item"] is List<string> items) | ||
| 63 | { | ||
| 64 | foreach (var item in items) | ||
| 65 | { | ||
| 66 | reqs.Add(new ItemRequirement(item)); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | if (yamlReq.ContainsKey("button")) | ||
| 72 | { | ||
| 73 | if (yamlReq["button"] is string index) | ||
| 74 | { | ||
| 75 | reqs.Add(new ButtonRequirement(new(scene, int.Parse(index)))); | ||
| 76 | } | ||
| 77 | else if (yamlReq["button"] is Dictionary<object, object> details) | ||
| 78 | { | ||
| 79 | reqs.Add(new ButtonRequirement(new((string)details["scene"], int.Parse((string)details["index"])))); | ||
| 80 | } | ||
| 81 | else if (yamlReq["button"] is List<object> buttons) | ||
| 82 | { | ||
| 83 | foreach (var button in buttons) | ||
| 84 | { | ||
| 85 | if (button is string index2) | ||
| 86 | { | ||
| 87 | reqs.Add(new ButtonRequirement(new(scene, int.Parse(index2)))); | ||
| 88 | } | ||
| 89 | else if (button is Dictionary<object, object> details2) | ||
| 90 | { | ||
| 91 | reqs.Add(new ButtonRequirement(new((string)details2["scene"], int.Parse((string)details2["index"])))); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | if (yamlReq.ContainsKey("socket")) | ||
| 98 | { | ||
| 99 | if (yamlReq["socket"] is string index) | ||
| 100 | { | ||
| 101 | reqs.Add(new SocketRequirement(new(scene, int.Parse(index)))); | ||
| 102 | } | ||
| 103 | else if (yamlReq["socket"] is Dictionary<object, object> details) | ||
| 104 | { | ||
| 105 | reqs.Add(new SocketRequirement(new((string)details["scene"], int.Parse((string)details["index"])))); | ||
| 106 | } | ||
| 107 | else if (yamlReq["socket"] is List<object> buttons) | ||
| 108 | { | ||
| 109 | foreach (var button in buttons) | ||
| 110 | { | ||
| 111 | if (button is string index2) | ||
| 112 | { | ||
| 113 | reqs.Add(new SocketRequirement(new(scene, int.Parse(index2)))); | ||
| 114 | } | ||
| 115 | else if (button is Dictionary<object, object> details2) | ||
| 116 | { | ||
| 117 | reqs.Add(new SocketRequirement(new((string)details2["scene"], int.Parse((string)details2["index"])))); | ||
| 118 | } | ||
| 119 | } | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | if (yamlReq.ContainsKey("pad")) | ||
| 124 | { | ||
| 125 | if (yamlReq["pad"] is string index) | ||
| 126 | { | ||
| 127 | reqs.Add(new PadRequirement(new(scene, int.Parse(index)))); | ||
| 128 | } | ||
| 129 | else if (yamlReq["pad"] is Dictionary<object, object> details) | ||
| 130 | { | ||
| 131 | reqs.Add(new PadRequirement(new((string)details["scene"], int.Parse((string)details["index"])))); | ||
| 132 | } | ||
| 133 | else if (yamlReq["pad"] is List<object> buttons) | ||
| 134 | { | ||
| 135 | foreach (var button in buttons) | ||
| 136 | { | ||
| 137 | if (button is string index2) | ||
| 138 | { | ||
| 139 | reqs.Add(new PadRequirement(new(scene, int.Parse(index2)))); | ||
| 140 | } | ||
| 141 | else if (button is Dictionary<object, object> details2) | ||
| 142 | { | ||
| 143 | reqs.Add(new PadRequirement(new((string)details2["scene"], int.Parse((string)details2["index"])))); | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | if (yamlReq.ContainsKey("waterwheel")) | ||
| 150 | { | ||
| 151 | if (yamlReq["waterwheel"] is string index) | ||
| 152 | { | ||
| 153 | reqs.Add(new WaterwheelRequirement(new(scene, int.Parse(index)))); | ||
| 154 | } | ||
| 155 | else if (yamlReq["waterwheel"] is Dictionary<object, object> details) | ||
| 156 | { | ||
| 157 | reqs.Add(new WaterwheelRequirement(new((string)details["scene"], int.Parse((string)details["index"])))); | ||
| 158 | } | ||
| 159 | else if (yamlReq["waterwheel"] is List<object> buttons) | ||
| 160 | { | ||
| 161 | foreach (var button in buttons) | ||
| 162 | { | ||
| 163 | if (button is string index2) | ||
| 164 | { | ||
| 165 | reqs.Add(new WaterwheelRequirement(new(scene, int.Parse(index2)))); | ||
| 166 | } | ||
| 167 | else if (button is Dictionary<object, object> details2) | ||
| 168 | { | ||
| 169 | reqs.Add(new WaterwheelRequirement(new((string)details2["scene"], int.Parse((string)details2["index"])))); | ||
| 170 | } | ||
| 171 | } | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | if (yamlReq.ContainsKey("sphere")) | ||
| 176 | { | ||
| 177 | if (yamlReq["sphere"] is string index) | ||
| 178 | { | ||
| 179 | reqs.Add(new SphereRequirement(new(scene, int.Parse(index)))); | ||
| 180 | } | ||
| 181 | else if (yamlReq["sphere"] is Dictionary<object, object> details) | ||
| 182 | { | ||
| 183 | reqs.Add(new SphereRequirement(new((string)details["scene"], int.Parse((string)details["index"])))); | ||
| 184 | } | ||
| 185 | else if (yamlReq["sphere"] is List<object> buttons) | ||
| 186 | { | ||
| 187 | foreach (var button in buttons) | ||
| 188 | { | ||
| 189 | if (button is string index2) | ||
| 190 | { | ||
| 191 | reqs.Add(new SphereRequirement(new(scene, int.Parse(index2)))); | ||
| 192 | } | ||
| 193 | else if (button is Dictionary<object, object> details2) | ||
| 194 | { | ||
| 195 | reqs.Add(new SphereRequirement(new((string)details2["scene"], int.Parse((string)details2["index"])))); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | if (yamlReq.ContainsKey("or")) | ||
| 202 | { | ||
| 203 | List<Requirement> unionReq = []; | ||
| 204 | |||
| 205 | foreach (var reqObj in (List<object>)yamlReq["or"]) | ||
| 206 | { | ||
| 207 | unionReq.Add(ParseRequirement(scene, (Dictionary<object, object>)reqObj)); | ||
| 208 | } | ||
| 209 | |||
| 210 | reqs.Add(new OrRequirement(unionReq)); | ||
| 211 | } | ||
| 212 | |||
| 213 | if (yamlReq.ContainsKey("inverted")) | ||
| 214 | { | ||
| 215 | reqs.Add(new InvertedRequirement(ParseRequirement(scene, (Dictionary<object, object>)yamlReq["inverted"]))); | ||
| 216 | } | ||
| 217 | |||
| 218 | if (reqs.Count == 1) | ||
| 219 | { | ||
| 220 | return reqs[0]; | ||
| 221 | } | ||
| 222 | else | ||
| 223 | { | ||
| 224 | return new AndRequirement(reqs); | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | private static GameStateListeners GetOrAddListeners<T>(Dictionary<T, GameStateListeners> kvp, T key) | ||
| 8 | { | 229 | { |
| 9 | public readonly string scene = scene_arg; | 230 | if (!kvp.TryGetValue(key, out GameStateListeners listeners)) |
| 10 | public readonly int index = index_arg; | 231 | { |
| 232 | listeners = new(); | ||
| 233 | kvp[key] = listeners; | ||
| 234 | } | ||
| 235 | |||
| 236 | return listeners; | ||
| 11 | } | 237 | } |
| 12 | 238 | ||
| 13 | public static readonly Dictionary<string, List<ChainListenerReference>> door_by_item = new() | 239 | public static void Load() |
| 14 | { | 240 | { |
| 15 | {"Blue Secret Path", [new ChainListenerReference("World_000_Optimized", 16)] } | 241 | Plugin.Logger.LogInfo(Path.Combine(BepInEx.Paths.BepInExRootPath, "plugins", "game_data.yaml")); |
| 16 | }; | 242 | var yamlText = File.OpenText(Path.Combine(BepInEx.Paths.BepInExRootPath, "plugins", "game_data.yaml")); |
| 243 | |||
| 244 | var deserializer = new DeserializerBuilder().Build(); | ||
| 245 | var yamlObject = deserializer.Deserialize<Dictionary<string, object>>(yamlText); | ||
| 246 | |||
| 247 | foreach (var scenePair in yamlObject) | ||
| 248 | { | ||
| 249 | Plugin.Logger.LogInfo($"Scene: {scenePair.Key}"); | ||
| 250 | SceneDescription sceneDescription = new(); | ||
| 251 | |||
| 252 | var sceneDetails = (Dictionary<object, object>)scenePair.Value; | ||
| 253 | |||
| 254 | if (sceneDetails.ContainsKey("locations")) | ||
| 255 | { | ||
| 256 | var sceneLocations = (Dictionary<object, object>)sceneDetails["locations"]; | ||
| 257 | |||
| 258 | foreach (var locationPair in sceneLocations) | ||
| 259 | { | ||
| 260 | string locationName = (string)locationPair.Key; | ||
| 261 | Requirement req = ParseRequirement(scenePair.Key, (Dictionary<object, object>)locationPair.Value); | ||
| 262 | sceneDescription.locations.Add(new(locationName, req)); | ||
| 263 | |||
| 264 | Plugin.Logger.LogInfo($"{locationName} requirements: {req}"); | ||
| 265 | |||
| 266 | foreach (var reqScene in req.references.scenes) | ||
| 267 | { | ||
| 268 | GetOrAddListeners(listenersByScene, reqScene).locations[locationName] = req; | ||
| 269 | } | ||
| 270 | |||
| 271 | foreach (var button in req.references.buttons) | ||
| 272 | { | ||
| 273 | GetOrAddListeners(listenersByButton, button).locations[locationName] = req; | ||
| 274 | } | ||
| 275 | |||
| 276 | foreach (var socket in req.references.sockets) | ||
| 277 | { | ||
| 278 | GetOrAddListeners(listenersBySocket, socket).locations[locationName] = req; | ||
| 279 | } | ||
| 280 | |||
| 281 | foreach (var pad in req.references.pads) | ||
| 282 | { | ||
| 283 | GetOrAddListeners(listenersByPad, pad).locations[locationName] = req; | ||
| 284 | } | ||
| 285 | |||
| 286 | foreach (var waterwheel in req.references.waterwheels) | ||
| 287 | { | ||
| 288 | GetOrAddListeners(listenersByWaterwheel, waterwheel).locations[locationName] = req; | ||
| 289 | } | ||
| 290 | |||
| 291 | foreach (var sphere in req.references.spheres) | ||
| 292 | { | ||
| 293 | GetOrAddListeners(listenersBySphere, sphere).locations[locationName] = req; | ||
| 294 | } | ||
| 295 | |||
| 296 | foreach (var item in req.references.items) | ||
| 297 | { | ||
| 298 | GetOrAddListeners(listenersByItem, item).locations[locationName] = req; | ||
| 299 | } | ||
| 300 | } | ||
| 301 | } | ||
| 302 | |||
| 303 | if (sceneDetails.ContainsKey("doors")) | ||
| 304 | { | ||
| 305 | var sceneDoors = (Dictionary<object, object>)sceneDetails["doors"]; | ||
| 306 | |||
| 307 | foreach (var doorPair in sceneDoors) | ||
| 308 | { | ||
| 309 | SceneItemReference sir = new(scenePair.Key, int.Parse((string)doorPair.Key)); | ||
| 310 | Requirement req = ParseRequirement(scenePair.Key, (Dictionary<object, object>)doorPair.Value); | ||
| 311 | sceneDescription.doors[sir.index] = req; | ||
| 312 | |||
| 313 | Plugin.Logger.LogInfo($"Door {sir} requirements: {req}"); | ||
| 314 | |||
| 315 | foreach (var reqScene in req.references.scenes) | ||
| 316 | { | ||
| 317 | GetOrAddListeners(listenersByScene, reqScene).doors[sir] = req; | ||
| 318 | } | ||
| 319 | |||
| 320 | foreach (var button in req.references.buttons) | ||
| 321 | { | ||
| 322 | GetOrAddListeners(listenersByButton, button).doors[sir] = req; | ||
| 323 | } | ||
| 324 | |||
| 325 | foreach (var socket in req.references.sockets) | ||
| 326 | { | ||
| 327 | GetOrAddListeners(listenersBySocket, socket).doors[sir] = req; | ||
| 328 | } | ||
| 329 | |||
| 330 | foreach (var pad in req.references.pads) | ||
| 331 | { | ||
| 332 | GetOrAddListeners(listenersByPad, pad).doors[sir] = req; | ||
| 333 | } | ||
| 334 | |||
| 335 | foreach (var waterwheel in req.references.waterwheels) | ||
| 336 | { | ||
| 337 | GetOrAddListeners(listenersByWaterwheel, waterwheel).doors[sir] = req; | ||
| 338 | } | ||
| 339 | |||
| 340 | foreach (var sphere in req.references.spheres) | ||
| 341 | { | ||
| 342 | GetOrAddListeners(listenersBySphere, sphere).doors[sir] = req; | ||
| 343 | } | ||
| 344 | |||
| 345 | foreach (var item in req.references.items) | ||
| 346 | { | ||
| 347 | GetOrAddListeners(listenersByItem, item).doors[sir] = req; | ||
| 348 | } | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | if (sceneDetails.ContainsKey("smoke")) | ||
| 353 | { | ||
| 354 | foreach (var smokePair in (Dictionary<object, object>)sceneDetails["smoke"]) | ||
| 355 | { | ||
| 356 | SceneItemReference sir = new(scenePair.Key, int.Parse((string)smokePair.Key)); | ||
| 357 | Requirement req = ParseRequirement(scenePair.Key, (Dictionary<object, object>)smokePair.Value); | ||
| 358 | sceneDescription.smokeWalls[sir.index] = req; | ||
| 359 | |||
| 360 | foreach (var reqScene in req.references.scenes) | ||
| 361 | { | ||
| 362 | GetOrAddListeners(listenersByScene, reqScene).smokeWalls[sir] = req; | ||
| 363 | } | ||
| 364 | |||
| 365 | foreach (var button in req.references.buttons) | ||
| 366 | { | ||
| 367 | GetOrAddListeners(listenersByButton, button).smokeWalls[sir] = req; | ||
| 368 | } | ||
| 369 | |||
| 370 | foreach (var socket in req.references.sockets) | ||
| 371 | { | ||
| 372 | GetOrAddListeners(listenersBySocket, socket).smokeWalls[sir] = req; | ||
| 373 | } | ||
| 374 | |||
| 375 | foreach (var pad in req.references.pads) | ||
| 376 | { | ||
| 377 | GetOrAddListeners(listenersByPad, pad).smokeWalls[sir] = req; | ||
| 378 | } | ||
| 379 | |||
| 380 | foreach (var waterwheel in req.references.waterwheels) | ||
| 381 | { | ||
| 382 | GetOrAddListeners(listenersByWaterwheel, waterwheel).smokeWalls[sir] = req; | ||
| 383 | } | ||
| 384 | |||
| 385 | foreach (var sphere in req.references.spheres) | ||
| 386 | { | ||
| 387 | GetOrAddListeners(listenersBySphere, sphere).smokeWalls[sir] = req; | ||
| 388 | } | ||
| 389 | |||
| 390 | foreach (var item in req.references.items) | ||
| 391 | { | ||
| 392 | GetOrAddListeners(listenersByItem, item).smokeWalls[sir] = req; | ||
| 393 | } | ||
| 394 | } | ||
| 395 | } | ||
| 396 | |||
| 397 | if (sceneDetails.ContainsKey("world_grow")) | ||
| 398 | { | ||
| 399 | foreach (var worldPair in (Dictionary<object, object>)sceneDetails["world_grow"]) | ||
| 400 | { | ||
| 401 | SceneItemReference sir = new(scenePair.Key, int.Parse((string)worldPair.Key)); | ||
| 402 | Requirement req = ParseRequirement(scenePair.Key, (Dictionary<object, object>)worldPair.Value); | ||
| 403 | sceneDescription.worldGrows[sir.index] = req; | ||
| 404 | |||
| 405 | foreach (var reqScene in req.references.scenes) | ||
| 406 | { | ||
| 407 | GetOrAddListeners(listenersByScene, reqScene).worldGrows[sir] = req; | ||
| 408 | } | ||
| 409 | |||
| 410 | foreach (var button in req.references.buttons) | ||
| 411 | { | ||
| 412 | GetOrAddListeners(listenersByButton, button).worldGrows[sir] = req; | ||
| 413 | } | ||
| 414 | |||
| 415 | foreach (var socket in req.references.sockets) | ||
| 416 | { | ||
| 417 | GetOrAddListeners(listenersBySocket, socket).worldGrows[sir] = req; | ||
| 418 | } | ||
| 419 | |||
| 420 | foreach (var pad in req.references.pads) | ||
| 421 | { | ||
| 422 | GetOrAddListeners(listenersByPad, pad).worldGrows[sir] = req; | ||
| 423 | } | ||
| 424 | |||
| 425 | foreach (var waterwheel in req.references.waterwheels) | ||
| 426 | { | ||
| 427 | GetOrAddListeners(listenersByWaterwheel, waterwheel).worldGrows[sir] = req; | ||
| 428 | } | ||
| 429 | |||
| 430 | foreach (var sphere in req.references.spheres) | ||
| 431 | { | ||
| 432 | GetOrAddListeners(listenersBySphere, sphere).worldGrows[sir] = req; | ||
| 433 | } | ||
| 434 | |||
| 435 | foreach (var item in req.references.items) | ||
| 436 | { | ||
| 437 | GetOrAddListeners(listenersByItem, item).worldGrows[sir] = req; | ||
| 438 | } | ||
| 439 | } | ||
| 440 | } | ||
| 441 | |||
| 442 | scenes[scenePair.Key] = sceneDescription; | ||
| 443 | } | ||
| 444 | } | ||
| 17 | } | 445 | } |
| 18 | } | 446 | } |
