From c98b58820f957a9d94756338c0e9c3971b5d2085 Mon Sep 17 00:00:00 2001 From: troido Date: Tue, 2 Jan 2018 11:26:08 +0100 Subject: sprites without a background will now take the background of the sprite below it (if any) --- asciifarm/common/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'asciifarm/common/utils.py') 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] -- cgit