internal static void MapBlueprint(ModBlueprint modBlueprint) { BlueprintItem bpItem = GameManager.GetBlueprints().AddComponent <BlueprintItem>(); if (bpItem == null) { throw new Exception("Error creating Blueprint"); } bpItem.m_DurationMinutes = modBlueprint.DurationMinutes; bpItem.m_CraftingAudio = modBlueprint.CraftingAudio; bpItem.m_RequiresForge = modBlueprint.RequiresForge; bpItem.m_RequiresWorkbench = modBlueprint.RequiresWorkbench; bpItem.m_RequiresLight = modBlueprint.RequiresLight; bpItem.m_Locked = modBlueprint.Locked; bpItem.m_CraftedResultCount = modBlueprint.CraftedResultCount; bpItem.m_CraftedResult = ModUtils.GetItem <GearItem>(modBlueprint.CraftedResult); if (!string.IsNullOrEmpty(modBlueprint.RequiredTool)) { bpItem.m_RequiredTool = ModUtils.GetItem <ToolsItem>(modBlueprint.RequiredTool); } bpItem.m_OptionalTools = ModUtils.NotNull(ModUtils.GetMatchingItems <ToolsItem>(modBlueprint.OptionalTools)); bpItem.m_RequiredGear = ModUtils.NotNull(ModUtils.GetMatchingItems <GearItem>(modBlueprint.RequiredGear)); bpItem.m_RequiredGearUnits = modBlueprint.RequiredGearUnits; }
internal static void ValidateBlueprint(ModBlueprint modBlueprint, string sourcePath) { try { ModComponentUtils.ModUtils.GetItem <GearItem>(modBlueprint.CraftedResult); if (!string.IsNullOrEmpty(modBlueprint.RequiredTool)) { ModComponentUtils.ModUtils.GetItem <ToolsItem>(modBlueprint.RequiredTool); } if (modBlueprint.OptionalTools != null) { ModComponentUtils.ModUtils.GetMatchingItems <ToolsItem>(modBlueprint.OptionalTools); } ModComponentUtils.ModUtils.GetMatchingItems <GearItem>(modBlueprint.RequiredGear); } catch (Exception e) { if (string.IsNullOrEmpty(sourcePath)) { throw new ArgumentException("Validation of blueprint " + modBlueprint.name + " failed: " + e.Message + "\nThe blueprint was provided by '" + sourcePath + "', which may be out-of-date or installed incorrectly."); } else { throw new ArgumentException("Validation of blueprint " + modBlueprint.name + " failed: " + e.Message + "\nThe blueprint may be out-of-date or installed incorrectly."); } } }
private static void MapBlueprint(GameObject prefab, string sourcePath) { ModBlueprint modBlueprint = ModUtils.GetComponent <ModBlueprint>(prefab); if (modBlueprint != null) { Mapper.RegisterBlueprint(modBlueprint, sourcePath); } }
private static void ProcessFile(string path) { string text = File.ReadAllText(path); try { ModBlueprint blueprint = FastJson.Deserialize <ModBlueprint>(text); Mapper.RegisterBlueprint(blueprint, path); } catch (Exception e) { throw new System.ArgumentException("Could not read blueprint from '" + path + "'.", e); } }
private static void ProcessText(string path, string text) { if (string.IsNullOrWhiteSpace(text)) { PageManager.SetItemPackNotWorking(path, "Skipping because blueprint text contains no information"); return; } try { ModBlueprint blueprint = MelonLoader.TinyJSON.JSON.Load(text).Make <ModBlueprint>(); if (!(blueprint is null)) { BlueprintMapper.RegisterBlueprint(blueprint, path); } else { PageManager.SetItemPackNotWorking(path, "Skipping because blueprint is null"); } }
internal static void MapBlueprint(ModBlueprint modBlueprint) { BlueprintItem bpItem = GameManager.GetBlueprints().AddComponent <BlueprintItem>(); if (bpItem is null) { throw new Exception("Error creating Blueprint"); } bpItem.m_DurationMinutes = modBlueprint.DurationMinutes; bpItem.m_CraftingAudio = modBlueprint.CraftingAudio; bpItem.m_RequiredCraftingLocation = ModComponentUtils.EnumUtils.TranslateEnumValue <CraftingLocation, ModComponentAPI.CraftingLocation>(modBlueprint.RequiredCraftingLocation); bpItem.m_RequiresLitFire = modBlueprint.RequiresLitFire; bpItem.m_RequiresLight = modBlueprint.RequiresLight; bpItem.m_Locked = false; bpItem.m_AppearsInStoryOnly = false; bpItem.m_CraftedResultCount = modBlueprint.CraftedResultCount; bpItem.m_CraftedResult = ModComponentUtils.ModUtils.GetItem <GearItem>(modBlueprint.CraftedResult); if (!string.IsNullOrEmpty(modBlueprint.RequiredTool)) { bpItem.m_RequiredTool = ModComponentUtils.ModUtils.GetItem <ToolsItem>(modBlueprint.RequiredTool); } bpItem.m_OptionalTools = ModComponentUtils.ModUtils.NotNull(ModComponentUtils.ModUtils.GetMatchingItems <ToolsItem>(modBlueprint.OptionalTools)); bpItem.m_RequiredGear = ModComponentUtils.ModUtils.NotNull(ModComponentUtils.ModUtils.GetMatchingItems <GearItem>(modBlueprint.RequiredGear)); bpItem.m_RequiredGearUnits = modBlueprint.RequiredGearUnits; bpItem.m_KeroseneLitersRequired = modBlueprint.KeroseneLitersRequired; bpItem.m_GunpowderKGRequired = modBlueprint.GunpowderKGRequired; bpItem.m_AppliedSkill = ModComponentUtils.EnumUtils.TranslateEnumValue <SkillType, ModComponentAPI.SkillType>(modBlueprint.AppliedSkill); bpItem.m_ImprovedSkill = ModComponentUtils.EnumUtils.TranslateEnumValue <SkillType, ModComponentAPI.SkillType>(modBlueprint.ImprovedSkill); }
internal static void RegisterBlueprint(ModBlueprint modBlueprint, string sourcePath) { ValidateBlueprint(modBlueprint, sourcePath); blueprints.Add(modBlueprint); }