mirror of
https://gitlab.com/GameFeverOnline/py-mmlv.git
synced 2025-12-17 17:27:42 -04:00
completed set_player
This commit is contained in:
parent
45b6344f28
commit
07a393b9b7
5 changed files with 135 additions and 84 deletions
|
|
@ -9,6 +9,7 @@ This includes:
|
|||
* Every function that spawns something in the level should have intuitive naming and arguments.
|
||||
* A stable base to improve upon: Every function will lookup in the definitions.py file.
|
||||
* Be able to generate from scratch a valid mmlv file, as well as modifying a file (valid or not).
|
||||
* It should also be able to FIX corrupted Mega Man Maker Levels, at least attempt to.
|
||||
|
||||
## Installation
|
||||
Dependencies:
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ aliases = {
|
|||
"spike_subtype" : "l",
|
||||
"object_type" : "d",
|
||||
"bg" : "2d",
|
||||
"lava_status" : "q"
|
||||
"lava_status" : "q",
|
||||
"mistery":"1t" # REMEMBER THIS
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -110,7 +111,7 @@ object_names = {
|
|||
background_names = {
|
||||
"cut" : "115"
|
||||
}
|
||||
block_with_coordinates = ["a", "k", "j", "i","e", "o", "d", "q"]
|
||||
block_with_coordinates = ["a", "k", "j", "i","e", "o", "d", "q", "r", ]
|
||||
tile_identifiers = [["a", "enable"], ["k", "sub_type"], "j", "i","e"]
|
||||
spike_identifiers = [["l", "direction"],"i","e","a"]
|
||||
spike_direction = [["1" ,"point_down"], ["0", "point_up"], ["2", "point_left"], ["3", "point_right"], ["4", "center"]]
|
||||
|
|
|
|||
129
mmlv_library.py
129
mmlv_library.py
|
|
@ -8,6 +8,7 @@ It could also work by calling a function, say place_tile(tilename, x, y) and the
|
|||
try:
|
||||
import configparser, os, definitions
|
||||
import requests
|
||||
import csv
|
||||
except ModuleNotFoundError:
|
||||
print("module not found, please install configparser, requests, os and have the definitions.py in the same folder as mmlv_library.py")
|
||||
Exception(ModuleNotFoundError)
|
||||
|
|
@ -15,6 +16,7 @@ except ModuleNotFoundError:
|
|||
### init global variables
|
||||
section = "Level"
|
||||
config = configparser.ConfigParser()
|
||||
safe_config = configparser.SafeConfigParser()
|
||||
alias = definitions.aliases
|
||||
max_x = 799
|
||||
max_y = 279
|
||||
|
|
@ -64,78 +66,91 @@ def get_items():
|
|||
items = config.items(section)
|
||||
return items
|
||||
|
||||
#done. Not tested
|
||||
#done.
|
||||
def get_user():
|
||||
if config.has_option(section, alias["user_name"]):
|
||||
current_username = config.get(section, alias["user_name"])
|
||||
return current_username
|
||||
|
||||
# IS NOT WORKING NEEDS OPTIMIZATION
|
||||
|
||||
def is_block_used(x, y, details=False):
|
||||
conv_list = conv_coordinates_x16(x, y)
|
||||
x = conv_list[0]
|
||||
y = conv_list[1]
|
||||
for letter in definitions.block_with_coordinates:
|
||||
current = letter + str(x) + "," + str(y)
|
||||
try:
|
||||
answ_option = config[section][current]
|
||||
current = f"{letter}{x},{y}"
|
||||
if current in config[section]:
|
||||
return True
|
||||
except KeyError:
|
||||
else:
|
||||
return False
|
||||
|
||||
#todo: filter list before doing anything, And SPEED IT UP! (maybe by using this algorithm in the "is block used" or just using the "for letter in definitions.block_with_coordinates. maybe by using a full_scan=True)
|
||||
def get_block_contents(x, y, full_scan=True):
|
||||
#todo: filter list before doing anything
|
||||
def get_block_contents(x, y, full_scan=False):
|
||||
conv_list = conv_coordinates_x16(x, y)
|
||||
x = conv_list[0]
|
||||
y = conv_list[1]
|
||||
result = []
|
||||
if full_scan and True:
|
||||
if full_scan:
|
||||
coordinates = f"{x},{y}"
|
||||
options = get_options()
|
||||
#print(options)
|
||||
for key in options:
|
||||
#print(key.endswith(coordinates))
|
||||
if key.endswith(coordinates):
|
||||
index = key.find(coordinates)
|
||||
#print("index", index)
|
||||
|
||||
for key in options: #for every key in the file
|
||||
if key.endswith(coordinates): #if each key ends with the correct coordinates
|
||||
index = key.find(coordinates)
|
||||
for character in key:
|
||||
if character.isdigit():
|
||||
test = key.find(character)
|
||||
#print("character", character)
|
||||
if index != test:
|
||||
break
|
||||
|
||||
result.append([key,config.get(section, key)])
|
||||
# else:
|
||||
# for letter in definitions.block_with_coordinates:
|
||||
# current = f"{letter}{x},{y}"
|
||||
# try:
|
||||
# result.append([current,config[section,current]])
|
||||
# except KeyError:
|
||||
# print("skipping")
|
||||
|
||||
|
||||
else:
|
||||
#same logic as is_block_used
|
||||
for letter in definitions.block_with_coordinates:
|
||||
current = f"{letter}{x},{y}"
|
||||
if current in config[section]:
|
||||
result.append([current, config.get(section, current)])
|
||||
return result
|
||||
|
||||
|
||||
|
||||
#print(key)
|
||||
# if coordinates in key:
|
||||
# print(key)
|
||||
|
||||
#config.get(section, f"{}")
|
||||
|
||||
|
||||
###----------------------------------------------------------------------------------------------------------------###
|
||||
|
||||
def set_values(key, x="", y="", value=""):
|
||||
if value != "":
|
||||
value = str(value)
|
||||
keys_with_string_values = ("4a", "1a", "0v")
|
||||
if key in value:
|
||||
value = set_apos(value)
|
||||
config[section][f"{key}{x},{y}"] = value
|
||||
else:
|
||||
Exception("no value specified in set_values. that is ironic.")
|
||||
|
||||
|
||||
#def check_overlap(x,y):
|
||||
|
||||
def write_changes(filename="sample.mmlv"):
|
||||
|
||||
## frozen
|
||||
def optimize_mmlv(verbose=False):
|
||||
for key in config[section]:
|
||||
value_string = config[section][key]
|
||||
try:
|
||||
value = float(value_string.replace('"', ""))
|
||||
floatified = float(value)
|
||||
config[section][key] = str(floatified)
|
||||
except ValueError:
|
||||
if verbose == True:
|
||||
print("this was a float or a string",value_string)
|
||||
else:
|
||||
continue
|
||||
|
||||
def write_changes(filename="sample.mmlv", optimize_enable=True):
|
||||
#Well well well... this for loop is here to make every thing work. I'm not sure for what the 1s, 1q,1r and 1p keys are, but if they are the same as a blank mmlv created by mmm, it just doesn't work. It's weird.'
|
||||
|
||||
for key,value in zip("srqp", [set_apos(4480), set_apos(0), set_apos(12800), set_apos(0)]):
|
||||
config.set(section,f"1{key}", value)
|
||||
|
||||
optimize_mmlv()
|
||||
|
||||
with open(filename, 'w') as configfile:
|
||||
config.write(configfile, space_around_delimiters=False)
|
||||
|
||||
|
|
@ -217,18 +232,47 @@ def set_room_active(roomX, roomY,status=True, quadrant="IV"):
|
|||
code = alias["room_active"]
|
||||
config.set(section,f"{code}{roomX},{roomY}", status)
|
||||
|
||||
# inspected _____ frozen
|
||||
def del_tile(x,y,times_16=False):
|
||||
if not times_16:
|
||||
by16 = conv_coordinates_x16(x, y)
|
||||
x = str(by16[0])
|
||||
y = str(by16[1])
|
||||
|
||||
def set_player(x, y,type="mm", allow_duplicates=0):
|
||||
for letter in definitions.block_with_coordinates:
|
||||
current = f"{letter}{x},{y}
|
||||
config.remove_option(section, current)
|
||||
|
||||
### should check if there is another "1t" (and maybe "r" and "e" idk) and delete everything on that tile.
|
||||
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.
|
||||
for key,value in zip("oda", ['"9999"', '"4"', '"1"']):
|
||||
config.set(section,key + x16 + "," + y16, value)
|
||||
# inspected _____ frozen
|
||||
def del_tile(x,y,disable=False):
|
||||
for letter in definitions.block_with_coordinates:
|
||||
current = letter + str(x) + ',' + str(y)
|
||||
config.remove_option(section, current)
|
||||
|
||||
if is_block_used(x, y):
|
||||
del_tile(x16, y16)
|
||||
|
||||
type_lookup = {
|
||||
"mm":{"1t":"0"},
|
||||
"pm":{"r":"2","1t":"1","e":"1"},
|
||||
"b":{"r":"3", "1t":"2","e":"2"},
|
||||
"r":{"r":"4", "1t":"3","e":"3"}
|
||||
}
|
||||
|
||||
a = "1"
|
||||
d = "4"
|
||||
|
||||
player_dictionary = type_lookup[player_type]
|
||||
player_dictionary["a"] = "1"
|
||||
player_dictionary["d"] = "4"
|
||||
|
||||
for key in player_dictionary:
|
||||
value = player_dictionary[key]
|
||||
full_key = f"{key}{x16},{y16}"
|
||||
if key == "1t":
|
||||
full_key = key
|
||||
config.set(section,full_key, value)
|
||||
|
||||
# inspected _____ frozen
|
||||
#sets version variable in mmlv file. If 'version' argument is False it will reach for MMM's api to get current version.'
|
||||
def set_ver(version=False):
|
||||
|
|
@ -262,6 +306,7 @@ def disconnect_screen(h_or_v, x, y):
|
|||
else:
|
||||
config.remove_option(section, f"2c{x},{y}")
|
||||
|
||||
|
||||
def set_object(x, y, object_name="energy_element", setting="9999", object_type="8"):
|
||||
by16 = conv_coordinates_x16(x, y)
|
||||
x16 = str(by16[0])
|
||||
|
|
|
|||
61
sample.mmlv
61
sample.mmlv
|
|
@ -1,39 +1,30 @@
|
|||
[Level]
|
||||
k16,16="71.000"
|
||||
j16,16="141.000"
|
||||
i16,16="1.000"
|
||||
e16,16="3.000"
|
||||
a16,16="1.000"
|
||||
k0,0="71.000"
|
||||
j0,0="71.000"
|
||||
i0,0="1.000"
|
||||
e0,0="3.000"
|
||||
a0,0="1.000"
|
||||
2c512,224="1.000"
|
||||
2d256,4256="115.000"
|
||||
2d0,0="115.000"
|
||||
2a0,0="1.000"
|
||||
1s="4480"
|
||||
1r="0"
|
||||
1q="12800"
|
||||
1p="0"
|
||||
1m="10.000"
|
||||
1l="6.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"
|
||||
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.5.2"
|
||||
0a="386743.000"
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# A Mega Man Maker MMLV Library/Module By Timothy J. (GameFeverOnline, www.youtube.com/@GameFeverOnline)
|
||||
import mmlv_library as mmlv
|
||||
|
||||
import time
|
||||
|
||||
"""
|
||||
_|_ _ __|_o._ _ _ .__ ._ _| _
|
||||
|
|
@ -8,7 +8,7 @@ _|_ _ __|_o._ _ _ .__ ._ _| _
|
|||
_| _|
|
||||
"""
|
||||
|
||||
mmlv.read_file("4 hour level PyMMLV.mmlv")
|
||||
mmlv.read_file()
|
||||
#
|
||||
# # print(mmlv.get_user())
|
||||
# #
|
||||
|
|
@ -16,9 +16,22 @@ mmlv.read_file("4 hour level PyMMLV.mmlv")
|
|||
# # mmlv.set_user("Python")
|
||||
# # print(count)
|
||||
# # mmlv.connect_screen("v", 2, 1)
|
||||
# # mmlv.set_background(0,0, 115)
|
||||
# # mmlv.set_background(1,mmlv.max_room_y, "cut")
|
||||
print(mmlv.get_block_contents(1,2))
|
||||
# #mmlv.write_changes("sample.mmlv")
|
||||
#print(mmlv.get_block_contents(1,2))
|
||||
#print(mmlv.is_block_used(1,2))
|
||||
|
||||
# n = 1000
|
||||
# t0 = time.time()
|
||||
# # for i in range(n): mmlv.get_block_contents(1,2, True)
|
||||
# for x in range(mmlv.max_x+1):
|
||||
# for y in range(mmlv.max_y+1):
|
||||
# if mmlv.is_block_used(x,y):
|
||||
# print(mmlv.get_block_contents(x, y))
|
||||
# t1 = time.time()
|
||||
#
|
||||
# total_n = t1-t0
|
||||
# print(total_n)
|
||||
mmlv.set_player(1,1, player_type="pm")
|
||||
mmlv.write_changes("sample.mmlv")
|
||||
#del_tile(1,1)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue