Created
October 17, 2021 04:43
-
-
Save ShellyHerself/5cd2d5c192d915ee159b949c783f3b16 to your computer and use it in GitHub Desktop.
A tool for quickly renaming bones in jms/jma/etc files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DESCRIPTION = ''' | |
Quick and dirty script for translating node names in jms-jma-jmm-etc files. | |
Requested for easy conversion of bonesets from one game to another. | |
For an example translation list for use with this tool, check here: | |
https://gist.github.com/gbMichelle/3015af5888565f4b1506e37655dfe98c | |
Licensed under GPLv3 https://www.gnu.org/licenses/gpl-3.0.en.html | |
Made by Shelly Herself! | |
Socials & Donation Links: | |
https://twitter.com/Shelly_Herself | |
https://github.com/gbMichelle | |
https://ko-fi.com/shellyherself | |
https://paypal.me/gbmichelle | |
''' | |
def fuck_you(): | |
print(""" | |
Ya blew it | |
/'¯/) | |
,/¯ / | |
/ / | |
/´¯/' '/´¯¯`·¸ | |
/'/ / / /¨¯\\ | |
('( ´ ´ ¯~/' ') | |
\\ ' / | |
\\ _ ·´ | |
\\ ( | |
\\ \\""") | |
try: | |
print(DESCRIPTION) | |
print("") | |
print("#################################################") | |
print("") | |
import sys | |
import glob | |
from traceback import format_exc | |
args = sys.argv[1:] | |
# Build a translation list from a file with key:value pairs | |
translation_list = {} | |
if len(args) >= 1: | |
not_good = False | |
print("Reading", args[0], "as translation file.") | |
with open(args[0], 'r') as file: | |
for line in file.readlines(): | |
# Just skip empty lines, because people make mistakes | |
line = line.strip() | |
if not line: continue | |
# Complain if people fucked up | |
if line.count(":") < 1: | |
print("Non empty line missing ':' split character on line:", line) | |
not_good = True | |
continue | |
if line.count(":") > 1: | |
print("More than one ':' split character on line:", line) | |
not_good = True | |
continue | |
# Split the lines | |
key, value = line.split(":") | |
translation_list[key.strip()] = value.strip() | |
if not_good: | |
print("\nCOULD NOT CONVERT! Translation index had errors.") | |
exit(1) | |
print("\nUsing translation index with the following translations:") | |
for key in translation_list: | |
print("\"%s\"" % key, "->", "\"%s\"" % translation_list[key]) | |
print("") | |
# Tell people about command usage if they didn't use the tool right | |
if len(args) < 2: | |
if len(args) < 1: | |
print("Didn't supply a translation list") | |
print("Example contents of a translation list file:") | |
print("") | |
print("frame r wriste:b_r_hand") | |
print("frame l wriste:b_l_hand") | |
print("frame l pinky tip:b_l_pinky_tip") | |
print("") | |
print("I need something to work with. Try using me like this:") | |
print("jm_bone_renamer.py translation_list.txt filename1.jma filename2.jms filename3.jmm") | |
fuck_you() | |
exit(1) | |
# Cut off the translation list arg, glob the given paths so windows users have it easier | |
args = args[1:] | |
files_to_process = [] | |
for file in args: | |
files_to_process += glob.glob(file) | |
# Convert the files in place | |
print("Processing these files:", args, "\n") | |
for filename in files_to_process: | |
print("#################################################") | |
print("Butchering", filename) | |
lines = [] | |
with open(filename, 'r+') as file: | |
lines = file.read().split("\n") | |
count = 0 | |
for line_i in range(len(lines)): | |
stripped_line = lines[line_i].strip() | |
lines[line_i] = stripped_line | |
new = translation_list.get(stripped_line, None) | |
if new is not None: | |
count += 1 | |
lines[line_i] = new.strip() | |
print("Renamed", count, "bones") | |
# Empty the file | |
file.seek(0) | |
file.truncate(0) | |
# Write new contents to the file | |
# We do \n here even though it should do \r\n. | |
# Universal newlines deals with this for us. | |
file.write(("\n".join(lines)+"\n")) | |
file.flush() | |
print("\nDone!") | |
except Exception as e: | |
fuck_you() | |
print(format_exc()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frame bone24:b_base | |
frame l upperarm:b_l_upperarm | |
frame r upperarm:b_r_upperarm | |
frame l forearm:b_l_forearm | |
frame r forearm:b_r_forearm | |
frame l wriste:b_l_hand | |
frame r wriste:b_r_hand | |
frame l index low:b_l_index_low | |
frame l middlelow:b_l_middle_low | |
frame l pinky low:b_l_pinky_low | |
frame l ring low:b_l_ring_low | |
frame l thumb low:b_l_thumb_low | |
frame r index low:b_r_index_low | |
frame r middle low:b_r_middle_low | |
frame r pinky low:b_r_pinky_low | |
frame r ring low:b_r_ring_low | |
frame r thumb low:b_r_thumb_low | |
frame l index mid:b_l_index_mid | |
frame l middle mid:b_l_middle_mid | |
frame l pinky mid:b_l_pinky_mid | |
frame l ring mid:b_l_ring_mid | |
frame l thumb mid:b_l_thumb_mid | |
frame r index mid:b_r_index_mid | |
frame r middle mid:b_r_middle_mid | |
frame r pinky mid:b_r_pinky_mid | |
frame r ring mid:b_r_ring_mid | |
frame r thumb mid:b_r_thumb_mid | |
frame l index tip:b_l_index_tip | |
frame l middle tip:b_l_middle_tip | |
frame l pinky tip:b_l_pinky_tip | |
frame l ring tip:b_l_ring_tip | |
frame l thumb tip:b_l_thumb_tip | |
frame r index tip:b_r_index_tip | |
frame r middle tip:b_r_middle_tip | |
frame r pinky tip:b_r_pinky_tip | |
frame r ring tip:b_r_ring_tip | |
frame r thumb tip:b_r_thumb_tip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment