set default in from_string and allow "true" to become any value
This commit is contained in:
parent
afcafbba0a
commit
011abd7fb5
@ -377,10 +377,10 @@ class Grid:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@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)
|
ret = cls(default=default)
|
||||||
for y, line in enumerate(grid_string.split("/")):
|
for y, line in enumerate(grid_string.split("/")):
|
||||||
for x, c in enumerate(line):
|
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
|
return ret
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user