private static void ExtractVanillaItems(SweetBridgeDog bridge) { AnankeContext.Current.ItemsRegistry.Reset(); IEnumerable <Tuple <string, int> > pairs = bridge.CollectBuiltinItemTypes(); var enumerable = pairs as Tuple <string, int>[] ?? pairs.ToArray(); IEnumerable <Tuple <int, Type> > typeProbe = bridge.ProbeTypesOfCreatedObjects(enumerable.Select(p => p.Item2)); foreach (var pair in enumerable) { var assoc = typeProbe.FirstOrDefault(p => p.Item1 == pair.Item2); Type type = null; if (assoc != null) { type = assoc.Item2; } ItemActivator activator; if (type == null) { activator = new ItemActivator(() => null); } else { activator = new ItemActivator( () => (InventoryItem)Activator.CreateInstance(type) ); } var definition = new VanillaItemDefinition(pair.Item2, pair.Item1, activator); AnankeContext.Current.ItemsRegistry.Add(definition); } }
public static void Boot() { SweetBridgeDog bridge = new SweetBridgeDog(); ExtractVanillaItems(bridge); ExtractVanillaStaticPrefabs(bridge); ExtractVanillaEntities(bridge); ModLoader loader = new ModLoader(new DirectoryInfo("mods")); loader.LoadMods(); }
private static void ExtractVanillaEntities(SweetBridgeDog bridge) { AnankeContext.Current.LivingEntityRegistry.Reset(); var listOfVanillaEntities = bridge.CollectBuiltingEnumedEntities(); var listOfProbedEntites = bridge.ProbeTypesOfCreatedEntites(listOfVanillaEntities); foreach (var probe in listOfProbedEntites) { var activator = probe.Item2 == null ? new LivingEntityActivator(() => null) : new LivingEntityActivator(() => (LivingEntity)Activator.CreateInstance(probe.Item2)); LivingEntityDefinition definition = new LivingEntityDefinition(probe.Item1.Item2, probe.Item1.Item1, activator); AnankeContext.Current.LivingEntityRegistry.Add(definition); } }
private static void ExtractVanillaStaticPrefabs(SweetBridgeDog bridge) { AnankeContext.Current.StaticPrefabRegistry.Reset(); IEnumerable <Tuple <string, int> > listOfVanillaPrefabs = bridge.CollectBuiltinEnummedStaticPrefabs(); IEnumerable <Tuple <Tuple <string, int>, Type> > listOfProbedItems = bridge.ProbeTypesOfCreatedStaticPrefabs(listOfVanillaPrefabs); foreach (var probe in listOfProbedItems) { var activator = probe.Item2 == null ? new StaticPrefabActivator(() => null) : new StaticPrefabActivator(() => (StaticPrefab)Activator.CreateInstance(probe.Item2)); StaticPrefabDefinition definition = new StaticPrefabDefinition(probe.Item1.Item2, probe.Item1.Item1, activator); AnankeContext.Current.StaticPrefabRegistry.Add(definition); } }