-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModEdit.py
75 lines (66 loc) · 1.66 KB
/
ModEdit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import Befunge as bfg
import Funge as fng
import TermIntr as ti
import TermUI as tui
plane=None
cursor=None
moveButton=ti.Button("toggle smartmove","tab",toggle=True,activated=True)
listener=ti.Listener()
@listener.handle
def handler(key):
if len(key)==1:
if key=="\n":
return
else:
plane[cursor.cursor]=ord(key)
if not moveButton.activated:
cursor.cursor+=cursor.cursorDelta
elif (
key==" " or ord(key) not in bfg.befunge2d or (moveButton.activated and not cursor.step(certain=True))
):
cursor.cursor+=cursor.cursorDelta
elif key=="backspace":
if moveButton.activated:
if plane[cursor.cursor]==plane.defaultValue:
cursor.cursor-=cursor.cursorDelta
if plane[cursor.cursor]==plane.defaultValue:
cursor.cursor+=cursor.cursorDelta
else:
cursor.cursor-=cursor.cursorDelta
del plane[cursor.cursor]
cursor.updateInfo(cursor.cursorDelta,cursor.cursor)
valueButton=ti.Button("put value","ctrl k")
valueBox=ti.Textbox("ctrl l",text="")
statusText=None
@valueButton.onPress
def putDown(*_):
try:
plane[cursor.cursor]=int(valueBox.text)
cursor.updateInfo(cursor.cursorDelta,cursor.cursor)
except ValueError:
statusText(f"Invalid number '{valueBox.text}'!")
stack=tui.VStack(
tui.Text("Type to put tile down!")
.pad(bottom=1),
moveButton,
valueButton,
tui.HStack(
tui.Text("*value -> *"),
valueBox
),
)
intr=ti.Group(
listener,
valueBox,
valueButton,
moveButton
)
def modInit(m,config,lock):
global plane,cursor,statusText
plane=m.load.funge.plane
cursor=m.cursor
statusText=m.statustext.queueText
sidebar=m.sidebar.Sidebar("Editor",stack,intr)
def prioritise(m):
m.sidebar.addSidebar(sidebar)
return prioritise