cc-haxe/src/kernel/peripherals/Peripherals.hx

60 lines
1.5 KiB
Haxe
Raw Normal View History

2021-12-20 00:55:30 +00:00
package kernel.peripherals;
import kernel.peripherals.Modem;
import kernel.peripherals.Screen;
using lua.Table;
using Lambda;
/**
Class responseable for retrieving peripherals.
**/
class Peripheral {
2022-02-21 00:50:19 +00:00
public static var instance:Peripheral;
@:allow(kernel.Init)
2021-12-20 00:55:30 +00:00
private function new() {}
/**
Get all connected screens.
**/
public function getScreens(): Array<Screen> {
var allScreens = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "monitor");
return allScreens.map(s -> return new Screen((cc.Peripheral.wrap(s):Dynamic),s));
}
public function getScreen(addr: String): Screen {
if (!getAllPeripheralsAddr().exists(item -> item == addr)){
return null;
}
return new Screen((cc.Peripheral.wrap(addr):Dynamic),addr);
}
/**
Get all connected modems.
**/
public function getModems(): Array<Modem> {
var allModems = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "modem");
return allModems.map(s -> return new Modem((cc.Peripheral.wrap(s): Dynamic),s));
}
/**
Get all connected wireless modems.
**/
public function getWirelessModems(): Array<Modem> {
return getModems().filter(modem -> return modem.isWireless());
}
/**
Get all connected wired modems.
**/
public function getWiredModems(): Array<Modem> {
return getModems().filter(modem -> return !modem.isWireless());
}
public function getAllPeripheralsAddr(): Array<String> {
return cc.Peripheral.getNames().toArray();
}
}