diff --git a/README.md b/README.md index b438b8f..0758e47 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,11 @@ add automatic room activation to set_tile add ability to all functions to accept raw x, y values (the times 16 numbers in mmlv) and raw codes (like "a" instead of "active") complete set_tile, set_spike, set_ladder add set_enemy and set_boss -add way to figure out if there's a player (megaman, protoman etc...) in the file have integrated functions for changing/replacing the blocks that have some code in them with something else. add verifier for what a block contains, what type of *thing* (the block x, y contains an object, or the block 1, 5 contains an enemy object) ## Contributing -I would like to be the main developer of this project until it has some missing core functions and it reaches beta. After that feel free to leave pull requests for me to check. +I would like to be the main developer of this project until it has some missing core functions since I treat this as a learning project. However, feel free to notify me of any issues. Also, pull requests are welcome. ## License GNU General Public License v3.0 diff --git a/mmlv_library.py b/mmlv_library.py index 953cdd6..8afd80d 100644 --- a/mmlv_library.py +++ b/mmlv_library.py @@ -73,10 +73,24 @@ def get_user(): return current_username -def is_block_used(x, y, details=False): +def is_block_used(x, y, details=False, alt_algorithm=False): conv_list = conv_coordinates_x16(x, y) x = conv_list[0] y = conv_list[1] + + if alt_algorithm: + ans = False + config_dict = config[section] + print(type(config_dict)) + for key in config_dict: + if f"{x},{y}" in key: + ans = True + break + # else: + # ans = False + return ans + + for letter in definitions.block_with_coordinates: current = f"{letter}{x},{y}" if current in config[section]: @@ -109,9 +123,20 @@ def get_block_contents(x, y, full_scan=False): for letter in definitions.block_with_coordinates: current = f"{letter}{x},{y}" if current in config[section]: - result.append([current, config.get(section, current)]) + result.append({current : config.get(section, current)}) return result +def string_to_number(value): + try: + value = int(value) + except ValueError: + try: + value = float(value) + if value.is_integer(): + value = int(value) + except ValueError: + value = None + return value ###----------------------------------------------------------------------------------------------------------------### @@ -246,11 +271,24 @@ def del_tile(x,y,times_16=False): def set_player(x, y, player_type="mm",direction="right", allow_duplicates=False): by16 = conv_coordinates_x16(x, y) x16 = str(by16[0]) - y16 = str(by16[1]) #Every function that has something like all this should be a funcion. + y16 = str(by16[1]) if is_block_used(x, y): - #this should check if what is there is a player, if so then only replace the values? del_tile(x16, y16) + # checks if there is another "player" instance and deletes it + if allow_duplicates == False: + for dup_x in range(max_x+1): + for dup_y in range(max_y+1): + for letter in get_block_contents(dup_x,dup_y): + by16 = conv_coordinates_x16(dup_x, dup_y) + dup_x16 = str(by16[0]) + dup_y16 = str(by16[1]) + + if f"d{dup_x16},{dup_y16}" in letter: + value = letter[f"d{dup_x16},{dup_y16}"].strip('"') + value = string_to_number(value) + if value == 4: + del_tile(dup_x,dup_y) type_lookup = { "mm":{"1t":"0"}, @@ -273,6 +311,8 @@ def set_player(x, y, player_type="mm",direction="right", allow_duplicates=False) #this is needed because 1t doesn't have coordinate values in the key' if key == "1t": full_key = key + print("spawning player", full_key, value) + config.set(section,full_key, value) # inspected _____ frozen diff --git a/sample.mmlv b/sample.mmlv index b316da8..42e58af 100644 --- a/sample.mmlv +++ b/sample.mmlv @@ -1,30 +1,135 @@ -[Level] -1s=4480.0 -1r=0.0 -1q=12800.0 -1p=0.0 -1m=10.0 -1l=6.0 -1k0=0.0 -1bc=0.0 -1f=-1.0 -1e=29.0 -1d=6.0 -1cc=1.0 -1cb=1.0 -1bb=0.0 -1ca=0.0 -1ba=0.0 -1c=1.0 -1b=1.0 -4b=75.0 -4a="game fever online yt" -1a="sample" -0v="1.8.4.1" -0a=386743.0 -r16,16=2.0 -1t=1.0 -e16,16=1.0 -a16,16=1.0 -d16,16=4.0 - +; This level was NOT made in Py-MMLV but I'm testing to see if comments are allowed on the Mega Man Maker servers. I hope so because I'm trying to have a banner for levels made in py-mmlv. +[Level] +k3312,3040="106.000" +j3312,3040="88.000" +i3312,3040="1.000" +e3312,3040="699.000" +a3312,3040="1.000" +k3296,3040="106.000" +j3296,3040="36.000" +i3296,3040="1.000" +e3296,3040="699.000" +a3296,3040="1.000" +k3280,3040="106.000" +j3280,3040="53.000" +i3280,3040="1.000" +e3280,3040="699.000" +a3280,3040="1.000" +k3264,3040="106.000" +j3264,3040="36.000" +i3264,3040="1.000" +e3264,3040="699.000" +a3264,3040="1.000" +k3248,3040="106.000" +j3248,3040="53.000" +i3248,3040="1.000" +e3248,3040="699.000" +a3248,3040="1.000" +k3232,3040="106.000" +j3232,3040="36.000" +i3232,3040="1.000" +e3232,3040="699.000" +a3232,3040="1.000" +k3216,3040="106.000" +j3216,3040="53.000" +i3216,3040="1.000" +e3216,3040="699.000" +a3216,3040="1.000" +k3200,3040="106.000" +j3200,3040="36.000" +i3200,3040="1.000" +e3200,3040="699.000" +a3200,3040="1.000" +o3200,3024="9999.000" +e3200,3024="15.000" +d3200,3024="8.000" +a3200,3024="1.000" +k3184,3040="106.000" +j3184,3040="53.000" +i3184,3040="1.000" +e3184,3040="699.000" +a3184,3040="1.000" +1t="0.000" +o3184,3024="9999.000" +d3184,3024="4.000" +a3184,3024="1.000" +k3168,3040="106.000" +j3168,3040="36.000" +i3168,3040="1.000" +e3168,3040="699.000" +a3168,3040="1.000" +k3152,3040="106.000" +j3152,3040="53.000" +i3152,3040="1.000" +e3152,3040="699.000" +a3152,3040="1.000" +k3136,3040="106.000" +j3136,3040="36.000" +i3136,3040="1.000" +e3136,3040="699.000" +a3136,3040="1.000" +k3120,3040="106.000" +j3120,3040="53.000" +i3120,3040="1.000" +e3120,3040="699.000" +a3120,3040="1.000" +k3104,3040="106.000" +j3104,3040="36.000" +i3104,3040="1.000" +e3104,3040="699.000" +a3104,3040="1.000" +k3088,3040="106.000" +j3088,3040="53.000" +i3088,3040="1.000" +e3088,3040="699.000" +a3088,3040="1.000" +k3072,3040="106.000" +j3072,3040="1.000" +i3072,3040="1.000" +e3072,3040="699.000" +a3072,3040="1.000" +2d3072,2912="443.000" +2a3072,2912="1.000" +2b0,4256="0.000" +2b0,4032="0.000" +2b0,3808="0.000" +2b0,3584="0.000" +2b0,3360="0.000" +2b0,3136="0.000" +2b0,2912="0.000" +2b0,2688="0.000" +2b0,2464="0.000" +2b0,2240="0.000" +2b0,2016="0.000" +2b0,1792="0.000" +2b0,1568="0.000" +2b0,1344="0.000" +2b0,1120="0.000" +2b0,896="0.000" +2b0,672="0.000" +2b0,448="0.000" +2b0,224="0.000" +2b0,0="0.000" +1s="3072.000" +1r="3008.000" +1q="3344.000" +1p="3040.000" +1m="4.000" +1l="7.000" +1k0="0.000" +1bc="0.000" +1f="-1.000" +1e="29.000" +1d="6.000" +1cc="1.000" +1cb="1.000" +1bb="0.000" +1ca="0.000" +1ba="0.000" +1c="1.000" +1b="1.000" +4b="75.000" +4a="game fever online" +1a="MMLV-comment-test" +0v="1.8.5.2" +0a="386743.000" diff --git a/testing_grounds.py b/testing_grounds.py index 844ec5a..2919f9f 100644 --- a/testing_grounds.py +++ b/testing_grounds.py @@ -8,7 +8,7 @@ _|_ _ __|_o._ _ _ .__ ._ _| _ _| _| """ -mmlv.read_file() +mmlv.read_file("sample.mmlv") # # # print(mmlv.get_user()) # # @@ -20,23 +20,30 @@ mmlv.read_file() #print(mmlv.get_block_contents(1,2)) #print(mmlv.is_block_used(1,2)) -n = 1000 +n = mmlv.max_x * mmlv.max_y t0 = time.time() -# for i in range(n): mmlv.get_block_contents(1,2, True) -repeat = 0 -for x in range(mmlv.max_x+1): - for y in range(mmlv.max_y+1): - #if mmlv.is_block_used(x,y): - repeat = repeat + 1 - print(x,y) - mmlv.set_tile(x, y) - #print(mmlv.get_block_contents(x, y)) +for i in range(n): mmlv.is_block_used(0,0,details=False, alt_algorithm=False) +# repeat = 0 +# for x in range(mmlv.max_x+1): +# for y in range(mmlv.max_y+1): +# #if mmlv.is_block_used(x,y): +# repeat = repeat + 1 +# print(x,y) +# mmlv.set_tile(x, y) +# #print(mmlv.get_block_contents(x, y)) t1 = time.time() - +# total_n = t1-t0 print(total_n) -print(repeat) - -mmlv.write_changes("sample.mmlv") +n = mmlv.max_x * mmlv.max_y +t0 = time.time() +for i in range(n): mmlv.is_block_used(0,0,details=False, alt_algorithm=True) +t1 = time.time() +# +total_n = t1-t0 +print(total_n, "alt") +# print(repeat) +#mmlv.is_block_used(0,0,details=False,alt_algorithm=True) +#mmlv.write_changes("sample.mmlv") #del_tile(1,1)