set default in from_string and allow "true" to become any value

This commit is contained in:
Stefan Harmuth 2022-12-04 11:11:27 +01:00
parent afcafbba0a
commit 011abd7fb5

View File

@ -377,10 +377,10 @@ class Grid:
)
@classmethod
def from_str(cls, grid_string: str, true_char: str = '#', default: Any = False) -> 'Grid':
def from_str(cls, grid_string: str, true_char: str = '#', true_value: Any = True, default: Any = False) -> 'Grid':
ret = cls(default=default)
for y, line in enumerate(grid_string.split("/")):
for x, c in enumerate(line):
ret.set(Coordinate(x, y), c == true_char)
ret.set(Coordinate(x, y), true_value if c == true_char else default)
return ret