def refresh_auto(file_): dirname = os.path.relpath( os.path.dirname(file_), project.get_project_dir(join="assets/minecraft/sounds")).replace( os.path.sep, ".") location = project.get_project_dir(join="assets/minecraft/sounds.json") with open(location) as f: f2 = os.path.relpath( file_, project.get_project_dir(join="assets/minecraft/sounds")) d = json.load(f) if dirname not in d: add_sound_group( argparse.Namespace(category="master", group=dirname, remove=False)) # print Fore.LIGHTBLUE_EX + "Adding sound " + Fore.WHITE + file_ + Fore.LIGHTBLUE_EX + " to group " + Fore.WHITE + dirname add_to_sound_group( argparse.Namespace(group=dirname, weight=1.0, pitch=1.0, volume=1.0, type="sound", stream=False, sound=f2, remove=False))
def add_sound_group(args): if project.get_project_dir(os.getcwd()): proj_json = json.load(open(os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"))) if args.group not in proj_json: new_group = {} category = args.category if args.category == "": category = input_.options(Fore.LIGHTBLUE_EX + "Please select a category:", [ "master", "ambient", "weather", "player", "neutral", "hostile", "block", "record", "music" ]) new_group["category"] = category new_group["sounds"] = [] proj_json[args.group] = new_group if args.remove: del proj_json[args.group] json.dump(proj_json, open(os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"), "w"), indent=4) if not args.remove: print Fore.GREEN + "Added sound group " + Fore.WHITE + args.group + Fore.GREEN + " successfully!" else: print Fore.GREEN + "Removed sound group " + Fore.WHITE + args.group + Fore.GREEN + " successfully!" else: if args.remove: del proj_json[args.group] json.dump(proj_json, open(os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"), "w"), indent=4) print Fore.GREEN + "Removed sound group " + Fore.WHITE + args.group + Fore.GREEN + " successfully!" return print Fore.RED + "Sound group already exists!" + Fore.CYAN + \ " (maybe you wanted mcrsrctool addsoundtogroup?)" else: print Fore.RED + "Could not find project"
def add_language(args): json_pth = project.get_project_dir(os.getcwd(), ".mcrsrctools/metadata.json") json_dta = json.load(open(json_pth)) real_path = project.get_project_dir(os.getcwd(), "assets/minecraft/lang") if not os.path.exists(os.path.join(real_path, args.file)): if input_.get_yn(Fore.RED + "Could not find specified lang file. Continue? " + Fore.CYAN) is False: return if args.remove: if args.file in json_dta["langs"]: del json_dta["langs"][args.file] print Fore.GREEN + "Deleted language " + Fore.WHITE + " " + args.file + Fore.GREEN + " successfully!" else: print Fore.RED + "Language does not exist" else: if args.file in json_dta["langs"]: print Fore.GREEN + "Collecting required info to modify language " + Fore.WHITE + " " + args.file name = args.name if args.name else raw_input(Fore.LIGHTBLUE_EX + "\tFull name of language: " + Fore.CYAN) region = args.region if args.region else raw_input(Fore.LIGHTBLUE_EX + "\tRegion of language: " + Fore.CYAN) rtl = args.rtl json_dta["langs"][args.file] = {"region": region, "rtl": rtl, "name": name} print Fore.GREEN + "Modified language " + Fore.WHITE + " " + args.file + Fore.GREEN + " successfully!" else: print Fore.GREEN + "Collecting required info to add language " + Fore.WHITE + " " + args.file name = args.name if args.name else raw_input(Fore.LIGHTBLUE_EX + "\tFull name of language: " + Fore.CYAN) region = args.region if args.region else raw_input(Fore.LIGHTBLUE_EX + "\tRegion of language: " + Fore.CYAN) rtl = args.rtl json_dta["langs"][args.file] = {"region": region, "rtl": rtl, "name": name} print Fore.GREEN + "Added language " + Fore.WHITE + " " + args.file + Fore.GREEN + " successfully!" json.dump(json_dta, open(json_pth, "w"))
def refresh_auto(file_): dirname = os.path.relpath(os.path.dirname(file_), project.get_project_dir(join="assets/minecraft/sounds")).replace( os.path.sep, ".") location = project.get_project_dir(join="assets/minecraft/sounds.json") with open(location) as f: f2 = os.path.relpath(file_, project.get_project_dir(join="assets/minecraft/sounds")) d = json.load(f) if dirname not in d: add_sound_group(argparse.Namespace(category="master", group=dirname, remove=False)) # print Fore.LIGHTBLUE_EX + "Adding sound " + Fore.WHITE + file_ + Fore.LIGHTBLUE_EX + " to group " + Fore.WHITE + dirname add_to_sound_group( argparse.Namespace(group=dirname, weight=1.0, pitch=1.0, volume=1.0, type="sound", stream=False, sound=f2, remove=False))
def add_language(args): json_pth = project.get_project_dir(os.getcwd(), ".mcrsrctools/metadata.json") json_dta = json.load(open(json_pth)) real_path = project.get_project_dir(os.getcwd(), "assets/minecraft/lang") if not os.path.exists(os.path.join(real_path, args.file)): if input_.get_yn(Fore.RED + "Could not find specified lang file. Continue? " + Fore.CYAN) is False: return if args.remove: if args.file in json_dta["langs"]: del json_dta["langs"][args.file] print Fore.GREEN + "Deleted language " + Fore.WHITE + " " + args.file + Fore.GREEN + " successfully!" else: print Fore.RED + "Language does not exist" else: if args.file in json_dta["langs"]: print Fore.GREEN + "Collecting required info to modify language " + Fore.WHITE + " " + args.file name = args.name if args.name else raw_input( Fore.LIGHTBLUE_EX + "\tFull name of language: " + Fore.CYAN) region = args.region if args.region else raw_input( Fore.LIGHTBLUE_EX + "\tRegion of language: " + Fore.CYAN) rtl = args.rtl json_dta["langs"][args.file] = { "region": region, "rtl": rtl, "name": name } print Fore.GREEN + "Modified language " + Fore.WHITE + " " + args.file + Fore.GREEN + " successfully!" else: print Fore.GREEN + "Collecting required info to add language " + Fore.WHITE + " " + args.file name = args.name if args.name else raw_input( Fore.LIGHTBLUE_EX + "\tFull name of language: " + Fore.CYAN) region = args.region if args.region else raw_input( Fore.LIGHTBLUE_EX + "\tRegion of language: " + Fore.CYAN) rtl = args.rtl json_dta["langs"][args.file] = { "region": region, "rtl": rtl, "name": name } print Fore.GREEN + "Added language " + Fore.WHITE + " " + args.file + Fore.GREEN + " successfully!" json.dump(json_dta, open(json_pth, "w"))
def is_lang_in_registry(file_): location = project.get_project_dir(os.getcwd(), ".mcrsrctools/metadata.json") entry_name = os.path.split(file_)[1] with open(location) as f: data = json.load(f) if entry_name in data["langs"]: return True return False
def is_in_sound_group(file_): location = project.get_project_dir(join="assets/minecraft/sounds.json") print location file_entry_pos = os.path.splitext( os.path.relpath(file_, os.path.normpath(project.get_project_dir(join="assets/minecraft/sounds"))).replace( os.path.sep, '/'))[0] with open(location, "r+") as f: sounds = json.load(f) for sound in sounds: for other_sound in sounds[sound]["sounds"]: if type(other_sound) == unicode: if other_sound == file_entry_pos: return True else: if other_sound["name"] == file_entry_pos: return True return False
def add_sound_group(args): if project.get_project_dir(os.getcwd()): proj_json = json.load( open( os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"))) if args.group not in proj_json: new_group = {} category = args.category if args.category == "": category = input_.options( Fore.LIGHTBLUE_EX + "Please select a category:", [ "master", "ambient", "weather", "player", "neutral", "hostile", "block", "record", "music" ]) new_group["category"] = category new_group["sounds"] = [] proj_json[args.group] = new_group if args.remove: del proj_json[args.group] json.dump(proj_json, open( os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"), "w"), indent=4) if not args.remove: print Fore.GREEN + "Added sound group " + Fore.WHITE + args.group + Fore.GREEN + " successfully!" else: print Fore.GREEN + "Removed sound group " + Fore.WHITE + args.group + Fore.GREEN + " successfully!" else: if args.remove: del proj_json[args.group] json.dump(proj_json, open( os.path.join( project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"), "w"), indent=4) print Fore.GREEN + "Removed sound group " + Fore.WHITE + args.group + Fore.GREEN + " successfully!" return print Fore.RED + "Sound group already exists!" + Fore.CYAN + \ " (maybe you wanted mcrsrctool addsoundtogroup?)" else: print Fore.RED + "Could not find project"
def is_in_sound_group(file_): location = project.get_project_dir(join="assets/minecraft/sounds.json") print location file_entry_pos = os.path.splitext( os.path.relpath( file_, os.path.normpath( project.get_project_dir( join="assets/minecraft/sounds"))).replace( os.path.sep, '/'))[0] with open(location, "r+") as f: sounds = json.load(f) for sound in sounds: for other_sound in sounds[sound]["sounds"]: if type(other_sound) == unicode: if other_sound == file_entry_pos: return True else: if other_sound["name"] == file_entry_pos: return True return False
def add_to_sound_group(args): if project.get_project_dir(os.getcwd()): proj_json = json.load( open( os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"))) if args.group not in proj_json: print Fore.RED + "Sound group does not exist! " + Fore.CYAN + "(maybe you wanted mcrsrctool addsoundgroup?)" else: if not os.path.exists( os.path.join( os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds"), args.sound)): if not input_.get_yn( Fore.RED + "I couldn't find the specified sound. Continue anyways? [Y or N] " + Fore.CYAN): return args.sound = os.path.splitext(args.sound)[0] group = proj_json[args.group] new_s = [] for entry in group["sounds"]: # print type(entry) if type(entry) == unicode: if entry == args.sound: ## print "conting" continue else: if entry["name"] == args.sound: ## print "conting" continue new_s.append(entry) ##print new_s data = {"name": args.sound} us = True if args.type == "event": data["type"] = "event" us = False if args.volume != 1.0: data["volume"] = args.volume us = False if args.pitch != 1.0: data["pitch"] = args.pitch us = False if args.weight != 1.0: data["weight"] = args.weight us = False if args.stream: data["stream"] = True us = False if us: data = args.sound if not args.remove: new_s.append(data) proj_json[args.group]["sounds"] = new_s json.dump(proj_json, open( os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"), "w"), indent=4) if not args.remove: print Fore.GREEN + "Added sound " + Fore.WHITE + args.sound + Fore.GREEN + " to group " + Fore.WHITE \ + args.group + Fore.GREEN + " successfully!" else: print Fore.GREEN + "Removed sound " + Fore.WHITE + args.sound + Fore.GREEN + " from group " + Fore.WHITE \ + args.group + Fore.GREEN + " successfully!" else: print Fore.RED + "Could not find project"
def add_to_sound_group(args): if project.get_project_dir(os.getcwd()): proj_json = json.load(open(os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"))) if args.group not in proj_json: print Fore.RED + "Sound group does not exist! " + Fore.CYAN + "(maybe you wanted mcrsrctool addsoundgroup?)" else: if not os.path.exists( os.path.join(os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds"), args.sound)): if not input_.get_yn( Fore.RED + "I couldn't find the specified sound. Continue anyways? [Y or N] " + Fore.CYAN): return args.sound = os.path.splitext(args.sound)[0] group = proj_json[args.group] new_s = [] for entry in group["sounds"]: # print type(entry) if type(entry) == unicode: if entry == args.sound: ## print "conting" continue else: if entry["name"] == args.sound: ## print "conting" continue new_s.append(entry) ##print new_s data = {"name": args.sound} us = True if args.type == "event": data["type"] = "event" us = False if args.volume != 1.0: data["volume"] = args.volume us = False if args.pitch != 1.0: data["pitch"] = args.pitch us = False if args.weight != 1.0: data["weight"] = args.weight us = False if args.stream: data["stream"] = True us = False if us: data = args.sound if not args.remove: new_s.append(data) proj_json[args.group]["sounds"] = new_s json.dump(proj_json, open(os.path.join(project.get_project_dir(os.getcwd()), "assets/minecraft/sounds.json"), "w"), indent=4) if not args.remove: print Fore.GREEN + "Added sound " + Fore.WHITE + args.sound + Fore.GREEN + " to group " + Fore.WHITE \ + args.group + Fore.GREEN + " successfully!" else: print Fore.GREEN + "Removed sound " + Fore.WHITE + args.sound + Fore.GREEN + " from group " + Fore.WHITE \ + args.group + Fore.GREEN + " successfully!" else: print Fore.RED + "Could not find project"