Compare commits

...

23 Commits

Author SHA1 Message Date
Shadow15510 bb382622bc Merge branch 'dev' 2023-01-05 15:51:55 +01:00
Shadow15510 28d9eb5231 Minor fix 2023-01-05 15:26:10 +01:00
Shadow15510 77d99659a9 Merge branch 'dev' 2022-12-20 11:32:48 +01:00
Shadow15510 f2c74bbea5 Minor modification on the gestion of the screen's size 2022-12-20 11:27:59 +01:00
Shadow15510 1b0a3a3500 Merge branch 'dev' 2022-12-11 23:15:57 +01:00
Shadow15510 a2e02f3030 Update README 2022-07-16 11:11:31 +02:00
Shadow15510 a42aceeeab Merge branch 'dev' 2022-07-15 22:40:06 +02:00
Shadow15510 af27d031be Enhance behavior gestion 2022-07-15 22:33:57 +02:00
Shadow15510 bf7bad73b7 Revision of 'follow' behavior 2022-07-13 10:30:16 +02:00
Shadow15510 2d670448b2 Fix deadlock with 'follow' 2022-07-12 12:58:21 +02:00
Shadow15510 a8e0d374ac Merge branch 'dev' 2022-07-12 11:05:59 +02:00
Shadow15510 3ad286dd5a Add some extra functions 2022-07-12 11:00:46 +02:00
Shadow15510 088c29a6e3 Add customisable screen size 2022-04-18 12:07:51 +02:00
Shadow15510 0fb38d9fd7 Add a customisable low bar 2022-04-17 22:24:07 +02:00
Shadow15510 7a3388fa76 Add a customisable low bar 2022-04-17 22:16:46 +02:00
Shadow15510 d4af0f34f1 Merge branch 'dev' 2022-02-28 14:40:34 +01:00
Shadow15510 1e26a80982 Add some new animations 2022-02-28 14:39:18 +01:00
Shadow15510 377be90983 Merge branch 'dev' 2022-02-27 13:54:17 +01:00
Shadow15510 b74816619b Fix version 2022-02-27 13:53:49 +01:00
Shadow15510 ced6c831d3 Merge branch 'dev' 2022-02-27 13:43:57 +01:00
Shadow15510 1984d7ce6c Improve new entity gestion 2022-02-27 11:58:37 +01:00
Shadow15510 8eb6ff15cc Merge branch 'dev' 2022-02-27 09:58:40 +01:00
Shadow15510 02c7af8007 Changes on entities gestion 2022-02-27 09:38:05 +01:00
9 changed files with 299 additions and 125 deletions

View File

@ -18,7 +18,7 @@ Tout le projet est soumis à la licence GNU General Public Licence v3.0.
### Utilisation
Tout est détaillé dans [le wiki du projet](https://gitea.planet-casio.com/Shadow15510/Asci/wiki/Cr%C3%A9ation-d%27un-jeu-de-r%C3%B4le-avec-Asci).
Tout est détaillé dans [le wiki du projet](https://gitea.planet-casio.com/Shadow15510/Asci/wiki/Home).
### Exemples

251
asci.py
View File

@ -1,22 +1,36 @@
# Asci (1.7.2)
# Asci (1.9.3)
from math import floor, ceil
SCREEN_WIDTH = 21
SCREEN_HEIGHT = 7
class Asci:
def __init__(self, maps, events_mapping, keys_mapping, behaviors=None, screen_width=21, screen_height=6):
# Load maps
def __init__(self, maps, entities, events_mapping, keys_mapping, behaviors=None):
# Load maps and entities
self.maps = [Map(*i) for i in maps]
self.entities = {}
entity_id = 0
for i in entities:
if not i[0]:
i[0] = entity_id
entity_id += 1
if i[0] in self.entities: raise KeyError("'{}' is already a registered entities".format(i[0]))
else: self.entities[i[0]] = Entity(*i)
# Custom functions
self._legend = list(events_mapping.keys())
self._game_events_mapping = [events_mapping[i] for i in self._legend]
self._game_keys_mapping = {key: keys_mapping[key] for key in keys_mapping if not key in (1, 2, 3, 5)}
# Custom entities behavior
self._behaviors = {"permanent": permanent, "stand by": stand_by, "follow": follow, "walk": walk}
self._behaviors = {"permanent": permanent, "stand by": stand_by, "follow": follow, "walk between": walk_between, "walk to": walk_to, "follow by player": follow_by_player}
if behaviors:
for i in behaviors: self._behaviors[i] = behaviors[i]
# Screen initialisation
self.screen = Screen(screen_width, screen_height)
self.screen = Screen()
self.current_map = None
def _looked_case(self, direction):
@ -89,18 +103,18 @@ class Asci:
return self.data[1], self.data[2], self.data[3]
def _change_map(self, new_map):
# Update entities
if self.current_map:
for i in self.current_map.entities.copy():
entity = self.current_map.entities[i]
if entity.behavior == "follow":
entity.pos_x = entity.pos_y = -1
self.maps[new_map].entities[entity.entity_id] = entity
self.maps[self.data[1]].entities.pop(i)
# Update current map
self.data[1] = new_map
# Update map id and data
old_map, self.data[1] = self.data[1], new_map
self.current_map = self.maps[self.data[1]]
self.current_map.entities = {}
# Update entities
for i in self.entities:
entity = self.entities[i]
if entity.map_id == old_map and entity.behavior == "follow":
entity.pos_x = entity.pos_y = -1
entity.map_id = new_map
if entity.map_id == new_map: self.current_map.entities[i] = entity
# Update screen configuration
self.screen.set_world(self.current_map.map_data)
@ -146,7 +160,7 @@ class Asci:
return entity.entity_id
# Mainloop
def mainloop(self, end_game, stat=None, data=None, routine=None, player="@", door="^", walkable=" ", exit_key=9, multi_move="."):
def mainloop(self, end_game, stat=None, data=None, routine=None, low_bar=None, player="@", door="^", walkable=" ", exit_key=9, multi_move="."):
if exit_key in self._game_keys_mapping:
raise ValueError("'{}' is already assigned to a function.".format(exit_key))
@ -160,7 +174,7 @@ class Asci:
# Configuration
self._legend.append(door)
self._legend.append(walkable)
self._change_map(data[1])
self._change_map(self.data[1])
self.screen.load_data(self.data)
key = 0
@ -173,13 +187,15 @@ class Asci:
data_copy = self.data[:]
for entity in self.current_map.entities.values():
self._behaviors[entity.behavior](entity, data_copy, self.stat, self.screen, walkable)
if (0 <= entity.pos_x - self.data[2] + 10 < self.screen.screen_width) and (0 <= entity.pos_y - self.data[3] + 3 < self.screen.screen_height):
if entity.map_id == self.data[1] and (0 <= entity.pos_x - self.data[2] + self.screen.pos_player[0] < SCREEN_WIDTH) and (0 <= entity.pos_y - self.data[3] + self.screen.pos_player[1] < SCREEN_HEIGHT):
self.screen.set_cell(entity.pos_x, entity.pos_y, entity.symbol)
self.screen.set_cell(self.data[2], self.data[3], player)
# Display map, get the key and update key buffer
key = convert(self.screen.display())
# Display map, low bar, get the key and update key buffer
if low_bar: bar = low_bar(self.data[:], self.stat[:])
else: bar = None
key = convert(self.screen.display(low_bar=bar))
if not key: key = self.data[4]
else: self.data[4] = key
@ -206,11 +222,10 @@ class Asci:
# Classes used by Asci
class Screen:
def __init__(self, screen_width=21, screen_height=6):
def __init__(self):
# Screen configuration
self.screen_width = screen_width
self.screen_height = screen_height
self._on_screen = [[" " for _ in range(screen_width)] for _ in range(screen_height)]
self.pos_player = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)
self._on_screen = [[" " for _ in range(SCREEN_WIDTH)] for _ in range(SCREEN_HEIGHT)]
self._asci_data = []
def load_data(self, data):
@ -225,23 +240,27 @@ class Screen:
self.map_height = len(self._world)
def set_screen(self):
x = self._asci_data[2] - 10 ; y = self._asci_data[3] - 3
for x_map in range(x, x + self.screen_width):
for y_map in range(y, y + self.screen_height):
x = self._asci_data[2] - self.pos_player[0] ; y = self._asci_data[3] - self.pos_player[1]
for x_map in range(x, x + SCREEN_WIDTH):
for y_map in range(y, y + SCREEN_HEIGHT):
self._on_screen[y_map - y][x_map - x] = " "
if 0 <= x_map < self.map_width and 0 <= y_map < self.map_height:
try: self._on_screen[y_map - y][x_map - x] = self._world[y_map][x_map]
except: pass
def display(self, return_input=True):
for line in self._on_screen:
print("".join(line))
if return_input: return input(">")
def display(self, return_input=True, low_bar=None):
for line_no in range(len(self._on_screen)):
line = "".join(self._on_screen[line_no])
if line_no + 1 == SCREEN_HEIGHT and return_input:
if not low_bar: line = line[:-6] + ">"
else: line = low_bar + ">"
print(line, end="")
return input()
else:
print(line)
def clear(self):
print("\n" * self.screen_height)
print("\n" * SCREEN_HEIGHT)
def display_text(self, string):
paragraphs = [i for i in text_formater(string) if i]
@ -253,18 +272,19 @@ class Screen:
else: input()
def set_cell(self, x, y, value):
x = x - (self._asci_data[2] - 10)
y = y - (self._asci_data[3] - 3)
if 0 <= x < self.screen_width and 0 <= y < self.screen_height:
x = x - (self._asci_data[2] - self.pos_player[0])
y = y - (self._asci_data[3] - self.pos_player[1])
if 0 <= x < SCREEN_WIDTH and 0 <= y < SCREEN_HEIGHT:
self._on_screen[y][x] = value
def get_cell(self, x, y):
x = x - (self._asci_data[2] - 10)
y = y - (self._asci_data[3] - 3)
if 0 <= x < self.screen_width and 0 <= y < self.screen_height:
x = x - (self._asci_data[2] - self.pos_player[0])
y = y - (self._asci_data[3] - self.pos_player[1])
if 0 <= x < SCREEN_WIDTH and 0 <= y < SCREEN_HEIGHT:
return self._on_screen[y][x]
else: return " "
class Event:
def __init__(self, xp, text, answer=0, *stat):
self.xp = xp
@ -274,23 +294,29 @@ class Event:
class Map:
def __init__(self, map_data, entities, *coords):
def __init__(self, map_data, *coords):
self.map_data = map_data
if entities: self.entities = {i[0]: Entity(*i) for i in entities}
else: self.entities = {}
self.coords = coords
self.entities = {}
class Entity:
def __init__(self, entity_id, symbol, x, y, behavior, *args):
def __init__(self, entity_id, symbol, map_id, x, y, behavior, *args):
self.entity_id = entity_id
self.symbol = symbol
self.map_id = map_id
self.pos_x = x
self.pos_y = y
self.behavior = behavior
self.args = list(args)
def change_behavior(self, new_behavior):
if self.behavior != "permanent": self.behavior = new_behavior
def change_behavior(self, new_behavior, *args):
if self.behavior != "permanent":
self.behavior = new_behavior
self.args = list(args)
def teleport(self, map_id, x, y):
if self.behavior != "permanent": self.map_id, self.pos_x, self.pos_y = map_id, x, y
# Functions used by Asci
@ -301,34 +327,35 @@ def convert(string, force_int=False):
else: return string
def text_formater(string, screen_width=21, screen_height=6):
def text_formater(string):
screen_displayable_height = SCREEN_HEIGHT - 1
def line_formater(string, screen_width):
def line_formater(string):
string_result = ""
while len(string) > screen_width:
stop_index = screen_width
while len(string) > SCREEN_WIDTH:
stop_index = SCREEN_WIDTH
while stop_index > 0 and not string[stop_index].isspace(): stop_index -= 1
if not stop_index: stop_index = screen_width
if not stop_index: stop_index = SCREEN_WIDTH
string_result += string[:stop_index].strip() + "\n"
string = string[stop_index:].strip()
return string_result + string
def paragraph_formater(lines, screen_height):
def paragraph_formater(lines):
paragraphs = ""
while len(lines) >= screen_height:
paragraphs += "\n".join(lines[:screen_height]) + "\n\n"
lines = lines[screen_height:]
while len(lines) >= screen_displayable_height:
paragraphs += "\n".join(lines[:screen_displayable_height]) + "\n\n"
lines = lines[screen_displayable_height:]
return paragraphs + "\n".join(lines)
lines = []
for line in string.split("\n"):
for formated_line in line_formater(line, screen_width).split("\n"):
for formated_line in line_formater(line).split("\n"):
lines.append(formated_line)
return paragraph_formater(lines, screen_height).split("\n\n")
return paragraph_formater(lines).split("\n\n")
def read_event(data, event, quest):
@ -365,6 +392,87 @@ def get_multi_move(key):
return [(convert(k), 1) for k in key]
# Motions functions
def stand_by(entity, data, stat, screen, walkable):
pass
def permanent(entity, data, stat, screen, walkable):
pass
def follow(entity, data, stat, screen, walkable):
if entity.pos_x == entity.pos_y == -1:
entity.pos_x, entity.pos_y = data[2], data[3]
elif data[4] in (1, 2, 3, 5):
direction = (data[4] - 1) if data[4] != 5 else 3
if entity.args: walkable += entity.args[0]
cases = [(data[2] + 1, data[3]), (data[2], data[3] - 1), (data[2] - 1, data[3]), (data[2], data[3] + 1)]
pos = cases[direction]
if not (0 <= pos[0] < screen.map_width and 0 <= pos[1] < screen.map_height) or (not screen.get_cell(pos[0], pos[1]) in walkable):
find = False
cases.remove(cases[(direction + 2) % 4])
for pos in cases:
if (0 <= pos[0] < screen.map_width and 0 <= pos[1] < screen.map_height) and (screen.get_cell(pos[0], pos[1]) in walkable):
find = True
entity.pos_x, entity.pos_y = pos
break
if not find:
entity.pos_x, entity.pos_y = data[2], data[3]
else:
entity.pos_x, entity.pos_y = pos
def walk_between(entity, data, stat, screen, walkable):
frame = (entity.args[0] + 1) % len(entity.args[1])
new_x, new_y = _walk_engine(entity, frame)
if screen.get_cell(new_x, new_y) in walkable:
entity.pos_x, entity.pos_y = new_x, new_y
if (entity.pos_x, entity.pos_y) == entity.args[1][frame]: entity.args[0] = frame
def walk_to(entity, data, stat, screen, walkable):
frame = entity.args[0]
print(frame, len(entity.args[1]), entity.args)
if len(entity.args[1]) == frame:
entity.behavior = "stand by"
entity.args = []
return
new_x, new_y = _walk_engine(entity, frame)
if screen.get_cell(new_x, new_y) in walkable:
entity.pos_x, entity.pos_y = new_x, new_y
if (entity.pos_x, entity.pos_y) == entity.args[1][frame]: entity.args[0] += 1
def follow_by_player(entity, data, stat, screen, walkable):
frame = entity.args[0]
if len(entity.args[1]) == frame:
entity.behavior = "stand by"
entity.args = []
return
new_x, new_y = _walk_engine(entity, frame)
if abs(data[2] - new_x) < 5 and abs(data[3] - new_y) < 3 and screen.get_cell(new_x, new_y) in walkable:
entity.pos_x, entity.pos_y = new_x, new_y
if (new_x, new_y) == entity.args[1][frame]: entity.args[0] += 1
def _walk_engine(entity, frame):
delta_x, delta_y = list(map(lambda x,y: y - x, (entity.pos_x, entity.pos_y), entity.args[1][frame]))
new_x = entity.pos_x
new_y = entity.pos_y
if delta_x: new_x += abs(delta_x) // delta_x
if delta_y: new_y += abs(delta_y) // delta_y
return new_x, new_y
# Extra functions
def print_text(text, min_value=0, max_value=0, default_value=0):
@ -385,27 +493,12 @@ def print_text(text, min_value=0, max_value=0, default_value=0):
else: input()
def stand_by(entity, data, stat, screen, walkable):
pass
def center(string, total_length, symbol):
left = floor((total_length - len(string)) / 2)
right = ceil((total_length - len(string)) / 2)
def permanent(entity, data, stat, screen, walkable):
pass
return left * symbol + string + right * symbol
def follow(entity, data, stat, screen, walkable):
if entity.pos_x == entity.pos_y == -1:
entity.pos_x, entity.pos_y = data[2], data[3]
elif data[4] in (1, 2, 3, 5):
if entity.args: walkable += entity.args[0]
cases = ((data[2] + 1, data[3]), (data[2], data[3] - 1), (data[2] - 1, data[3]), 0, (data[2], data[3] + 1))[data[4] - 1]
if not (0 <= cases[0] < screen.map_width and 0 <= cases[1] < screen.map_height): entity.pos_x, entity.pos_y = data[2], data[3]
elif screen.get_cell(cases[0], cases[1]) in walkable: entity.pos_x, entity.pos_y = cases
def walk(entity, data, stat, screen, walkable):
frame = (entity.args[0] + 1) % len(entity.args[1])
new_x, new_y = entity.args[1][frame]
if screen.get_cell(new_x, new_y) in walkable:
entity.pos_x, entity.pos_y = new_x, new_y
entity.args[0] = frame
def enumerate(data):
return [(i, data[i]) for i in range(len(data))]

View File

@ -1,6 +1,6 @@
from asci import *
maison = (r"""
exterieur = (r"""
_ ###
/o\__ #####
|_ <>\ ###
@ -10,30 +10,48 @@ maison = (r"""
|==|==|==|==|==|==|==|""",
# Entités
[
("sdf", "*", 2, 5, "stand by")
])
# Points de passage
(1, 3, 1, 3, 5))
carte_monde = (maison,)
interieur = (r"""
+----------+
| |
| |
| |
| |
+-|^|------+
""",
# Points de passage
(3, 5, 0, 1, 3))
carte_monde = (exterieur, interieur)
entites = (
["sdf", "*", 0, 2, 5, "stand by"],
)
def pnj(data, stat, entites, identifiant):
xp = data[0]["main"]
if identifiant == "sdf":
if xp == 2: entites["sdf"].change_behavior("follow")
if xp in (2, 7): entites["sdf"].change_behavior("follow")
elif xp == 4: entites["sdf"].change_behavior("stand by")
elif xp == 6:
entites["sdf"].change_behavior("stand by")
entites["sdf"].teleport(1, 2, 2)
return {
0: [0, "Mon bon monsieur, vous n'auriez pas quelques sous pour moi ?\n1. He non mon brave...\n2. Mais si, bien sur, tenez.", 2],
1: [5, "Radin !"],
2: [1, "Merci !", 0, (1, -1)], # 0 réponse possibles, -1 Argent
3: [0, "Hmm ?\n1. Arretez de me suivre !\n2. Non rien.", 2],
3: [0, "Hmm ?\n1.Arretez de me suivre !\n2.Non rien.\n3.Attendez-moi a l'intérieur, j'en ai pour une minute.", 3],
4: [2, "Soit..."],
5: [-2, "Bien"],
5: [-2, "Bien."],
6: [1, "Soit."],
7: [-4, "Je vous suis !"],
"base": [0, "Hmm ?"]
}
@ -55,5 +73,5 @@ touche = {6: affichage_stat}
def mon_jeu():
rpg_python = Asci(carte_monde, evenements, touche)
rpg_python.mainloop(7, stat=[100, 5], data=[{"main": 0}, 0, 10, 3])
rpg_python = Asci(carte_monde, entites, evenements, touche)
rpg_python.mainloop(10, stat=[100, 5], data=[{"main": 0}, 0, 10, 3])

View File

@ -12,9 +12,6 @@ cartes = (
|==|==|==|==|==|==|==|""",
[
(1, "*", 2, 5, "stand by")
],
(1, 3, 1, 5, 7)),
(r"""
@ -26,13 +23,14 @@ cartes = (
+--/ \--------/ \--+
| |
+---|^|--------------+""",
[
("habitant", "?", 9, 1, "stand by"),
("voleur", "?", 20, 1, "stand by")
],
(5, 7, 0, 1, 3))
)
entites = (
[1, "*", 0, 2, 5, "stand by"],
["habitant", "?", 1, 9, 1, "stand by"],
["voleur", "?", 1, 20, 1, "stand by"]
)
def pnj(data, stat, entites, identifiant):
carte_actuelle = data[1]
@ -83,5 +81,5 @@ touche = {8: affichage_statistique}
def mon_jeu():
rpg_python = Asci(cartes, evenements, touche)
rpg_python = Asci(cartes, entites, evenements, touche)
rpg_python.mainloop(11, [100], [{"main": 0}, 0, 10, 3])

View File

@ -15,11 +15,6 @@ cartes = (
#### |<> <>| ####
## |_________| ##
|| ||""",
[
("medecin", "*", 24, 4, "stand by"),
("ami", "*", 16, 1, "stand by"),
("bandit", "$", 4, 7, "walk", 0, ((4, 7), (3, 7), (3, 6), (4, 6)))
],
(1, 3, 1, 5, 7),
(19, 4, 2, 4, 4)),
@ -32,7 +27,6 @@ cartes = (
+--/ \--------/ \--+
| |
+---|^|--------------+""",
[(0, "*", 5, 5, "stand by")],
(5, 7, 0, 1, 3)),
(r"""
@ -42,10 +36,15 @@ cartes = (
| |
+--|^|--+
""",
[],
(4, 4, 0, 19, 4))
)
entites = (
["medecin", "*", 0, 24, 4, "stand by"],
["ami", "*", 0, 16, 1, "stand by"],
["bandit", "$", 0, 4, 7, "walk", 0, ((4, 7), (3, 7), (3, 6), (4, 6))],
[0, "*", 1, 5, 5, "stand by"]
)
def pnj(data, stat, entites, identifiant):
carte_actuelle = data[1]
@ -129,7 +128,7 @@ touche = {7: affichage_stat}
def mon_jeu(stat=[100, 0, 0], data=[{"main": 0}, 0, 10, 3]):
rpg_python = Asci(cartes, evenements, touche)
rpg_python = Asci(cartes, entites, evenements, touche)
stat, data = rpg_python.mainloop(5, stat, data=data)
print("Pour reprendre :")
print("mon_jeu({}, {})".format(stat, data))

View File

@ -12,9 +12,6 @@ cartes = (
|==|==|==|==|==|==|==|""",
[
("pnj", "?", 2, 5, "stand by")
],
(1, 3, 1, 5, 7)),
(r"""
@ -26,13 +23,14 @@ cartes = (
+--/ \--------/ \--+
| |
+---|^|--------------+""",
[
("boulanger", "?", 9, 1, "stand by"),
("kiosque", "?", 20, 1, "stand by")
],
(5, 7, 0, 1, 3))
)
entites = (
["pnj", "?", 0, 2, 5, "stand by"],
["boulanger", "?", 1, 9, 1, "stand by"],
["kiosque", "?", 1, 20, 1, "stand by"]
)
def pnj(data, stat, entites, identifiant):
if identifiant == "pnj":
@ -80,5 +78,5 @@ touche = {8: affichage_statistique}
def mon_jeu():
rpg_python = Asci(cartes, evenements, touche)
stat, data = rpg_python.mainloop(5, [100])
rpg_python = Asci(cartes, entites, evenements, touche)
stat, data = rpg_python.mainloop(5, [100], [{"main": 0}, 0, 10, 3])

69
samples/sample_5.py Normal file
View File

@ -0,0 +1,69 @@
from asci import *
exterieur = (r"""
_ ###
/o\__ #####
|_ <>\ ###
|^|__| /_\
|==|==|==|==|==|==|==|""",
# Points de passage
(1, 3, 1, 3, 5))
interieur = (r"""
+----------+
| |
| |
| |
| |
+-|^|------+""",
# Points de passage
(3, 5, 0, 1, 3))
carte_monde = (exterieur, interieur)
entites = (
["pnj", "*", 0, 2, 5, "stand by"],
)
def pnj(data, stat, entites, identifiant):
xp = data[0]["main"]
if identifiant == "pnj":
if xp == 1:
entites["pnj"].change_behavior("follow by player")
entites["pnj"].args = [0, ((3, 5), (16, 5), (16, 2))]
return {
"base": [0, "Moui ?"],
0: [0, "Tu me suis ?\n1.Oui\n2.Non", 2],
1: [2, "Parfait ! C'est parti !"],
2: [-2, "Rhoo alleezz..."],
3: [1, "Hehe"]
}
return [0, "Hmm ?"]
def affichage_stat(data, stat):
pv, argent = stat
print("Statistiques")
print("PV : {}".format(pv))
print("Argent : {}".format(argent))
input()
evenements = {"*": pnj}
touche = {6: affichage_stat}
def mon_jeu():
rpg_python = Asci(carte_monde, entites, evenements, touche)
rpg_python.mainloop(10, stat=[100, 5], data=[{"main": 0}, 0, 10, 3])

View File

@ -2,11 +2,11 @@
mkdir map_python
for i in $(ls -X *.tmx)
for i in *.tmx
do
echo "$i -> ${i%%.*}.py"
echo "$i -> ${i%.*}.py"
python converter "$i" doors=^ entities=?*
cp "${i%%.*}.py" map_python/
rm "${i%%.*}.py"
cp "${i%.*}.py" map_python/
rm "${i%.*}.py"
done

View File

@ -19,7 +19,6 @@ def convert_to_string(filename, doors, entities):
doors_coords = []
entities_data = []
entities_count = 0
output = r""
for line_index, line in enumerate(data):
for char_index, char_id in enumerate(line):
@ -28,8 +27,8 @@ def convert_to_string(filename, doors, entities):
output += char_list[char_id]
else:
output += " "
entities_data.append(f"({entities_count}, '{char_list[char_id]}', {char_index}, {line_index}, 'stand_by'),")
entities_count += 1
entities_data.append(f"[None, '{char_list[char_id]}', , {char_index}, {line_index}, 'stand_by'],")
if char_list[char_id] in doors:
doors_coords.append(f"\t({char_index}, {line_index}, , 0, 0),")
@ -37,10 +36,10 @@ def convert_to_string(filename, doors, entities):
output += "\n"
doors_coords = "\n".join(doors_coords)
entities_data = "[\n\t" + "\n\t".join(entities_data) + "\n]"
entities_data = "(\n\t" + "\n\t".join(entities_data) + "\n)"
with open(f"{output_filename}.py", "w") as file:
file.write(f"{output_filename} = (r\"\"\"\n{output[:-1]}\"\"\",\n{entities_data},\n\n{doors_coords}\n)")
file.write(f"{output_filename} = (r\"\"\"\n{output[:-1]}\"\"\",\n{doors_coords}\n)\n\n{output_filename}_entities = {entities_data}")
filename, doors, misc = argv[1], "", ""