Compare commits
4 Commits
72dfcb1aa1
...
a75f86cbc1
| Author | SHA1 | Date | |
|---|---|---|---|
| a75f86cbc1 | |||
| 35be02dbe2 | |||
| aee8c0fd3c | |||
| f3141a0f99 |
@@ -60,7 +60,7 @@ class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) {
|
public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) {
|
||||||
writer.writeLn(logLine("SILY",pos,msg), LightGrey);
|
writer.writeLn(logLine("SILY",pos,msg), LightGray);
|
||||||
#if webconsole
|
#if webconsole
|
||||||
Debug.printWeb(logLine("SILY",pos,msg));
|
Debug.printWeb(logLine("SILY",pos,msg));
|
||||||
#end
|
#end
|
||||||
|
|||||||
@@ -77,19 +77,19 @@ class MainTerm implements TermWriteable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getTextColor():Color {
|
public function getTextColor():Color {
|
||||||
return ColorConvert.ccToColor(Term.getTextColor());
|
return Term.getTextColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTextColor(colour:Color) {
|
public function setTextColor(color:Color) {
|
||||||
Term.setTextColor(ColorConvert.colorToCC(colour));
|
Term.setTextColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBackgroundColor():Color {
|
public function getBackgroundColor():Color {
|
||||||
return ColorConvert.ccToColor(Term.getBackgroundColor());
|
return Term.getBackgroundColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBackgroundColor(color:Color) {
|
public function setBackgroundColor(color:Color) {
|
||||||
Term.setBackgroundColor(ColorConvert.colorToCC(color));
|
Term.setBackgroundColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isColor():Bool {
|
public function isColor():Bool {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package kernel.fs;
|
package kernel.fs;
|
||||||
|
|
||||||
|
import haxe.ds.ReadOnlyArray;
|
||||||
import kernel.fs.FileHandler.WriteBinaryHandle;
|
import kernel.fs.FileHandler.WriteBinaryHandle;
|
||||||
import kernel.fs.FileHandler.ReadBinaryHandle;
|
import kernel.fs.FileHandler.ReadBinaryHandle;
|
||||||
import kernel.fs.FileHandler.WriteHandle;
|
import kernel.fs.FileHandler.WriteHandle;
|
||||||
@@ -12,7 +13,7 @@ using lua.Table;
|
|||||||
Wrapper to interact with the filesystem.
|
Wrapper to interact with the filesystem.
|
||||||
**/
|
**/
|
||||||
class FS {
|
class FS {
|
||||||
public static inline function list(path: String):Array<String> {
|
public static inline function list(path: String):ReadOnlyArray<String> {
|
||||||
return FileSystem.list(path).toArray();
|
return FileSystem.list(path).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +85,7 @@ class FS {
|
|||||||
return FileSystem.open(path,BinaryAppend);
|
return FileSystem.open(path,BinaryAppend);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function find(pattern: String):Array<String> {
|
public static inline function find(pattern: String):ReadOnlyArray<String> {
|
||||||
return FileSystem.find(pattern).toArray();
|
return FileSystem.find(pattern).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
|
import haxe.ds.ReadOnlyArray;
|
||||||
import kernel.peripherals.Modem;
|
import kernel.peripherals.Modem;
|
||||||
import kernel.peripherals.Screen;
|
import kernel.peripherals.Screen;
|
||||||
|
|
||||||
@@ -19,12 +20,15 @@ class Peripheral {
|
|||||||
private var screens: Array<Screen> = [];
|
private var screens: Array<Screen> = [];
|
||||||
private var modes: Array<Modem> = [];
|
private var modes: Array<Modem> = [];
|
||||||
private var drives:Array<Drive> = [];
|
private var drives:Array<Drive> = [];
|
||||||
|
private var redstone:Array<Redstone> = [];
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private function new() {
|
private function new() {
|
||||||
KernelEvents.instance.onPeripheral.handle(this.updatePeripherals);
|
KernelEvents.instance.onPeripheral.handle(this.updatePeripherals);
|
||||||
KernelEvents.instance.onPeripheralDetach.handle(this.updatePeripherals);
|
KernelEvents.instance.onPeripheralDetach.handle(this.updatePeripherals);
|
||||||
updatePeripherals();
|
updatePeripherals();
|
||||||
|
|
||||||
|
redstone = [ for(side in [Side.Top,Side.Right,Side.Left,Side.Front,Side.Bottom,Side.Back]) new Redstone(side) ];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updatePeripherals() {
|
private function updatePeripherals() {
|
||||||
@@ -36,7 +40,7 @@ class Peripheral {
|
|||||||
/**
|
/**
|
||||||
Get all connected screens.
|
Get all connected screens.
|
||||||
**/
|
**/
|
||||||
public function getScreens():Array<Screen> {
|
public function getScreens():ReadOnlyArray<Screen> {
|
||||||
return this.screens;
|
return this.screens;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +56,7 @@ class Peripheral {
|
|||||||
/**
|
/**
|
||||||
Get all connected modems.
|
Get all connected modems.
|
||||||
**/
|
**/
|
||||||
public function getModems():Array<Modem> {
|
public function getModems():ReadOnlyArray<Modem> {
|
||||||
return this.modes;
|
return this.modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +72,7 @@ class Peripheral {
|
|||||||
/**
|
/**
|
||||||
Get all connected drives.
|
Get all connected drives.
|
||||||
**/
|
**/
|
||||||
public function getDrives(): Array<Drive> {
|
public function getDrives(): ReadOnlyArray<Drive> {
|
||||||
return this.drives;
|
return this.drives;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,4 +84,8 @@ class Peripheral {
|
|||||||
var allDrives = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "drive");
|
var allDrives = cc.Peripheral.getNames().toArray().filter(s -> cc.Peripheral.getType(s) == "drive");
|
||||||
this.drives = allDrives.map(s -> return new Drive((cc.Peripheral.wrap(s) : Dynamic), s));
|
this.drives = allDrives.map(s -> return new Drive((cc.Peripheral.wrap(s) : Dynamic), s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRedstone(side: String): Redstone {
|
||||||
|
return this.redstone.find(item -> item.getAddr() == side);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
60
src/kernel/peripherals/Redstone.hx
Normal file
60
src/kernel/peripherals/Redstone.hx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package kernel.peripherals;
|
||||||
|
|
||||||
|
import util.Color;
|
||||||
|
|
||||||
|
typedef BundleMask = Color;
|
||||||
|
|
||||||
|
class Redstone implements IPeripheral {
|
||||||
|
|
||||||
|
private final addr:Side;
|
||||||
|
|
||||||
|
@:allow(kernel.peripherals)
|
||||||
|
private function new(side: Side) {
|
||||||
|
this.addr = side;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddr():String {
|
||||||
|
return this.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function setOutput(on:Bool):Void {
|
||||||
|
cc.Redstone.setOutput(this.addr,on);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function getOutput(): Bool {
|
||||||
|
return cc.Redstone.getOutput(this.addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function getInput(): Bool {
|
||||||
|
return cc.Redstone.getInput(this.addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function setAnalogOutput(strength:Int): Void {
|
||||||
|
cc.Redstone.setAnalogOutput(this.addr,strength);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function getAnalogOutput(): Int {
|
||||||
|
return cc.Redstone.getAnalogOutput(this.addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function getAnalogInput(): Int {
|
||||||
|
return cc.Redstone.getAnalogInput(this.addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function setBundledOutput(output: BundleMask) {
|
||||||
|
cc.Redstone.setBundledOutput(this.addr,output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function getBundledOutput():BundleMask {
|
||||||
|
return cc.Redstone.getBundledOutput(this.addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function getBundledInput():BundleMask {
|
||||||
|
return cc.Redstone.getBundledInput(this.addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function testBundledInput(mask: Color): Bool {
|
||||||
|
return cc.Redstone.testBundledInput(this.addr,mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -90,19 +90,19 @@ class Screen implements TermWriteable implements IPeripheral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getTextColor():Color {
|
public function getTextColor():Color {
|
||||||
return ColorConvert.ccToColor(nativ.getTextColor());
|
return nativ.getTextColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTextColor(colour:Color) {
|
public function setTextColor(color:Color) {
|
||||||
nativ.setTextColor(ColorConvert.colorToCC(colour));
|
nativ.setTextColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBackgroundColor():Color {
|
public function getBackgroundColor():Color {
|
||||||
return ColorConvert.ccToColor(nativ.getBackgroundColor());
|
return nativ.getBackgroundColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBackgroundColor(color:Color) {
|
public function setBackgroundColor(color:Color) {
|
||||||
nativ.setBackgroundColor(ColorConvert.colorToCC(color));
|
nativ.setBackgroundColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isColor():Bool {
|
public function isColor():Bool {
|
||||||
|
|||||||
10
src/kernel/peripherals/Side.hx
Normal file
10
src/kernel/peripherals/Side.hx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package kernel.peripherals;
|
||||||
|
|
||||||
|
enum abstract Side(String) to String {
|
||||||
|
var Top = "top";
|
||||||
|
var Bottom = "bottom";
|
||||||
|
var Left = "left";
|
||||||
|
var Right = "right";
|
||||||
|
var Front = "front";
|
||||||
|
var Back = "back";
|
||||||
|
}
|
||||||
@@ -158,8 +158,8 @@ class TermBuffer implements TermWriteable {
|
|||||||
return currentTextColor;
|
return currentTextColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTextColor(colour:Color) {
|
public function setTextColor(color:Color) {
|
||||||
currentTextColor = colour;
|
currentTextColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBackgroundColor():Color {
|
public function getBackgroundColor():Color {
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ interface TermWriteable {
|
|||||||
public function clear():Void;
|
public function clear():Void;
|
||||||
public function clearLine():Void;
|
public function clearLine():Void;
|
||||||
public function getTextColor():Color;
|
public function getTextColor():Color;
|
||||||
public function setTextColor(colour:Color):Void;
|
public function setTextColor(color:Color):Void;
|
||||||
public function getBackgroundColor():Color;
|
public function getBackgroundColor():Color;
|
||||||
public function setBackgroundColor(color:Color):Void;
|
public function setBackgroundColor(color:Color):Void;
|
||||||
public function isColor():Bool;
|
public function isColor():Bool;
|
||||||
// public function setPaletteColor(...);
|
// public function setPaletteColor(...);
|
||||||
// public function getPaletteColor(colour);
|
// public function getPaletteColor(color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Clears the screen, resetes the courser to (0,0) and resetes the color to Black and White.
|
Clears the screen, resetes the courser to (0,0) and resetes the color to Black and White.
|
||||||
|
|||||||
@@ -150,12 +150,12 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
|
|||||||
return super.getTextColor();
|
return super.getTextColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function setTextColor(colour:Color) {
|
public override function setTextColor(color:Color) {
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
target.setTextColor(colour);
|
target.setTextColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.setTextColor(colour);
|
super.setTextColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function getBackgroundColor():Color {
|
public override function getBackgroundColor():Color {
|
||||||
|
|||||||
@@ -114,8 +114,8 @@ class WindowContext implements TermWriteable {
|
|||||||
return writer.getTextColor();
|
return writer.getTextColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTextColor(colour:Color) {
|
public function setTextColor(color:Color) {
|
||||||
writer.setTextColor(colour);
|
writer.setTextColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBackgroundColor():Color {
|
public function getBackgroundColor():Color {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package kernel.ui;
|
package kernel.ui;
|
||||||
|
|
||||||
|
import haxe.ds.ReadOnlyArray;
|
||||||
import kernel.ui.TermWriteable;
|
import kernel.ui.TermWriteable;
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ class WindowManager {
|
|||||||
return newContext;
|
return newContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOutputs():Array<String> {
|
public function getOutputs():ReadOnlyArray<String> {
|
||||||
var arr = Peripheral.instance.getScreens().map(screen -> return screen.getAddr());
|
var arr = Peripheral.instance.getScreens().map(screen -> return screen.getAddr());
|
||||||
arr.push("main");
|
arr.push("main");
|
||||||
return arr;
|
return arr;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ _G.require = function (module)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
print("ERROR: Tell a dev to implement: " .. i)
|
print("ERROR: Tell a dev to implement: " .. i)
|
||||||
os.exit()
|
error("ERROR: Tell a dev to implement: " .. i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ _G.require = function (module)
|
|||||||
return module
|
return module
|
||||||
end
|
end
|
||||||
print("ERROR: Tell a dev to implement: " .. module)
|
print("ERROR: Tell a dev to implement: " .. module)
|
||||||
os.exit()
|
error("ERROR: Tell a dev to implement: " .. module)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Polyfill bit. see: http://bitop.luajit.org/api.html
|
-- Polyfill bit. see: http://bitop.luajit.org/api.html
|
||||||
@@ -36,23 +36,23 @@ end
|
|||||||
|
|
||||||
bit.tobit = function(x)
|
bit.tobit = function(x)
|
||||||
print("ERROR: Tell a dev to implement: bit.tobi")
|
print("ERROR: Tell a dev to implement: bit.tobi")
|
||||||
os.exit()
|
error()
|
||||||
end
|
end
|
||||||
|
|
||||||
bit.tohex = function(x,n)
|
bit.tohex = function(x,n)
|
||||||
print("ERROR: Tell a dev to implement: bit.tohex")
|
print("ERROR: Tell a dev to implement: bit.tohex")
|
||||||
os.exit()
|
error()
|
||||||
end
|
end
|
||||||
|
|
||||||
bit.lshift = function(x,n)
|
bit.lshift = function(x,n)
|
||||||
print("ERROR: Tell a dev to implement: bit.lshift")
|
print("ERROR: Tell a dev to implement: bit.lshift")
|
||||||
os.exit()
|
error()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
bit.rshift = function(x,n)
|
bit.rshift = function(x,n)
|
||||||
print("ERROR: Tell a dev to implement: bit.rshift")
|
print("ERROR: Tell a dev to implement: bit.rshift")
|
||||||
os.exit()
|
error()
|
||||||
end
|
end
|
||||||
|
|
||||||
bit.arshift = function(x,n)
|
bit.arshift = function(x,n)
|
||||||
@@ -62,15 +62,15 @@ end
|
|||||||
|
|
||||||
bit.rol = function(x,n)
|
bit.rol = function(x,n)
|
||||||
print("ERROR: Tell a dev to implement: bit.rol")
|
print("ERROR: Tell a dev to implement: bit.rol")
|
||||||
os.exit()
|
error()
|
||||||
end
|
end
|
||||||
|
|
||||||
bit.ror = function(x,n)
|
bit.ror = function(x,n)
|
||||||
print("ERROR: Tell a dev to implement: bit.ror")
|
print("ERROR: Tell a dev to implement: bit.ror")
|
||||||
os.exit()
|
error()
|
||||||
end
|
end
|
||||||
|
|
||||||
bit.bswap = function(x)
|
bit.bswap = function(x)
|
||||||
print("ERROR: Tell a dev to implement: bit.bswap")
|
print("ERROR: Tell a dev to implement: bit.bswap")
|
||||||
os.exit()
|
error()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,111 +1,27 @@
|
|||||||
package util;
|
package util;
|
||||||
|
|
||||||
import haxe.Exception;
|
import kernel.peripherals.Redstone.BundleMask;
|
||||||
import cc.Colors;
|
|
||||||
|
|
||||||
enum Color {
|
enum abstract Color(Int) from cc.Colors.Color to cc.Colors.Color {
|
||||||
White;
|
var White = 0x1;
|
||||||
Orange;
|
var Orange = 0x2;
|
||||||
Magenta;
|
var Magenta = 0x4;
|
||||||
LightBlue;
|
var LightBlue = 0x8;
|
||||||
Yellow;
|
var Yellow = 0x10;
|
||||||
Lime;
|
var Lime = 0x20;
|
||||||
Pink;
|
var Pink = 0x40;
|
||||||
Gray;
|
var Gray = 0x80;
|
||||||
Grey;
|
var LightGray = 0x100;
|
||||||
LightGray;
|
var Cyan = 0x200;
|
||||||
LightGrey;
|
var Purple = 0x400;
|
||||||
Cyan;
|
var Blue = 0x800;
|
||||||
Purple;
|
var Brown = 0x1000;
|
||||||
Blue;
|
var Green = 0x2000;
|
||||||
Brown;
|
var Red = 0x4000;
|
||||||
Green;
|
var Black = 0x8000;
|
||||||
Red;
|
|
||||||
Black;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ColorConvert {
|
@:op(A + B)
|
||||||
public static function colorToCC(color:Color):cc.Colors.Color {
|
public inline function combine(rhs: Color):BundleMask {
|
||||||
switch color {
|
return this + rhs;
|
||||||
case White:
|
|
||||||
return Colors.white;
|
|
||||||
case Orange:
|
|
||||||
return Colors.orange;
|
|
||||||
case Magenta:
|
|
||||||
return Colors.magenta;
|
|
||||||
case LightBlue:
|
|
||||||
return Colors.lightBlue;
|
|
||||||
case Yellow:
|
|
||||||
return Colors.yellow;
|
|
||||||
case Lime:
|
|
||||||
return Colors.lime;
|
|
||||||
case Pink:
|
|
||||||
return Colors.pink;
|
|
||||||
case Gray:
|
|
||||||
return Colors.gray;
|
|
||||||
case Grey:
|
|
||||||
return Colors.grey;
|
|
||||||
case LightGray:
|
|
||||||
return Colors.lightGray;
|
|
||||||
case LightGrey:
|
|
||||||
return Colors.lightGrey;
|
|
||||||
case Cyan:
|
|
||||||
return Colors.cyan;
|
|
||||||
case Purple:
|
|
||||||
return Colors.purple;
|
|
||||||
case Blue:
|
|
||||||
return Colors.blue;
|
|
||||||
case Brown:
|
|
||||||
return Colors.brown;
|
|
||||||
case Green:
|
|
||||||
return Colors.green;
|
|
||||||
case Red:
|
|
||||||
return Colors.red;
|
|
||||||
case Black:
|
|
||||||
return Colors.black;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function ccToColor(color:cc.Colors.Color):Color {
|
|
||||||
switch color {
|
|
||||||
case 0:
|
|
||||||
return White;
|
|
||||||
case 1:
|
|
||||||
return Orange;
|
|
||||||
case 2:
|
|
||||||
return Magenta;
|
|
||||||
case 3:
|
|
||||||
return LightBlue;
|
|
||||||
case 4:
|
|
||||||
return Yellow;
|
|
||||||
case 5:
|
|
||||||
return Lime;
|
|
||||||
case 6:
|
|
||||||
return Pink;
|
|
||||||
case 7:
|
|
||||||
return Gray;
|
|
||||||
case 8:
|
|
||||||
return Grey;
|
|
||||||
case 9:
|
|
||||||
return LightGray;
|
|
||||||
case 10:
|
|
||||||
return LightGrey;
|
|
||||||
case 11:
|
|
||||||
return Cyan;
|
|
||||||
case 12:
|
|
||||||
return Purple;
|
|
||||||
case 13:
|
|
||||||
return Blue;
|
|
||||||
case 14:
|
|
||||||
return Brown;
|
|
||||||
case 15:
|
|
||||||
return Green;
|
|
||||||
case 16:
|
|
||||||
return Red;
|
|
||||||
case 17:
|
|
||||||
return Black;
|
|
||||||
case _:
|
|
||||||
throw new Exception("Invalid input");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user