Skip to content

Commit 443b3e4

Browse files
committed
Turtle peripheral
1 parent 1930ae8 commit 443b3e4

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

computercraft/subapis/peripheral.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def setTextScale(self, scale: int):
7373
return nil(await self._send('setTextScale', scale))
7474

7575

76-
class CCComputer(BasePeripheral):
76+
class ComputerMixin:
7777
async def turnOn(self):
7878
return nil(await self._send('turnOn'))
7979

@@ -93,6 +93,14 @@ async def isOn(self) -> bool:
9393
return boolean(await self._send('isOn'))
9494

9595

96+
class CCComputer(BasePeripheral, ComputerMixin):
97+
pass
98+
99+
100+
class CCTurtle(BasePeripheral, ComputerMixin):
101+
pass
102+
103+
96104
@dataclass
97105
class ModemMessage:
98106
reply_channel: int
@@ -258,6 +266,7 @@ async def craft(self, quantity: int = 64) -> bool:
258266
'drive': CCDrive,
259267
'monitor': CCMonitor,
260268
'computer': CCComputer,
269+
'turtle': CCTurtle,
261270
'printer': CCPrinter,
262271
'speaker': CCSpeaker,
263272
'command': CCCommandBlock,

testmod.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,43 +1172,50 @@ async def test_monitor_peripheral(api):
11721172
await api.print('Test finished successfully')
11731173

11741174

1175-
async def test_computer_peripheral(api):
1175+
async def _computer_peri(api, place_thing, thing):
11761176
side = 'left'
11771177

11781178
await step(
11791179
api,
1180-
f'Place another computer on {side} side of computer\n'
1180+
f'Place {place_thing} on {side} side of computer\n'
11811181
"Don't turn it on!",
11821182
)
11831183

11841184
c = await api.peripheral.wrap(side)
11851185
assert c is not None
11861186

1187-
from computercraft.subapis.peripheral import CCComputer
1188-
1187+
from computercraft.subapis.peripheral import ComputerMixin
11891188
tbl = await get_object_table(api, f'peripheral.wrap("{side}")')
1190-
assert get_class_table(CCComputer) == tbl
1189+
assert get_class_table(ComputerMixin) == tbl
11911190

11921191
assert await c.isOn() is False
11931192
assert isinstance(await c.getID(), int)
11941193
assert await c.getLabel() is None
11951194
assert await c.turnOn() is None
11961195

1197-
await step(api, 'Computer must be turned on now')
1196+
await step(api, f'{thing.capitalize()} must be turned on now')
11981197

11991198
assert await c.shutdown() is None
12001199

1201-
await step(api, 'Computer must shutdown')
1200+
await step(api, f'{thing.capitalize()} must shutdown')
12021201

1203-
await step(api, 'Now turn on computer manually and enter some commands')
1202+
await step(api, f'Now turn on {thing} manually and enter some commands')
12041203

12051204
assert await c.reboot() is None
12061205

1207-
await step(api, 'Computer must reboot')
1206+
await step(api, f'{thing.capitalize()} must reboot')
12081207

12091208
await api.print('Test finished successfully')
12101209

12111210

1211+
async def test_computer_peripheral(api):
1212+
await _computer_peri(api, 'another computer', 'computer')
1213+
1214+
1215+
async def test_turtle_peripheral(api):
1216+
await _computer_peri(api, 'turtle', 'turtle')
1217+
1218+
12121219
async def modem_server(api):
12131220
side = 'back'
12141221
m = await api.peripheral.wrap(side)
@@ -1463,10 +1470,6 @@ async def test_modem_wrap(api):
14631470
await api.print('Test finished successfully')
14641471

14651472

1466-
async def test_turtle_peripheral(api):
1467-
raise NotImplementedError
1468-
1469-
14701473
async def test_textutils(api):
14711474
assert await api.textutils.slowWrite('write ') is None
14721475
assert await api.textutils.slowWrite('write ', 5) is None

0 commit comments

Comments
 (0)