improvements

This commit is contained in:
Timothy GFO 2023-10-25 21:00:31 -04:00
parent 85c21c2ec5
commit 723f8afe49
4 changed files with 202 additions and 51 deletions

View file

@ -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