/// <summary> /// Adds the specified resource to the parent resource node /// </summary> /// <param name="parentNode">ResourceNode that is contained by the project</param> /// <param name="resource">New resource to add</param> /// <returns>The added resource node result</returns> public virtual MagitekResult <ResourceNode> AddResource(ResourceNode parentNode, IProjectResource resource) { var tree = _projects.FirstOrDefault(x => x.ContainsNode(parentNode)); if (tree is null) { return(new MagitekResult <ResourceNode> .Failed($"{parentNode.Item.Name} is not contained within any loaded project")); } if (parentNode.ContainsChildNode(resource.Name)) { return(new MagitekResult <ResourceNode> .Failed($"'{parentNode.Name}' already contains a child named '{resource.Name}'")); } else if (parentNode.Item.CanContainChildResources == false) { return(new MagitekResult <ResourceNode> .Failed($"'{parentNode.Name}' cannot contain children")); } try { ResourceNode childNode = resource switch { DataSource df => new DataFileNode(df.Name, df), ScatteredArranger arranger => new ArrangerNode(arranger.Name, arranger), Palette pal => new PaletteNode(pal.Name, pal), ResourceFolder folder => new ResourceFolderNode(folder.Name, folder), _ => null }; if (childNode is null) { return(new MagitekResult <ResourceNode> .Failed($"Cannot add a resource of type '{resource.GetType()}'")); } var contents = _serializerFactory.CreateWriter(tree).SerializeResource(childNode); var location = ResourceFileLocator.LocateByParent(tree, parentNode, childNode); File.WriteAllText(location, contents); parentNode.AttachChildNode(childNode); childNode.DiskLocation = location; UpdateNodeModel(tree, childNode); return(new MagitekResult <ResourceNode> .Success(childNode)); } catch (Exception ex) { return(new MagitekResult <ResourceNode> .Failed(ex.Message)); } }
/// <summary> /// Event to create a new scattered arranger from a copy /// </summary> /// <param name="copy">Source containing all elements to be copied</param> /// <param name="projectResource">Source resource within the the project</param> public AddScatteredArrangerFromCopyEvent(ElementCopy copy, IProjectResource projectResource) { Copy = copy; ProjectResource = projectResource; }
public virtual bool UnlinkResource(IProjectResource resource) => false;
public bool UnlinkResource(IProjectResource resource) => false;