cc-haxe/src/kernel/peripherals/Peripherals.hx
2022-02-21 01:50:19 +01:00

60 lines
1.5 KiB
Haxe

package kernel.peripherals;
import kernel.peripherals.Modem;
import kernel.peripherals.Screen;
using lua.Table;
using Lambda;
/**
Class responseable for retrieving peripherals.
**/
class Peripheral {
public static var instance:Peripheral;
@:allow(kernel.Init)
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();
}
}