From 0d83da70aee475d962c376034b001bb75aa1aad4 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sat, 1 Aug 2020 22:57:26 -0400 Subject: [PATCH] Janky line delete --- scripting.py | 36 +++++++++++++++++++++++++----------- world.py | 4 ++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/scripting.py b/scripting.py index b75fed1..ee7c218 100644 --- a/scripting.py +++ b/scripting.py @@ -352,12 +352,18 @@ class SyntBlock(Synt): self.rgsynt.insert(self.rgsynt.index(syntAfter) + 1, syntStmt) syntStmt.syntParent = self return syntStmt - + + def RemoveLine(self, synt): + self.rgsynt.remove(synt) + def HandleKey(self, pwKey, pov, psel, key): if ansi.FEnter(key): self.InsertLineAfter(pwKey.pwChild.Value(), None) psel.Inc(pwKey.PwParent()) return True + elif key == ansi.K_DEL and pwKey.pwChild.RgpwChild()[0] == psel.PwSelected(pwKey): + psel.Inc(pwKey.PwParent()) + self.RemoveLine(pwKey.pwChild.Value()) return False def Eval(self, env): @@ -738,8 +744,6 @@ class PwBlock(PwContainer): return psel.Dec(self) elif key == ansi.K_DOWN: return psel.Inc(self) - elif key == ansi.K_DEL: - pass return False class PwDropdown(PwBlock): @@ -865,14 +869,28 @@ class Psel(TPrs): if self.FPwValid(pwChild): return True return False - + + def CLevelChild_PwRoot(self, pw): + clevelChild = 1 + while pw.PwParent() != None: + clevelChild = clevelChild + 1 + pw = pw.PwParent() + return (clevelChild, pw) + + def PwRoot(self, pw): + return self.CLevelChild_PwRoot(pw)[1] + def Value(self, pwRoot): + pwRoot = self.PwRoot(pwRoot) self.Validate(pwRoot) if len(self.rgo_ipw) > 0: return self.rgo_ipw[-1][0] return None - def PwSelected(self, pwRoot, clevel = None): + def PwSelected(self, pw, clevel = None): + clevelChild, pwRoot = self.CLevelChild_PwRoot(pw) + if clevel is not None: + clevel = clevel + clevelChild - 1 self.Validate(pwRoot) return self.PwSelectedI(pwRoot, self.rgo_ipw[:clevel]) @@ -887,11 +905,7 @@ class Psel(TPrs): return self.ChangeI(pwContainer, IoDec) def ChangeI(self, pwContainer, fnChange): - clevelChild = 1 - pwRoot = pwContainer - while pwRoot.PwParent() != None: - clevelChild = clevelChild + 1 - pwRoot = pwRoot.PwParent() + clevelChild, pwRoot = self.CLevelChild_PwRoot(pwContainer) self.Validate(pwRoot) assert self.PwSelected(pwRoot, clevelChild).PwParent() == pwContainer @@ -915,7 +929,7 @@ class Pov(TokenClient): def Back(self, val, pw): self.client.leaveGame() - + def run(self): while True: key = self.EvKey().receive(self) diff --git a/world.py b/world.py index 0824fd8..8395c74 100644 --- a/world.py +++ b/world.py @@ -213,7 +213,7 @@ class Joiner(LeaveJoinToken): self.game.Chat().Add(ChlSys(client, "has left")) ## TODO: -## - fix numbering +## - fix lobby numbering (clients either editing or playing a game) class Player(TokenClient): def InitPersistent(self, owner, client): @@ -282,7 +282,7 @@ class GameWorld(Game): def Chat(self): return self.chat - + def StName(self): return self.dtStart.strftime("%b %d, %Y at %I:%M%p") + " [" + str(len(self.RgclientConnected())) + "]"