//updates all tags which match the cur_tag_name and save_dir (which in most cases is a single tag, unless viewing all saves). public static string update(string cur_tag_name, string new_tag_name, string save_dir, bool rule_based, string rule_attr, string rule_comparator, string rule_value) { if (String.IsNullOrEmpty(new_tag_name)) { return("Name cannot be blank"); } else if (cur_tag_name != new_tag_name && Tags.names.Contains(new_tag_name)) { return("A tag with this name already exists"); } else { List <Tag> tags = Tags.find_all(cur_tag_name, save_dir); foreach (Tag tag in tags) { tag.name = new_tag_name; if (rule_based) { tag.set_rule(rule_attr, rule_comparator, rule_value); } else { tag.remove_rule(); } } Tags.save(); if (CraftManager.main_ui) { CraftManager.main_ui.refresh(); } return("200"); } }
//creates a tag with all attribute options, returns "200" (status ok) if valid. returns error message is not valid public static string create(string tag_name, string save_dir, bool rule_based, string rule_attr, string rule_comparator, string rule_value, List <CraftData> craft = null) { tag_name = sanitize_name(tag_name); if (String.IsNullOrEmpty(tag_name)) { return("Tag Name cannot be blank"); } else if (names.Contains(tag_name)) { return("A tag with this name already exists"); } else { Tag tag = Tags.find_or_create_by(tag_name, save_dir, false); if (rule_based) { tag.set_rule(rule_attr, rule_comparator, rule_value); } else { if (craft != null) { foreach (CraftData c in craft) { tag.add(c); } } } Tags.save(); return("200"); } }
//Unassociate craft with the given tag public static void untag_craft(CraftData craft, string tag_name) { Tag tag = Tags.instance.data.Find(t => (t.name == tag_name && t.save_dir == craft.save_dir)); if (tag != null && tag.craft.Contains(craft_reference_key(craft))) { tag.remove(craft); } Tags.save(); }
public void remove(CraftData craft, bool save = true) { if (!this.rule_based && this.craft.Contains(Tags.craft_reference_key(craft))) { this.craft.Remove(Tags.craft_reference_key(craft)); craft.tag_name_cache = null; if (save) { Tags.save(); } } }
public void add(CraftData craft, bool save = true) { if (!this.rule_based) { this.craft.AddUnique(Tags.craft_reference_key(craft)); craft.tag_name_cache = null; if (save) { Tags.save(); } } }
//Unassociates a craft with all the tags it is associated with. Returns a list of the tags public static List <string> untag_craft(CraftData craft) { List <Tag> tags = Tags.instance.data.FindAll(t => (t.save_dir == craft.save_dir && t.craft.Contains(craft_reference_key(craft)))); List <string> tag_names = new List <string>(); foreach (Tag tag in tags) { tag.remove(craft, false); tag_names.AddUnique(tag.name); } Tags.save(); return(tag_names); }
//Remove a Tag from a save or from all saves if save_dir is "<all_save>" public static string remove(string tag_name, string save_dir) { List <Tag> tags = Tags.find_all(tag_name, save_dir); foreach (Tag tag in tags) { Tags.instance.data.Remove(tag); } Tags.save(); if (CraftManager.main_ui) { CraftManager.main_ui.refresh(); } return("200"); }
//returns a matching Tag or creates a new on if none was fond. public static Tag find_or_create_by(string tag_name, string save_dir, bool save_on_create = true) { tag_name = sanitize_name(tag_name); if (String.IsNullOrEmpty(tag_name)) { return(null); } Tag tag = Tags.find(tag_name, save_dir); if (tag == null) { tag = new Tag(tag_name, save_dir); } if (save_on_create) { Tags.save(); } return(tag); }