/// <summary> /// Create a new blueprint /// </summary> /// <param name="objectType">The type of the blueprint that is about to be created</param> /// <param name="locationType">The location where the blueprint will be placed</param> /// <returns>The new blueprint</returns> private static INWN2Blueprint createNewBlueprint(NWN2ObjectType objectType, NWN2BlueprintLocationType locationType) { INWN2Blueprint cBlueprint = null; IResourceRepository userOverrideDirectory = null; NWN2Campaign activeCampaign = NWN2CampaignManager.Instance.ActiveCampaign; INWN2BlueprintSet instance = null; switch (locationType) { case NWN2BlueprintLocationType.Global: userOverrideDirectory = NWN2ResourceManager.Instance.UserOverrideDirectory; if (userOverrideDirectory != null) { userOverrideDirectory = NWN2ResourceManager.Instance.OverrideDirectory; } instance = NWN2GlobalBlueprintManager.Instance; break; case NWN2BlueprintLocationType.Module: instance = NWN2Toolset.NWN2ToolsetMainForm.App.Module; userOverrideDirectory = NWN2Toolset.NWN2ToolsetMainForm.App.Module.Repository; break; case NWN2BlueprintLocationType.Campaign: userOverrideDirectory = (activeCampaign != null) ? activeCampaign.Repository : null; instance = activeCampaign; break; default: throw new Exception("Unknown object type in CreateNewBlueprint()" + locationType.ToString()); } if ((userOverrideDirectory == null) || (instance == null)) { return null; } switch (objectType) { case NWN2ObjectType.Creature: cBlueprint = new NWN2CreatureBlueprint(); createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Creature, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTC")); break; case NWN2ObjectType.Door: cBlueprint = new NWN2DoorBlueprint(); createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Door, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTD")); break; case NWN2ObjectType.Item: cBlueprint = new NWN2ItemBlueprint(); createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Item, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTI")); break; case NWN2ObjectType.Placeable: cBlueprint = new NWN2PlaceableBlueprint(); createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Placeable, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTP")); break; case NWN2ObjectType.Trigger: cBlueprint = new NWN2TriggerBlueprint(); createHelp(cBlueprint, NWN2GlobalBlueprintManager.GetTemporaryBlueprintName(NWN2ObjectType.Trigger, locationType), userOverrideDirectory, BWResourceTypes.GetResourceType("UTT")); break; default: throw new Exception("Unknown object type in CreateNewBlueprint()"); } NWN2BlueprintCollection blueprintCollectionForType = instance.GetBlueprintCollectionForType(objectType); INWN2Object obj2 = cBlueprint as INWN2Object; obj2.Tag = cBlueprint.ResourceName.Value; obj2.LocalizedName[BWLanguages.CurrentLanguage] = cBlueprint.ResourceName.Value; cBlueprint.BlueprintLocation = instance.BlueprintLocation; blueprintCollectionForType.Add(cBlueprint); GFFFile file = new GFFFile(); file.FileHeader.FileType = BWResourceTypes.GetFileExtension(cBlueprint.Resource.ResourceType); cBlueprint.SaveEverythingIntoGFFStruct(file.TopLevelStruct, true); using (Stream stream = cBlueprint.Resource.GetStream(true)) { file.Save(stream); cBlueprint.Resource.Release(); } return cBlueprint; }
private void Validate(NWN2PlaceableBlueprint placeable) { // Custom validation of only blueprints here. // Validation of all NWN2DoorTemplates (in areas, blueprints). Validate((NWN2PlaceableTemplate)placeable, placeable.ResourceName.ToString()); }