1.0 Alpha
This commit is contained in:
parent
8069a1cfa5
commit
5816616c33
4
Activities/Games/test.py
Normal file
4
Activities/Games/test.py
Normal file
@ -0,0 +1,4 @@
|
||||
x = "test"
|
||||
|
||||
def printit():
|
||||
print(x)
|
||||
65
Activities/States/home.py
Normal file
65
Activities/States/home.py
Normal file
@ -0,0 +1,65 @@
|
||||
import time
|
||||
import menu
|
||||
import alarm
|
||||
import board
|
||||
import entity
|
||||
import animate
|
||||
import selector
|
||||
import displayio
|
||||
import buttonBus
|
||||
import adafruit_imageload
|
||||
|
||||
class home:
|
||||
|
||||
root = displayio.Group()
|
||||
entity = entity.entity()
|
||||
select = selector.selector([[5,0],[40,0],[70,0],[90,0],[0,220],[110,220]])
|
||||
|
||||
|
||||
def __init__(self, root, entity):
|
||||
self.root = root
|
||||
self.entity = entity
|
||||
|
||||
self.entity.show(root[2])
|
||||
|
||||
bg, bgPallette = adafruit_imageload.load("/Sprites/Backgrounds/bg1.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
|
||||
bgTile = displayio.TileGrid(bg, pixel_shader=bgPallette)
|
||||
self.root[0].append(bgTile)
|
||||
self.select.showSelector(self.root[5])
|
||||
|
||||
def do(self, x):
|
||||
global wakeTime
|
||||
if x == -1:
|
||||
pass
|
||||
elif x == 0:
|
||||
pass
|
||||
elif x == 1:
|
||||
pass
|
||||
elif x == 2:
|
||||
pass
|
||||
elif x == 3:
|
||||
pass
|
||||
elif x == 4:
|
||||
self.select.hideSelector(self.root[5])
|
||||
menu.toggleMenu(self.root[4], self.root[5], "test", "test")
|
||||
elif x == 5:
|
||||
buttonBus.button1.deinit()
|
||||
pin_alarm = alarm.pin.PinAlarm(pin=board.D1, value=True, pull=True)
|
||||
time.sleep(0.5)
|
||||
alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
|
||||
|
||||
def looper(self):
|
||||
animate.doAnimate(self.root[2], 0.5, 10)
|
||||
|
||||
if buttonBus.getSelectedButton() == 0:
|
||||
self.select.lastPos()
|
||||
time.sleep(0.2)
|
||||
return True
|
||||
elif buttonBus.getSelectedButton() == 1:
|
||||
self.do(self.select.getSPos())
|
||||
time.sleep(0.2)
|
||||
return True
|
||||
elif buttonBus.getSelectedButton() == 2:
|
||||
self.select.nextPos()
|
||||
time.sleep(0.2)
|
||||
return True
|
||||
88
code.py
88
code.py
@ -1,13 +1,15 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import alarm
|
||||
import board
|
||||
import displayio
|
||||
import bitmaptools
|
||||
import adafruit_imageload
|
||||
import storage
|
||||
import displayio
|
||||
import supervisor
|
||||
import bitmaptools
|
||||
import microcontroller
|
||||
import adafruit_imageload
|
||||
|
||||
import menu
|
||||
import entity
|
||||
@ -15,6 +17,20 @@ import animate
|
||||
import selector
|
||||
import buttonBus
|
||||
|
||||
|
||||
def importer(path):
|
||||
sys.path.append(path)
|
||||
for entry in os.listdir(path):
|
||||
if entry[-3:] == ".py":
|
||||
string = f'import {entry}'[:-3]
|
||||
exec (string)
|
||||
elif "." not in entry:
|
||||
importer(path+'/'+entry)
|
||||
|
||||
importer("/Activities")
|
||||
sam = "xyz"
|
||||
test.printit()
|
||||
|
||||
#screen /dev/ttyACM0 115200
|
||||
|
||||
#setup
|
||||
@ -37,56 +53,27 @@ selectorGroup = displayio.Group()
|
||||
|
||||
board.DISPLAY.show(root)
|
||||
|
||||
entity = entity.entity()
|
||||
entity.importSave()
|
||||
entity.show(haioGroup)
|
||||
root.insert(0, bgGroup)
|
||||
root.insert(1, bgItemGroup)
|
||||
root.insert(2, haioGroup)
|
||||
root.insert(3, fgItemGroup)
|
||||
root.insert(4, menuGroup)
|
||||
root.insert(5, selectorGroup)
|
||||
|
||||
|
||||
bg, bgPallette = adafruit_imageload.load("/Sprites/Backgrounds/bg1.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
|
||||
bgTile = displayio.TileGrid(bg, pixel_shader=bgPallette)
|
||||
bgGroup.append(bgTile)
|
||||
|
||||
root.append(bgGroup)
|
||||
root.append(bgItemGroup)
|
||||
root.append(haioGroup)
|
||||
root.append(fgItemGroup)
|
||||
root.append(menuGroup)
|
||||
root.append(selectorGroup)
|
||||
|
||||
select = selector.selector([[5,0],[40,0],[70,0],[90,0],[0,220],[110,220]])
|
||||
select.showSelector(selectorGroup)
|
||||
wakeTime = time.monotonic()
|
||||
|
||||
|
||||
entity = entity.entity()
|
||||
entity.importSave()
|
||||
|
||||
#Load Settings
|
||||
with open("/Save/settings.json", "r") as reader:
|
||||
settings = json.loads(reader.read())
|
||||
|
||||
timeoutAmount = settings["timeout"]
|
||||
timeout = round(time.monotonic() + timeoutAmount, 1)
|
||||
|
||||
nextWake = max(entity.character["nextEventTime"], entity.character["nextEvloutionTime"], entity.character["death"]) - entity.character["age"]
|
||||
|
||||
#Menu Activites
|
||||
def do(x):
|
||||
global wakeTime
|
||||
if x == 0:
|
||||
entity.character["age"] += int(time.monotonic() - wakeTime)
|
||||
wakeTime = time.monotonic()
|
||||
print(entity.character["age"])
|
||||
pass
|
||||
elif x == 1:
|
||||
pass
|
||||
elif x == 2:
|
||||
pass
|
||||
elif x == 3:
|
||||
pass
|
||||
elif x == 4:
|
||||
menu.toggleMenu(root)
|
||||
elif x == 5:
|
||||
buttonBus.button1.deinit()
|
||||
pin_alarm = alarm.pin.PinAlarm(pin=board.D1, value=True, pull=True)
|
||||
time.sleep(0.5)
|
||||
alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
|
||||
|
||||
def checkTimeout():
|
||||
# print("Time: " + str(round(time.monotonic(), 1)) + " Timeout: " + str(timeout))
|
||||
@ -98,20 +85,11 @@ def checkTimeout():
|
||||
time.sleep(0.5)
|
||||
alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
|
||||
|
||||
|
||||
home = home.home(root, entity)
|
||||
|
||||
#System Loop
|
||||
while True:
|
||||
checkTimeout()
|
||||
animate.doAnimate(haioGroup, 0.5, 10)
|
||||
|
||||
if buttonBus.getSelectedButton() == 0:
|
||||
select.lastPos()
|
||||
time.sleep(0.2)
|
||||
timeout = round(time.monotonic() + timeoutAmount, 1)
|
||||
elif buttonBus.getSelectedButton() == 1:
|
||||
do(select.getSPos())
|
||||
time.sleep(0.2)
|
||||
timeout = round(time.monotonic() + timeoutAmount, 1)
|
||||
elif buttonBus.getSelectedButton() == 2:
|
||||
select.nextPos()
|
||||
time.sleep(0.2)
|
||||
if home.looper():
|
||||
timeout = round(time.monotonic() + timeoutAmount, 1)
|
||||
|
||||
12
lib/G.py
Normal file
12
lib/G.py
Normal file
@ -0,0 +1,12 @@
|
||||
import displayio
|
||||
|
||||
root = displayio.Group()
|
||||
|
||||
bgGroup = displayio.Group()
|
||||
bgItemGroup = displayio.Group()
|
||||
haioGroup = displayio.Group()
|
||||
fgItemGroup = displayio.Group()
|
||||
menuGroup = displayio.Group()
|
||||
selectorGroup = displayio.Group()
|
||||
|
||||
sam = "xyz"
|
||||
23
lib/menu.py
23
lib/menu.py
@ -1,28 +1,27 @@
|
||||
import board
|
||||
import adafruit_max1704x
|
||||
import time
|
||||
import terminalio
|
||||
import board
|
||||
import selector
|
||||
import buttonBus
|
||||
import displayio
|
||||
import terminalio
|
||||
import adafruit_max1704x
|
||||
from adafruit_display_shapes.rect import Rect
|
||||
from adafruit_display_text import bitmap_label, wrap_text_to_lines
|
||||
|
||||
menuToggle = True
|
||||
battery = adafruit_max1704x.MAX17048(board.I2C())
|
||||
|
||||
def toggleMenu(splash):
|
||||
global menuToggle
|
||||
def toggleMenu(menuGroup, selectorGroup, label1, method1):
|
||||
global battery
|
||||
if menuToggle:
|
||||
|
||||
|
||||
# bselect = selector.selector([[10, 60],[10, 80]])
|
||||
# bselect.showSelector(selectorGroup)
|
||||
|
||||
battery.reset()
|
||||
time.sleep(0.05)
|
||||
timeText = bitmap_label.Label(terminalio.FONT, text="Time: " + str(time.monotonic()), scale=1, color=0x000000, x=25, y=60)
|
||||
batText = bitmap_label.Label(terminalio.FONT, text="Battery: " + str(round(battery.cell_percent)) + "%", scale=1, color=0x000000, x=25, y=80)
|
||||
menuGroup = displayio.Group()
|
||||
menuGroup.append(Rect(10, 10, 115, 220, fill=0xFFFFFF, outline=0x000000, stroke=2))
|
||||
menuGroup.append(bitmap_label.Label(terminalio.FONT, text="Menu", scale=2, color=0x000000, x=30, y=30))
|
||||
menuGroup.append(timeText)
|
||||
menuGroup.append(batText)
|
||||
splash.append(menuGroup)
|
||||
else:
|
||||
splash.pop()
|
||||
menuToggle ^= True
|
||||
|
||||
@ -6,13 +6,15 @@ spos = -1
|
||||
class selector:
|
||||
|
||||
def __init__(self, positions):
|
||||
global spos
|
||||
self.size = len(positions)
|
||||
self.positions = positions
|
||||
spos = -1
|
||||
|
||||
def showSelector(self, selectorGroup):
|
||||
global spos
|
||||
if spos == -1:
|
||||
selectorGroup.insert(0,select)
|
||||
selectorGroup.append(select)
|
||||
spos += 1
|
||||
|
||||
def hideSelector(self, selectorGroup):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user