diff options
| author | troido <troido@hotmail.com> | 2018-01-02 11:26:08 +0100 |
|---|---|---|
| committer | troido <troido@hotmail.com> | 2018-01-02 11:26:08 +0100 |
| commit | c98b58820f957a9d94756338c0e9c3971b5d2085 (patch) | |
| tree | 7c5762a24771bd10fe670b8f65b1fac9ec2838d3 /asciifarm/common/utils.py | |
| parent | 5e12a9ed28154407ee0453913d74bcc9366fe2df (diff) | |
sprites without a background will now take the background of the sprite below it (if any)
Diffstat (limited to 'asciifarm/common/utils.py')
| -rw-r--r-- | asciifarm/common/utils.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/asciifarm/common/utils.py b/asciifarm/common/utils.py index b37ec02..cdc8dd5 100644 --- a/asciifarm/common/utils.py +++ b/asciifarm/common/utils.py @@ -38,3 +38,10 @@ def readFile(filepath): with open(filepath, "r") as f: text = f.read() return text + + +def get(collection, i, default=None): + """ Get an element in an indexed collection, or the default in case the index is out of bounds """ + if i < 0 or i >= len(collection): + return default + return collection[i] |
