## ACTIONS is the common basic moves ACTIONS = ['AVATAR', 'STAND', 'WALK', 'RUN', 'ROLL', 'SKY_ROLL', 'JUMP_START', 'JUMP', 'JUMP_LAND', 'JUMP_ATTACK', 'SOMERSAULT',\ 'SOMERSAULT2', 'BREAKFALL', 'LIE_TURN', 'RUN_STOP', 'DASH', 'DASH_AIR', 'DASH_BACK', 'DASH_AIR_BACK', 'DASH_ATTACK', 'KNEEL',\ 'HIT1', 'HIT2', 'HIT1_BACK', 'HIT2_BACK', 'HIT3', 'DIZZY', 'CAUGHT', 'CAUGHT_HIT', 'CAUGHT_STRUGGLE', 'FALL_HIT_WALL',\ 'FALL1', 'FALL2', 'FALL3', 'FALL4', 'FALL5', 'FALL6', 'LIE', 'LIE_HIT', 'FALL_BACK1', 'FALL_BACK2', 'FALL7', 'FALL8',\ 'FALL_SPIN1', 'FALL_SPIN2', 'FALL_SPIN3', 'BREAKGUARD', 'BREAKGUARD_SKY', '_GUA_STAND', '_GUA_WALK', '_GUA_RUN',\ '_GUA_JUMP_START', '_GUA_JUMP', '_GUA_DASH_BACK', '_CAT_STAND', '_CAT_HIT1', '_CAT_WALK', '_CAT_RUN', '_CAT_RUN_STOP',\ '_CAT_JUMP_START', '_CAT_JUMP', '_CAT_JUMP_LAND', '_HEA_JUMP_LAND', '_CAT_FORWARD_ATTACK', '_HEA_ATTACK1', '_CAT_JUMP_ATTACK',\ '_HEA_BREAKGUARD', '_CAT_ATTACK1', '_RID_STAND', '_RID_PULL', '_RID_GUARD', '_RID_GET_ON', '_RID_HIT1', '_RID_DIZZY',\ '_RID_BREAKGUARD', '_RID_DOWN_ATTACK', '_RID_BACK_ATTACK', '_RID_CATCH', '_RID_CATCH_ATTACK', '_RID_CATCH_FORWARD_ATTACK',\ 'FALL_ICE', 'FALL_FIRE', 'FALL_THUNDER'] ## 读入json from json import load, dumps print('Action Transplant Tool.') try: f = open('SptA.json') dictionary = load(f) f.close() f = open('SptB.json') dictionaryB = load(f) f.close() del f except: print("Way to use:\n") print("1.Unpack the json file in donor's Spt zip file, rename it as 'SptA.json', and place it in the same folder as this tool.") print("2.Unpack the json file in receptor's Spt zip file, rename it as 'SptB.json', and place it in the same folder as this tool.") print("3.Run this tool with python, operate with the tool's instruction. When finished, the output file 'Spt.json' can be found in thi folder.\n") print("[ hint ] If steps 1 and 2 are done right, you'll not see this sentence. If you didn't do steps 1 and 2, please close this window and do them. Then reopen this tool.") print('=========================================\n\n\n') print('Press ENTER to begin.') input() while True: ## data processing # action processing length = dictionary['Data.Spt']['action']['HFW_ArrayLenXXX'] # numbers of action action = dictionary['Data.Spt']['action'] actions1 = [action[str(i)]['name'] for i in range(length)] # action's name actionsA = [i for i in ACTIONS if i in actions1] # common actions actionsB = [j for j in actions1 if j not in actionsA] # special actions actionsType = [actionsA, actionsB] actIndex = {} # map name to the corresponding number for i in range(length): actIndex.update({actions1[i]: i}) # choose the action to add, found the range of related frames # choose the action's type print('-----------------------------------------') ii = -1 while ii not in {0, 1}: print("0: common action\n1: special action") print("Which type of action do you want to add? Enter the corresponding number: ") ii = int(input()) if ii not in {0, 1}: print("Please enter the right number.") else: break print('-----------------------------------------') actions = actionsType[ii] for i in range(len(actions)): print(str(i) + ": " + actions[i]) # choose the action ii = -1 iis = set([j for j in range(len(action))]) while ii not in iis: print("Which action do you want to add? Please enter the corresponding number: ") ii = int(input()) if ii not in iis: print("Please enter the right number.") else: break name = actions[ii] index = actIndex[name] # obtain the action's contents act_value = action[str(index)] # get the frame's range related to the action to add frameIndex = act_value['frameIndex'] start = int(frameIndex) # beginning frame frameNum = dictionary['Data.Spt']['frame']['HFW_ArrayLenXXX'] for i in range(int(frameIndex), int(frameNum)): if dictionary['Data.Spt']['frame'][str(i)]['last'] == True: end = i # ending frame break addNum = end - start + 1 # number of frames to copy # change the frames' number, index and refIndex according to the receptor's spt file's number of frames frameNumB = int(dictionaryB['Data.Spt']['frame']['HFW_ArrayLenXXX']) delta = int(frameNumB - start) # the amount the original index should be added for i in range(addNum): try: if dictionary['Data.Spt']['frame'][str(start + i)]['refIndex'] > 0: dictionary['Data.Spt']['frame'][str(start + i)]['refIndex'] += delta except: pass if len(dictionary['Data.Spt']['frame'][str(start + i)]['name']) > 0: dictionary['Data.Spt']['frame'][str(start + i)]['name'] += "_new" # add "_new" as the end of the new frame's name if it has one dictionary['Data.Spt']['frame'][str(start + i)]['index'] += delta dictionaryB['Data.Spt']['frame'].update({str(frameNumB + i): dictionary['Data.Spt']['frame'][str(start + i)]}) # add frames dictionaryB['Data.Spt']['frame']['HFW_ArrayLenXXX'] += addNum # update receptor's ArrayLength of frame # edit the wanted action's contents and add it to the receptor's actions act_value['frameIndex'] = float(frameNumB)# update the new action's frameIndex act_value['name'] += "_NEW" # add "_NEW" to the end of the new action's name actionNumB = int(dictionaryB['Data.Spt']['action']['HFW_ArrayLenXXX']) act_value['index'] = actionNumB # update the new action's index dictionaryB['Data.Spt']['action'].update({str(actionNumB): act_value}) # add the action dictionaryB['Data.Spt']['action']['HFW_ArrayLenXXX'] += 1 # update the ArrayLength of receptor's actions # set k, kr, agi, ati, ai, whether allow using when facing the other direction, consumption of hp and mp print('-----------------------------------------') ii = 0 while ii != 1: mHp = int(dictionaryB['Data.Spt']['mHp']) mMp = int(dictionaryB['Data.Spt']['mMp']) print("set the action's hp consumption as: (Enter an integer from 0 to {0})".format(mHp)) hp = float(input()) print("set the action's mp consumption as: (Enter an integer from 0 to {0})".format(mMp)) mp = float(input()) print('-----------------------------------------') print("set the key for action towards right as :(Enter as least one key)") print("Only seven letter is useful: u(up), d(down), l(left), r(right), a(attack), j(jump), g(guard)") k = input() print("set the key for action towards left as :(Enter as least one key with the same number of letters as for right)") kr = input() kl = float(len(kr)) print("whether to make the action active when facing the other direction\n0: NO\n1: YES") atfii = input() if atfii == '1': atf = True elif atfii == '0': atf = False else: ii = 0 if hp % 1 == 0 and 0 <= hp <= mHp and mp % 1 == 0 and 0 <= mp <= mMp and len(k) == len(kr): ii = 1 break if ii == 0: print("Please input properly - -") # set the pre-actions print('-----------------------------------------') for j in range(actionNumB): print(str(j) + ": " + dictionaryB['Data.Spt']['action'][str(j)]['name']) print("Enter the number(s), and then the transplanted action can be done after your choosen action(s)" + "\nIf there are multiple numbers, seperate them with space(' ')" * 3) targets = input().split() for t in targets: # for each pre-action: # update actionGroup agi = 0 if 'RID' in dictionaryB['Data.Spt']['action'][t]['name']: agi = 4 try: ai = dictionaryB['Data.Spt']['actionGroup'][str(agi)]['actionIndex']['3']['HFW_ArrayLenXXX'] for i in range(ai): if dictionaryB['Data.Spt']['actionGroup'][str(agi)]['actionIndex']['3'][str(i)] == actionNumB: ai = i dictionaryB['Data.Spt']['actionGroup'][str(agi)]['actionIndex']['3']['HFW_ArrayLenXXX'] -= 1 break except: dictionaryB['Data.Spt']['actionGroup'][str(agi)]['actionIndex']['3']['HFW_ArrayLenXXX'] = 0 ai = 0 dictionaryB['Data.Spt']['actionGroup'][str(agi)]['actionIndex']['3']['HFW_ArrayLenXXX'] += 1 dictionaryB['Data.Spt']['actionGroup'][str(agi)]['actionIndex']['3'].update({str(ai): float(actionNumB)}) try: ki = dictionaryB['Data.Spt']['action'][t]['a_keyTgr']['HFW_ArrayLenXXX'] except: dictionaryB['Data.Spt']['action'][t]['a_keyTgr'] = {'HFW_ArrayLenXXX': 0} ki = 0.0 new = {'HFW_classNameXXX': 'Data.A_KeyTgr', 'kl': kl, 'ati': 3.0, 'pollhp': 0.0, 'agi': float(agi),\ 'atf': atf, 'ai': float(ai), 'k': k, 'hp': hp, 'rkt': False, 'mp': mp, 'kr': kr} dictionaryB['Data.Spt']['action'][t]['a_keyTgr'].update({str(int(ki)): new}) # update the triggering key dictionaryB['Data.Spt']['action'][t]['a_keyTgr']['HFW_ArrayLenXXX'] += 1 # loop print('-----------------------------------------') print('Edit complete. What do you want to do next:') print('0: quit and save the changes\n1: continue to do another edit') ex = input() if ex == '0': break ## output json f = open('Spt.json', 'w+') s = dumps(dictionaryB, indent=4) f.write(s) f.close() print('-----------------------------------------') input('press ENTER to quit.')