-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework toplevel for future event infra
- Loading branch information
Showing
9 changed files
with
849 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# pygbag repl implement at the same time : | ||
# - the python console in the style of browser javascript's one | ||
# - the virtual gamepad | ||
# - demo record/replay | ||
# - event passthrough for pygame apps | ||
|
||
|
||
HISTORY = [] | ||
|
||
from embed import set_ps1, set_ps2, prompt, readline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
this = __import__(__name__) | ||
|
||
from pygbag_ui import Tui, TTY | ||
import pygbag_ui as ui | ||
from pygbag_ux import * | ||
|
||
ux_dim(1280 // 2 , 720 // 2) | ||
|
||
|
||
if 1: | ||
|
||
import pygame | ||
class vpad: | ||
X = 0 | ||
Z = 1 | ||
Y = 2 | ||
evx = [] | ||
evy = [] | ||
evz = [] | ||
axis = [evx, evz, evy] | ||
|
||
LZ = 0.5 | ||
|
||
@classmethod | ||
def get_axis(self, n): | ||
if len(self.axis[n]): | ||
return self.axis[n].pop(0) | ||
return 0.0 | ||
|
||
@classmethod | ||
def emit(self, axis, value): | ||
self.axis[axis].append(float(value)) | ||
ev = pygame.event.Event(pygame.JOYAXISMOTION) | ||
pygame.event.post(ev) | ||
return False | ||
|
||
|
||
|
||
|
||
import sys | ||
if sys.platform not in ('emscripten','wasi') or aio.cross.simulator: | ||
sleep_delay = 0 | ||
else: | ||
sleep_delay = 0.0155 | ||
|
||
|
||
|
||
|
||
def console(): | ||
import platform | ||
try: | ||
platform.window.pyconsole.hidden = False | ||
platform.window.document.body.style.background = "#000000"; | ||
except: | ||
... | ||
|
||
import os | ||
_, LINES = os.get_terminal_size() | ||
CONSOLE = os.get_console_size() | ||
|
||
# split the display | ||
if sys.platform not in ('emscripten','wasi') or aio.cross.simulator: | ||
LINES = LINES - CONSOLE | ||
|
||
TTY.set_raw(1) | ||
import select,os,platform | ||
|
||
platform.shell.is_interactive = False | ||
platform.shell.interactive(True) | ||
aio.toplevel.handler.muted = False | ||
|
||
ui.clear(LINES, CONSOLE, '>>> ') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
from transitions import Machine | ||
from dataclasses import dataclass | ||
import textwrap | ||
|
||
index = {} | ||
|
||
|
||
class State(object): | ||
... | ||
|
||
|
||
class Draft(object): | ||
... | ||
|
||
|
||
@dataclass() | ||
class FSM(Machine): | ||
states: tuple | ||
initial: str | ||
|
||
def __init__(self, *argv, **kw): | ||
Machine.__init__(self, states=self.states, initial=self.initial) | ||
|
||
|
||
# TODO move the wrap out of there. | ||
|
||
|
||
def state_refs(*argv): | ||
global index | ||
#tw = textwrap.TextWrapper(width=78) | ||
tw=None | ||
states = [] | ||
maxchapters = len(argv) | ||
for chapter, component in enumerate(argv): | ||
source = component.script | ||
block = source.strip().split("\n", 1)[0] | ||
states.append(block) | ||
lines = [] | ||
cmds = [] | ||
for i, line in enumerate(source.split("\n")): | ||
if i: | ||
if line: | ||
if line[0] != ":": | ||
# markdown eats space at § begin | ||
# line = line.replace(' ','\u2002\u2002') | ||
if tw: | ||
lines.extend(tw.wrap(line)) | ||
else: | ||
lines.append(line) | ||
else: | ||
cmds.append(line[1:]) | ||
else: | ||
lines.append("") | ||
while len(lines) and not lines[-1]: | ||
lines.pop() | ||
lines.append("") | ||
lines.append("") | ||
lines.pop(0) | ||
index[block] = { | ||
"heading": f"Chapter {chapter+1}/{maxchapters} : {block} ", | ||
"body": "\n".join(lines), | ||
"logic": cmds, | ||
} | ||
|
||
return tuple(states) | ||
|
||
|
||
def build(pkg, **kw): | ||
global story | ||
steps = [] # INTRO, BORED, WANDERING, EXPLORATION, BOOTING, PLAY | ||
|
||
for k, v in vars(pkg).items(): | ||
if v in [State, Draft]: | ||
continue | ||
|
||
if isinstance(v, type): | ||
if issubclass( | ||
v, | ||
( | ||
State, | ||
Draft, | ||
), | ||
): | ||
print(k, v) | ||
steps.append(v) | ||
|
||
class Story(FSM): | ||
states: tuple = state_refs(*steps) | ||
initial: str = states[0] | ||
index = index | ||
|
||
def setup(self, pkg, **kw): | ||
global index | ||
self.name = kw.get("name", pkg.__name__) | ||
|
||
for state in self.states: | ||
store = index[state] | ||
store["choices"] = {} | ||
|
||
for cmd in store["logic"]: | ||
if cmd.find(":") > 0: | ||
rel, tail = cmd.split(":") | ||
if rel == "?": | ||
continue | ||
if rel.find("->") >= 0: | ||
trigger, dest = map(str.strip, rel.split("->", 1)) | ||
if trigger == '-': | ||
trigger = dest | ||
else: | ||
if not trigger: | ||
trigger = dest | ||
store["choices"][trigger] = tail | ||
|
||
self.add_transition(trigger=trigger, source=state, dest=dest) | ||
return self | ||
|
||
story = Story() | ||
return story.setup(pkg, **kw) |
File renamed without changes.
Oops, something went wrong.