Tested program as a module

This commit is contained in:
Timothy GFO 2023-09-15 12:53:53 -04:00
parent b52228eeb4
commit 7439c11168
4 changed files with 142 additions and 95 deletions

View file

@ -4,7 +4,7 @@ aliases = {
"level_name" : "1a",
"user_icon" : "4b",
"slide" : "1b",
"charge" : "1d",
"charge" : "1c",
"double_damage" : "1ba",
"proto_strike" : "1ca",
"double_jump" : "1bb",
@ -30,7 +30,16 @@ aliases = {
"weapon_slot_10" : "1k10",
"weapon_slot_11" : "1k11",
"level_music" : "1m",
"room_active" : "2a" #2aX,Y="1.000"
"room_active" : "2a", #2aX,Y="1.000"
"game_version" : "0v",
"charge_broom" : "1cc",
"dodge_roll" : "1cb",
"background_color" : "1e",
"boss_portrait" : "1f",
"boss_count" : "1bc",
"music" : "1m",
"track_id" : "1l",
"spike_subtype" : "l"
}
weapons = {
@ -91,8 +100,6 @@ supported_values = {
tile_names = {
"mm1cuttile" : '"3.000"'
}
block_with_coordinates = ["a", "k", "j", "i","e"]

View file

@ -7,8 +7,8 @@ It could also work by calling a function, say place_tile(tilename, x, y) and the
import configparser, os, definitions
section = "Level"
config = configparser.ConfigParser()
filename = "blank.mmlv"
config.read(filename) #this must be changed to support writing ONLY the changes when giving and argument in write_changes(), and not filename PLUS the changes. Todo: Enable Modifying of levels, not just creating.
#filename = "blank.mmlv"
#config.read(filename) #this must be changed to support writing ONLY the changes when giving and argument in write_changes(), and not filename PLUS the changes. Todo: Enable Modifying of levels, not just creating.
alias = definitions.aliases
supported_values = definitions.supported_values
max_x = 799
@ -16,7 +16,7 @@ max_y = 279
max_room_x = 49
max_room_y = 19
#done. converts from multiples of 16 to normal x and y values. for use in reading
# converts from multiples of 16 to normal x and y values. for use in reading
def conv_coordinates(x16, y16):
if x16 < 1 or y16 < 1:
x = x16 / 16
@ -32,16 +32,24 @@ def conv_coordinates_x16(x, y):
y16 = y * 16
return [x16, y16]
#adds apostrofes to the string
def set_apos(object):
apos = '"'+ str(object) + '"'
return apos
#done. writes the changes to file specified in global variable filename.
def write_changes(filename=filename):
def read_file(filename="blank.mmlv"):
config.read(filename)
def write_changes(filename="blank.mmlv"):
#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 letter in "srqp":
if letter == "q":
config.set(section,"1"+letter, '"12800"' )
config.set(section,"1"+letter, set_apos(12800) )
elif letter == "s":
config.set(section,"1"+letter, '"4480"' )
config.set(section,"1"+letter, set_apos(4480) )
else:
config.set(section,"1"+letter, '"0"')
config.set(section,"1"+letter, set_apos(0) )
with open(filename, 'w') as configfile:
config.write(configfile, space_around_delimiters=False)
@ -49,6 +57,7 @@ def write_changes(filename=filename):
def get_options():
options = config.options(section)
return options
#so far unneeded
def get_items():
items = config.items(section)
@ -65,6 +74,15 @@ def get_user():
current_username = config.get(section, alias["user_name"])
return current_username
def set_tile_value(k_value, j_value, i_value, e_value, a_value, posX_16, posY_16):
config.set(section,letter + posX_16 + "," + posY_16, k_value)
config.set(section,letter + posX_16 + "," + posY_16, j_value)
config.set(section,letter + posX_16 + "," + posY_16, i_value)
config.set(section,letter + posX_16 + "," + posY_16, e_value)
config.set(section,letter + posX_16 + "," + posY_16, a_value)
#Needs work for choosing specific version of tilename (subtypes?), other versions of tiles (e.g. mm1electile1), and it also needs optional automatic room activator.
def set_tile(x, y, tilename="mm1cuttile", block_type="normal", tile_subtype=False, room_active=1):
by16 = conv_coordinates_x16(x, y)
@ -73,13 +91,14 @@ def set_tile(x, y, tilename="mm1cuttile", block_type="normal", tile_subtype=Fals
#this needs a check to see if the coordinates are already taken, and deal with object-tile conflicts accordingly.
option = 0
error = False
for letter in "kjiea":
if letter == "k":
#unknown, so sample for now
#unknown, so sample for now. Related to tile sub type
#print("working k")
option = '"106.000"'
elif letter == "j":
#unknown
#unknown Related to tile subtype. maybe this and k are x and y? This is x, not y.
#print("working j")
option = '"71.000"'
elif letter == "i":
@ -92,10 +111,14 @@ def set_tile(x, y, tilename="mm1cuttile", block_type="normal", tile_subtype=Fals
option = '"1.000"'
elif letter == "e":
#supposedly this is item sub-type. Leaving default for now. Need to implement a method to have an index of all the tiles.
if tilename in definitions.tile_names:
option = definitions.tile_names[tilename]
else:
error = True
try:
tilename = int(tilename)
option = set_apos(tilename)
except ValueError:
if tilename in definitions.tile_names:
option = definitions.tile_names[tilename]
else:
error = True
#print("working e")
#option = '"3.000"'
else:
@ -108,7 +131,7 @@ def set_tile(x, y, tilename="mm1cuttile", block_type="normal", tile_subtype=Fals
return "error in " + str(letter)
def set_level_name(levelname):
config.set(section, alias["level_name"],'"' + levelname + '"')
config.set(section, alias["level_name"],set_apos(levelname))
def set_room_active(roomX, roomY,status=True): #the x and y values have to be the 0,0 relative to the room, so just the one where the tile on the top left corner of a room goes. I'll add this on set tile as a argument.
@ -141,46 +164,36 @@ def set_player(x, y,type="mm", allow_duplicates=0):
config.set(section,letter + x16 + "," + y16, option)
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]
return True
except KeyError:
return False
#this will optionally report WHAT is actually in there.
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)
#def set_object(object_name):
#def set_object(x, y, object_name, setting1):
# config.set(section, ) < I'll maybe add the set_player function here, because they are sort of objects. That way everything can be made through here.'
"""
def del_tile < this will erase the entry for the tile, not just disable it. Maybe optional disable.
< this will erase the entry for the tile, not just disable it. Maybe optional disable.
def list_tiles < this will return a list of tiles already on the level as a list each one with every of the 5 values for the 5 letters
def is_block_used < this will tell you what is on that coordinate
def default_blank < this is to give a blank canvas for every action. Maybe this will only be used for if a mmlv is blank (example: custom filename on write_changes())
def set_setting
def set_background
def set_active
"""
#def set_ver(gamever) < this may support mega maker's api to get current version.'
"""
_|_ _ __|_o._ _ _ .__ ._ _| _
|_(/__> |_|| |(_| (_||(_)|_|| |(_|_>
_| _|
"""
# A problem that has to be fixed some day is that EVERY TILE WILL NOT APPEAR ON EDITOR TILL A PLAY TEST. It has something to do with the 1s, 1q,1p and 1r entries. I set the max value that works but on MMLV Editor the value changes if a tile is more torward the top left. Maybe an algorithm is needed to count every tile from the level and update those values accordingly.
print(get_options())
print(get_user())
#set_user("Game FEverOnline")
set_level_name("sample")
set_user("Python")
count = 0
for column in range(max_y+1):
count += 1
for tile in range(max_x+1):
count += 1
set_tile(tile,column)
set_room_active(max_room_x,max_room_y)
print(count)
write_changes("sample.mmlv")

View file

@ -1,45 +1,45 @@
[Level]
2a12544,4256="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="4480.000"
1r="0.000"
1q="12800.000"
1p="0.000"
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"
4a="game fever online yt"
1a="sample"
0v="1.8.4.1"
0a="386743.000"
[Level]
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="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"
4a="python"
1a="sample"
0v="1.8.4.1"
0a="386743.000"

27
testing_grounds.py Normal file
View file

@ -0,0 +1,27 @@
# A Mega Man Maker MMLV Library/Module By Timothy J. (GameFeverOnline, www.youtube.com/@GameFeverOnline)
import mmlv_library as mmlv
"""
_|_ _ __|_o._ _ _ .__ ._ _| _
|_(/__> |_|| |(_| (_||(_)|_|| |(_|_>
_| _|
"""
mmlv.read_file()
print(mmlv.get_user())
mmlv.set_level_name("sample")
mmlv.set_user("Python")
count = 0
#for column in range(max_y+1):
# count += 1
#
# for tile in range(max_x+1):
# count += 1
# set_tile(tile,column)
#set_room_active(max_room_x,max_room_y)
#set_tile(1,1)
print(count)
mmlv.write_changes("sample.mmlv")
#del_tile(1,1)