Skip to content

Commit 9bb226f

Browse files
committed
isInteractive mode passed in the Rpg construct instead of the init
1 parent f032f42 commit 9bb226f

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

core/Rpg.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
class Rpg:
1616
_debug = False
1717

18-
def __init__(self, debug=False, renderMode=RENDER_TEXT):
18+
def __init__(self, debug=False, renderMode=RENDER_TEXT, isInteractive=True):
1919
self._player = None
2020
self._debug = debug
2121
self._renderMode = renderMode
2222
self._action = []
23+
self._isInteractive = isInteractive
2324

2425
def init(self, world, login, password, action=None):
2526
if world is None:
@@ -90,7 +91,7 @@ def run(self):
9091
else ask the player to enter a command
9192
'''
9293
if len(self._action) > 0:
93-
print(self._runAction(isInteractive=False))
94+
print(self._runAction())
9495
else:
9596
c = ''
9697
result = 0
@@ -106,7 +107,7 @@ def run(self):
106107

107108
if c != "":
108109
self._action = self.parseTypedAction(c)
109-
result = self._runAction(isInteractive=True)
110+
result = self._runAction()
110111

111112
if result == command_factory.quit:
112113
break
@@ -116,9 +117,9 @@ def run(self):
116117
print(result)
117118
print("")
118119

119-
def _runAction(self, isInteractive):
120+
def _runAction(self):
120121
try:
121-
c = command_factory.factory.create(self._player, self._action, isInteractive)
122+
c = command_factory.factory.create(self._player, self._action, self._isInteractive)
122123

123124
if c == command_factory.quit:
124125
return c

rRpg

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def main(argv):
4343
render = core.Rpg.RENDER_TEXT
4444
if args.json is not False:
4545
render = core.Rpg.RENDER_JSON
46-
rpg = core.Rpg.Rpg(args.debug, render)
46+
47+
isInteractive = args.action == []
48+
rpg = core.Rpg.Rpg(args.debug, render, isInteractive)
4749

4850
world = str(args.world)
4951
login = None

tests/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ def __init__(self, methodName='runTest'):
1010
unittest.TestCase.__init__(self, methodName)
1111
core.config.memoization_enabled = False
1212
self.dbFile = "/tmp/rpg.db"
13-
self.rpgText = Rpg.Rpg(renderMode=Rpg.RENDER_TEXT)
13+
self.rpgText = Rpg.Rpg(renderMode=Rpg.RENDER_TEXT, isInteractive=False)
1414
self.rpgText.init(self.dbFile, 'TEST_PLAYER', 'TEST_PLAYER')
15-
self.rpgJSON = Rpg.Rpg(renderMode=Rpg.RENDER_JSON)
15+
self.rpgJSON = Rpg.Rpg(renderMode=Rpg.RENDER_JSON, isInteractive=False)
1616
self.rpgJSON.init(self.dbFile, 'TEST_PLAYER', 'TEST_PLAYER')
1717

1818
def setUp(self):

0 commit comments

Comments
 (0)