Compare commits
5 Commits
12eb9d05de
...
7f8c0d154c
| Author | SHA1 | Date | |
|---|---|---|---|
|
7f8c0d154c
|
|||
|
f9c10cfc0b
|
|||
|
be89ca12bd
|
|||
|
ca79714e8d
|
|||
|
e0d4844890
|
@@ -1,5 +1,6 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
|
import lua.NativeStringTools;
|
||||||
import kernel.binstore.BinStore;
|
import kernel.binstore.BinStore;
|
||||||
import kernel.ps.ProcessHandle;
|
import kernel.ps.ProcessHandle;
|
||||||
import kernel.ps.Process;
|
import kernel.ps.Process;
|
||||||
@@ -139,7 +140,6 @@ class Terminal implements Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var commandArgs:Array<String> = args.slice(1);
|
var commandArgs:Array<String> = args.slice(1);
|
||||||
var hadInput = false;
|
|
||||||
|
|
||||||
var ps = getProgByName(commandName);
|
var ps = getProgByName(commandName);
|
||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
@@ -155,17 +155,19 @@ class Terminal implements Process {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hadInput) {
|
var mfunc = NativeStringTools.gmatch(s, "(.-)(\n)");
|
||||||
// Add a new line, so that the input is not on the same line as the command
|
|
||||||
this.backlog.push("");
|
while (true) {
|
||||||
hadInput = true;
|
var found = mfunc();
|
||||||
|
|
||||||
|
if (found == null) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (line in s.split("\n")) {
|
if (found == "\n") {
|
||||||
if (line == "") {
|
|
||||||
this.backlog.push("");
|
this.backlog.push("");
|
||||||
} else {
|
} else {
|
||||||
this.backlog[this.backlog.length - 1] += s;
|
this.backlog.push(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim the backlog if it's too long
|
// Trim the backlog if it's too long
|
||||||
|
|||||||
@@ -37,29 +37,32 @@ class Printer {
|
|||||||
|
|
||||||
// Turn left or right
|
// Turn left or right
|
||||||
if (x % 2 == (inverse ? 1 : 0)) {
|
if (x % 2 == (inverse ? 1 : 0)) {
|
||||||
Turtle.turnRight();
|
Turtle.turnLeft();
|
||||||
Turtle.forward();
|
Turtle.forward();
|
||||||
Turtle.turnRight();
|
Turtle.turnLeft();
|
||||||
} else {
|
} else {
|
||||||
Turtle.turnLeft();
|
Turtle.turnRight();
|
||||||
Turtle.forward();
|
Turtle.forward();
|
||||||
Turtle.turnLeft();
|
Turtle.turnRight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute() {
|
public function execute() {
|
||||||
|
Turtle.up(); // We place the block below us so move up.
|
||||||
|
|
||||||
for (i in 0...structure.height()) {
|
for (i in 0...structure.height()) {
|
||||||
var layer = structure.getLayer(i);
|
var layer = structure.getLayer(i);
|
||||||
var inverse = i % 2 == 0;
|
var inverse = i % 2 == 0;
|
||||||
|
|
||||||
printLayer(layer, inverse);
|
printLayer(layer, inverse);
|
||||||
|
|
||||||
// Don't go up on the last layer
|
// Don't go up or turn around on the last layer
|
||||||
if (i != structure.height() - 1) {
|
if (i == structure.height() - 1) {
|
||||||
Turtle.up();
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Turtle.up();
|
||||||
Turtle.turnLeft();
|
Turtle.turnLeft();
|
||||||
Turtle.turnLeft();
|
Turtle.turnLeft();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package lib.turtle;
|
package lib.turtle;
|
||||||
|
|
||||||
|
typedef Block = Bool;
|
||||||
|
|
||||||
abstract Structure(Array<Layer>) from Array<Layer> {
|
abstract Structure(Array<Layer>) from Array<Layer> {
|
||||||
public inline function getLayer(i:Int):Layer {
|
public inline function getLayer(i:Int):Layer {
|
||||||
return this[i];
|
return this[i];
|
||||||
@@ -8,10 +10,14 @@ abstract Structure(Array<Layer>) from Array<Layer> {
|
|||||||
public inline function height():Int {
|
public inline function height():Int {
|
||||||
return this.length;
|
return this.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rotate():Structure {
|
||||||
|
return [for (i in 0...height()) this[i].rotate()];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract Layer(Array<Array<Bool>>) from Array<Array<Bool>> {
|
abstract Layer(Array<Array<Block>>) from Array<Array<Block>> {
|
||||||
public inline function get(x:Int, y:Int):Bool {
|
public inline function get(x:Int, y:Int):Block {
|
||||||
return this[y][x];
|
return this[y][x];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,4 +28,41 @@ abstract Layer(Array<Array<Bool>>) from Array<Array<Bool>> {
|
|||||||
public inline function height():Int {
|
public inline function height():Int {
|
||||||
return this.length;
|
return this.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTextRepresentation():String {
|
||||||
|
var str = "";
|
||||||
|
for (y in 0...height()) {
|
||||||
|
for (x in 0...width()) {
|
||||||
|
if (get(x, y)) {
|
||||||
|
str += "X";
|
||||||
|
} else {
|
||||||
|
str += " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str += "\n";
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rotate():Layer {
|
||||||
|
// Transpose the matrix (swap rows and columns)
|
||||||
|
var transposedMatrix:Array<Array<Block>> = [];
|
||||||
|
for (columnIndex in 0...width()) {
|
||||||
|
var newRow:Array<Block> = [];
|
||||||
|
for (rowIndex in 0...height()) {
|
||||||
|
newRow.push(get(columnIndex, rowIndex));
|
||||||
|
}
|
||||||
|
transposedMatrix.push(newRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse the order of the columns
|
||||||
|
var rotatedMatrix:Array<Array<Block>> = [];
|
||||||
|
for (row in transposedMatrix) {
|
||||||
|
var rev = row.copy();
|
||||||
|
rev.reverse();
|
||||||
|
rotatedMatrix.push(rev);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rotatedMatrix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user