private IDPool <T, TagType> _ReadIDMap <T, TagType>(Func <int, string, T> obtain_func, StreamReader stream) where T : UnityEngine.Object where TagType : struct, IConvertible { var pool = new IDPool <T, TagType>(); var line_id = 0; while (!stream.EndOfStream) { line_id += 1; var line = stream.ReadLine().Trim(); if (line.StartsWithInvariant("#")) { continue; } if (line.Length == 0) { continue; } var split = line.Split(' '); if (split.Length < 3) { throw new Exception($"Failed parsing ID map file: not enough columns at line {line_id} (need at least 2, ID and the name)"); } var tags_split = split[0].Split(','); try { var name_id = $"gungeon:{split[2]}"; pool[name_id] = obtain_func.Invoke(line_id, split[1]); for (int i = 0; i < tags_split.Length; i++) { var tag = (TagType)Enum.Parse(typeof(TagType), tags_split[i], true); pool.AddTag(name_id, tag); } } catch (Exception e) { throw new Exception($"Failed loading ID map file: Error while adding entry to ID pool ({e.Message})"); } } pool.LockNamespace("gungeon"); return(pool); }
private void SetupIDPools() { Logger.Debug("SetupIDPools()"); Logger.Info("Loading item ID map"); using (var stream = GetIDMapStream("items")) { Items = _ReadIDMapList <PickupObject, ItemTags>(PickupObjectDatabase.Instance.Objects, stream); } Logger.Info("Loading enemy ID map"); using (var stream = GetIDMapStream("enemies")) { Enemies = _ReadIDMapEnemyDB <AIActor, EnemyTags>(stream); } Logger.Info("Loading character ID map"); using (var stream = GetIDMapStream("characters")) { Characters = _ReadIDMapBraveResources <PlayerController, CharacterTags>(stream); } }