Compare commits
118 Commits
088fce0aaa
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
c665401fd8
|
|||
|
2799a0be3d
|
|||
|
e527dd5b6a
|
|||
|
fe17b4fd67
|
|||
|
90b4015ba1
|
|||
|
2dd85c2b26
|
|||
|
1d60e13792
|
|||
|
9d6e8a366b
|
|||
|
5167533c6d
|
|||
|
aac527ae89
|
|||
|
af6a4c840b
|
|||
|
afbd1dfd68
|
|||
|
b305594ea4
|
|||
|
df7991763d
|
|||
|
e0f8d274e7
|
|||
|
08f41ccb0b
|
|||
|
28ec48cc85
|
|||
|
4f2b6e7c53
|
|||
|
2e0bda7a6e
|
|||
|
87c93f3ae0
|
|||
|
628aef06e3
|
|||
|
2603527b67
|
|||
|
39a7da716c
|
|||
|
afc0309222
|
|||
|
0d9ce5d6b1
|
|||
|
be58ed1c05
|
|||
|
fe16799bbb
|
|||
|
5f5e899f6e
|
|||
|
8546659ae0
|
|||
|
249a48807a
|
|||
|
be405887e2
|
|||
|
73e2ccdcb8
|
|||
|
b05dae958d
|
|||
|
3e993b84eb
|
|||
|
09fef78f9a
|
|||
|
7d30d9d971
|
|||
|
29285641a4
|
|||
|
37eab6f8e2
|
|||
|
f95c262c57
|
|||
|
5f42941d76
|
|||
|
1108eab403
|
|||
|
e5b990ae61
|
|||
|
5925f851c4
|
|||
|
d13831f213
|
|||
|
a9f6adcd9d
|
|||
|
757d7098cf
|
|||
|
4e69bda3c8
|
|||
|
755e5ff6b4
|
|||
|
9353ccba8a
|
|||
|
5c71ab1c30
|
|||
|
36f97f09d5
|
|||
|
e04021425a
|
|||
|
d89956a626
|
|||
|
dd146d1caf
|
|||
|
adb758bd53
|
|||
|
baae1428bd
|
|||
|
7bd18c1a4c
|
|||
|
99489e37df
|
|||
|
86f6dbf302
|
|||
|
4836cae3fa
|
|||
|
69ca3f3282
|
|||
|
3484503ba1
|
|||
|
1efa8fa212
|
|||
|
9541b653b5
|
|||
|
4ab3d868c1
|
|||
|
2ab5a38894
|
|||
|
e3875f76f6
|
|||
|
fdcb81b565
|
|||
|
72654b1036
|
|||
|
fe85c33d64
|
|||
|
1d9e08641e
|
|||
|
638d1acbe0
|
|||
|
815ccdaab9
|
|||
|
c0741c48aa
|
|||
|
e2ab296e79
|
|||
|
64f4304626
|
|||
|
8cd105b84c
|
|||
|
ce0e89f5b3
|
|||
|
c9e0ceef32
|
|||
|
6170fdd0d3
|
|||
|
3fce8d515a
|
|||
|
fe88e065ab
|
|||
|
e2916a213a
|
|||
|
22509932c3
|
|||
|
f109305f48
|
|||
|
295d284bc1
|
|||
|
92deb7177f
|
|||
|
3e09bcfad2
|
|||
|
762f72c160
|
|||
|
1d2a43155a
|
|||
|
9bb6b8bf2b
|
|||
|
7f8c0d154c
|
|||
|
f9c10cfc0b
|
|||
|
be89ca12bd
|
|||
|
ca79714e8d
|
|||
|
e0d4844890
|
|||
|
12eb9d05de
|
|||
|
e39720b63d
|
|||
| e593fc52c4 | |||
| ad0c62d6e5 | |||
| 0cac0053e3 | |||
| a568c9cdd8 | |||
| 44772557ba | |||
| 0540cc465a | |||
| 21387cd8e7 | |||
| a46760e587 | |||
| c83f457968 | |||
| b8f5ffb93a | |||
| 3c59e045de | |||
| 4b8bc87db9 | |||
| 0c7280a2f5 | |||
| 98b8465436 | |||
| 016063e3be | |||
| 0fc2d4d397 | |||
| da3f00acb6 | |||
| db50a93512 | |||
| f3a13e4247 | |||
| 91972107eb |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
/build
|
/build
|
||||||
/node_modules
|
node_modules
|
||||||
|
/dump
|
||||||
|
|||||||
49
Makefile
49
Makefile
@@ -1,32 +1,57 @@
|
|||||||
BUNDLE_NAME = bundle.lua
|
BUNDLE_NAME = bundle.lua
|
||||||
HAXE_NAME = haxe.lua
|
HAXE_NAME = haxe.lua
|
||||||
MINIFYD_NAME = bundle.min.lua
|
MINIFYD_NAME = bundle.min.lua
|
||||||
|
HAXE_ZIP_NAME = "haxe.zip"
|
||||||
|
UNPACK_NAME = unpack.lua
|
||||||
|
UNPACK_POLYFILLED_NAME = unpack.polyfill.lua
|
||||||
|
UNPACK_MINIFYD_NAME = unpack.min.lua
|
||||||
BUILD_DIR = build
|
BUILD_DIR = build
|
||||||
HAXE_FLAGS =
|
HAXE_FLAGS = -D message.reporting=pretty
|
||||||
POLYFILLED_NAME = bundle.polyfill.lua
|
POLYFILLED_NAME = bundle.polyfill.lua
|
||||||
POLYFILL_SRC = src/polyfill.lua
|
POLYFILL_SRC = src/polyfill.lua
|
||||||
CREAFTOS_PATH = craftos
|
CREAFTOS_PATH = craftos
|
||||||
|
BUILD_HXML = build.hxml
|
||||||
|
|
||||||
HAXE_PATH := $(BUILD_DIR)/$(HAXE_NAME)
|
HAXE_PATH := $(BUILD_DIR)/$(HAXE_NAME)
|
||||||
MIN_PATH := $(BUILD_DIR)/$(MINIFYD_NAME)
|
MIN_PATH := $(BUILD_DIR)/$(MINIFYD_NAME)
|
||||||
POLYFILL_PATH := $(BUILD_DIR)/$(POLYFILLED_NAME)
|
POLYFILL_PATH := $(BUILD_DIR)/$(POLYFILLED_NAME)
|
||||||
|
UNPACK_PATH := $(BUILD_DIR)/$(UNPACK_NAME)
|
||||||
|
UNPACK_MINIFYD_PATH := $(BUILD_DIR)/$(UNPACK_MINIFYD_NAME)
|
||||||
|
HAXE_ZIP_PATH := $(BUILD_DIR)/$(HAXE_ZIP_NAME)
|
||||||
|
UNPACK_POLYFILLED_PATH := $(BUILD_DIR)/$(UNPACK_POLYFILLED_NAME)
|
||||||
|
|
||||||
all: clean build
|
all: clean build unpack
|
||||||
|
|
||||||
build: HAXE_FLAGS += --main kernel.Entrypoint -D analyzer-optimize
|
build: HAXE_FLAGS += -D analyzer-optimize -D no-traces
|
||||||
build: $(MIN_PATH)
|
build: $(MIN_PATH)
|
||||||
|
|
||||||
debug: HAXE_FLAGS += -D webconsole -D error_stack --debug
|
debug: HAXE_FLAGS += -D webconsole -D error_stack --debug
|
||||||
debug: build
|
debug: $(MIN_PATH)
|
||||||
|
|
||||||
|
unpack: $(UNPACK_MINIFYD_PATH) $(HAXE_ZIP_PATH)
|
||||||
|
|
||||||
|
$(HAXE_PATH): HAXE_FLAGS += --main kernel.Entrypoint --lua $(HAXE_PATH)
|
||||||
$(HAXE_PATH): $(shell find src -name '*.hx')
|
$(HAXE_PATH): $(shell find src -name '*.hx')
|
||||||
haxe build.hxml $(HAXE_FLAGS)
|
haxe $(BUILD_HXML) $(HAXE_FLAGS)
|
||||||
|
|
||||||
$(POLYFILL_PATH): $(POLYFILL_SRC) $(HAXE_PATH)
|
$(POLYFILL_PATH): $(POLYFILL_SRC) $(HAXE_PATH)
|
||||||
cat $(POLYFILL_SRC) $(HAXE_PATH) > $@
|
cat $(POLYFILL_SRC) $(HAXE_PATH) > $@
|
||||||
|
|
||||||
$(MIN_PATH): $(POLYFILL_PATH)
|
$(MIN_PATH): $(POLYFILL_PATH)
|
||||||
node minify.js $(POLYFILL_PATH) $@
|
node tools/minify.js < $(POLYFILL_PATH) > $@
|
||||||
|
|
||||||
|
$(HAXE_ZIP_PATH): $(MIN_PATH)
|
||||||
|
node tools/zlibDeflate.js < $(MIN_PATH) > $@
|
||||||
|
|
||||||
|
$(UNPACK_PATH): HAXE_FLAGS += --main Unpack -D analyzer-optimize --lua $(UNPACK_PATH)
|
||||||
|
$(UNPACK_PATH): $(shell find src -name '*.hx')
|
||||||
|
haxe $(BUILD_HXML) $(HAXE_FLAGS)
|
||||||
|
|
||||||
|
$(UNPACK_POLYFILLED_PATH): $(UNPACK_PATH)
|
||||||
|
cat $(POLYFILL_SRC) $(UNPACK_PATH) > $@
|
||||||
|
|
||||||
|
$(UNPACK_MINIFYD_PATH): $(UNPACK_POLYFILLED_PATH)
|
||||||
|
node tools/minify.js < $(UNPACK_POLYFILLED_PATH) > $@
|
||||||
|
|
||||||
.PHONY: deps
|
.PHONY: deps
|
||||||
deps: deps-hx deps-node
|
deps: deps-hx deps-node
|
||||||
@@ -37,7 +62,7 @@ deps-hx:
|
|||||||
|
|
||||||
.PHONY: deps-node
|
.PHONY: deps-node
|
||||||
deps-node:
|
deps-node:
|
||||||
yarn install
|
npm install
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
@@ -54,4 +79,12 @@ emulator:
|
|||||||
|
|
||||||
.PHONY: webconsole
|
.PHONY: webconsole
|
||||||
webconsole:
|
webconsole:
|
||||||
node console.js
|
node tools/console.js
|
||||||
|
|
||||||
|
.PHONY: format
|
||||||
|
format:
|
||||||
|
haxelib run formatter -s src
|
||||||
|
|
||||||
|
.PHONY: format-deps
|
||||||
|
format-deps:
|
||||||
|
haxelib install formatter
|
||||||
@@ -21,7 +21,7 @@ run `make deps && make`. The `bundle.min.lua` inside the `build` dir is the fina
|
|||||||
|
|
||||||
# Useful links
|
# Useful links
|
||||||
|
|
||||||
[CC lua code](https://github.com/cc-tweaked/CC-Tweaked/tree/mc-1.19.x/projects/core/src/main/resources/data/computercraft/lua)
|
[CC lua code](https://github.com/cc-tweaked/CC-Tweaked/tree/mc-1.20.x/projects/core/src/main/resources/data/computercraft/lua)
|
||||||
|
|
||||||
[CC wiki](https://tweaked.cc/)
|
[CC wiki](https://tweaked.cc/)
|
||||||
|
|
||||||
|
|||||||
@@ -9,4 +9,4 @@
|
|||||||
-D lua-vanilla
|
-D lua-vanilla
|
||||||
-D lua-ver 5.1
|
-D lua-ver 5.1
|
||||||
|
|
||||||
--lua build/haxe.lua
|
--macro include("bin")
|
||||||
|
|||||||
24
buildServer/Dockerfile
Normal file
24
buildServer/Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
FROM haxe:4.3-bullseye
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
git \
|
||||||
|
make \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN curl -fsSL https://deb.nodesource.com/setup_current.x | bash - && \
|
||||||
|
apt-get install -y nodejs
|
||||||
|
|
||||||
|
RUN mkdir -p /app
|
||||||
|
RUN mkdir -p /repo
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY index.js /app/index.js
|
||||||
|
COPY package.json /app/package.json
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
ENV REPO_DIR=/repo
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["node", "index.js"]
|
||||||
105
buildServer/index.js
Normal file
105
buildServer/index.js
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const childProcess = require('child_process');
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
const path = require('path');
|
||||||
|
const async = require('async');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
|
const workingDir = process.env.REPO_DIR ?? "repo";
|
||||||
|
const buildQueue = async.queue(async (task) => {
|
||||||
|
return build(task);
|
||||||
|
});
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
|
app.post('/build', async (req, res) => {
|
||||||
|
try{
|
||||||
|
let output = await buildQueue.push(req.body);
|
||||||
|
res.status(200);
|
||||||
|
res.send(output);
|
||||||
|
}catch(e){
|
||||||
|
res.status(500);
|
||||||
|
res.send(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/pull', async (req, res) => {
|
||||||
|
try{
|
||||||
|
await pull();
|
||||||
|
res.status(200);
|
||||||
|
res.send("Pulled");
|
||||||
|
}catch(e){
|
||||||
|
res.status(500);
|
||||||
|
res.send(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
||||||
|
async function build(body){
|
||||||
|
return await make();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
app.listen(3000, () => console.log('Server running on port 3000'));
|
||||||
|
|
||||||
|
process.on('SIGINT', async () => {
|
||||||
|
console.log("Shutting down");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pull(){
|
||||||
|
await runCommand("git pull");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function make(makeCommand = "make build"){
|
||||||
|
try{
|
||||||
|
await runCommand(makeCommand);
|
||||||
|
let build = await fs.readFile(path.join(workingDir,"build/bundle.min.lua"), "utf8");
|
||||||
|
return build;
|
||||||
|
}catch(e){
|
||||||
|
console.log("Build failed");
|
||||||
|
}finally{
|
||||||
|
await runCommand("make clean");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setup() {
|
||||||
|
try {
|
||||||
|
await fs.mkdir(workingDir);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.code !== "EEXIST") {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((await fs.readdir(workingDir)).length !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Setting up repo");
|
||||||
|
await runCommand("git clone https://git.kapelle.org/niklas/cc-haxe.git .");
|
||||||
|
await runCommand("make deps");
|
||||||
|
}
|
||||||
|
|
||||||
|
function runCommand(cmd) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
childProcess.exec(cmd,{
|
||||||
|
cwd: workingDir,
|
||||||
|
}, (err, stdout, stderr) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(stdout);
|
||||||
|
console.log(stderr);
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
701
buildServer/package-lock.json
generated
Normal file
701
buildServer/package-lock.json
generated
Normal file
@@ -0,0 +1,701 @@
|
|||||||
|
{
|
||||||
|
"name": "buildServer",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "buildServer",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"async": "^3.2.4",
|
||||||
|
"body-parser": "^1.20.2",
|
||||||
|
"express": "^4.18.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/accepts": {
|
||||||
|
"version": "1.3.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
|
||||||
|
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"mime-types": "~2.1.34",
|
||||||
|
"negotiator": "0.6.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/array-flatten": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/async": {
|
||||||
|
"version": "3.2.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz",
|
||||||
|
"integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ=="
|
||||||
|
},
|
||||||
|
"node_modules/body-parser": {
|
||||||
|
"version": "1.20.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
|
||||||
|
"integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
|
||||||
|
"dependencies": {
|
||||||
|
"bytes": "3.1.2",
|
||||||
|
"content-type": "~1.0.5",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"depd": "2.0.0",
|
||||||
|
"destroy": "1.2.0",
|
||||||
|
"http-errors": "2.0.0",
|
||||||
|
"iconv-lite": "0.4.24",
|
||||||
|
"on-finished": "2.4.1",
|
||||||
|
"qs": "6.11.0",
|
||||||
|
"raw-body": "2.5.2",
|
||||||
|
"type-is": "~1.6.18",
|
||||||
|
"unpipe": "1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8",
|
||||||
|
"npm": "1.2.8000 || >= 1.4.16"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/bytes": {
|
||||||
|
"version": "3.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
||||||
|
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/call-bind": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"function-bind": "^1.1.1",
|
||||||
|
"get-intrinsic": "^1.0.2"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/content-disposition": {
|
||||||
|
"version": "0.5.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
||||||
|
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"safe-buffer": "5.2.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/content-type": {
|
||||||
|
"version": "1.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
|
||||||
|
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/cookie": {
|
||||||
|
"version": "0.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz",
|
||||||
|
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/cookie-signature": {
|
||||||
|
"version": "1.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
|
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/debug": {
|
||||||
|
"version": "2.6.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/depd": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/destroy": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8",
|
||||||
|
"npm": "1.2.8000 || >= 1.4.16"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ee-first": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/encodeurl": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/escape-html": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/etag": {
|
||||||
|
"version": "1.8.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
||||||
|
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/express": {
|
||||||
|
"version": "4.18.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz",
|
||||||
|
"integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"accepts": "~1.3.8",
|
||||||
|
"array-flatten": "1.1.1",
|
||||||
|
"body-parser": "1.20.1",
|
||||||
|
"content-disposition": "0.5.4",
|
||||||
|
"content-type": "~1.0.4",
|
||||||
|
"cookie": "0.5.0",
|
||||||
|
"cookie-signature": "1.0.6",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"depd": "2.0.0",
|
||||||
|
"encodeurl": "~1.0.2",
|
||||||
|
"escape-html": "~1.0.3",
|
||||||
|
"etag": "~1.8.1",
|
||||||
|
"finalhandler": "1.2.0",
|
||||||
|
"fresh": "0.5.2",
|
||||||
|
"http-errors": "2.0.0",
|
||||||
|
"merge-descriptors": "1.0.1",
|
||||||
|
"methods": "~1.1.2",
|
||||||
|
"on-finished": "2.4.1",
|
||||||
|
"parseurl": "~1.3.3",
|
||||||
|
"path-to-regexp": "0.1.7",
|
||||||
|
"proxy-addr": "~2.0.7",
|
||||||
|
"qs": "6.11.0",
|
||||||
|
"range-parser": "~1.2.1",
|
||||||
|
"safe-buffer": "5.2.1",
|
||||||
|
"send": "0.18.0",
|
||||||
|
"serve-static": "1.15.0",
|
||||||
|
"setprototypeof": "1.2.0",
|
||||||
|
"statuses": "2.0.1",
|
||||||
|
"type-is": "~1.6.18",
|
||||||
|
"utils-merge": "1.0.1",
|
||||||
|
"vary": "~1.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/express/node_modules/body-parser": {
|
||||||
|
"version": "1.20.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
|
||||||
|
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
|
||||||
|
"dependencies": {
|
||||||
|
"bytes": "3.1.2",
|
||||||
|
"content-type": "~1.0.4",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"depd": "2.0.0",
|
||||||
|
"destroy": "1.2.0",
|
||||||
|
"http-errors": "2.0.0",
|
||||||
|
"iconv-lite": "0.4.24",
|
||||||
|
"on-finished": "2.4.1",
|
||||||
|
"qs": "6.11.0",
|
||||||
|
"raw-body": "2.5.1",
|
||||||
|
"type-is": "~1.6.18",
|
||||||
|
"unpipe": "1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8",
|
||||||
|
"npm": "1.2.8000 || >= 1.4.16"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/express/node_modules/raw-body": {
|
||||||
|
"version": "2.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
|
||||||
|
"integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
|
||||||
|
"dependencies": {
|
||||||
|
"bytes": "3.1.2",
|
||||||
|
"http-errors": "2.0.0",
|
||||||
|
"iconv-lite": "0.4.24",
|
||||||
|
"unpipe": "1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/finalhandler": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"encodeurl": "~1.0.2",
|
||||||
|
"escape-html": "~1.0.3",
|
||||||
|
"on-finished": "2.4.1",
|
||||||
|
"parseurl": "~1.3.3",
|
||||||
|
"statuses": "2.0.1",
|
||||||
|
"unpipe": "~1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/forwarded": {
|
||||||
|
"version": "0.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||||
|
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/fresh": {
|
||||||
|
"version": "0.5.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
||||||
|
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/function-bind": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/get-intrinsic": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"function-bind": "^1.1.1",
|
||||||
|
"has": "^1.0.3",
|
||||||
|
"has-proto": "^1.0.1",
|
||||||
|
"has-symbols": "^1.0.3"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/has": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"function-bind": "^1.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/has-proto": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/has-symbols": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/http-errors": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"depd": "2.0.0",
|
||||||
|
"inherits": "2.0.4",
|
||||||
|
"setprototypeof": "1.2.0",
|
||||||
|
"statuses": "2.0.1",
|
||||||
|
"toidentifier": "1.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/iconv-lite": {
|
||||||
|
"version": "0.4.24",
|
||||||
|
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||||
|
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||||
|
"dependencies": {
|
||||||
|
"safer-buffer": ">= 2.1.2 < 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/inherits": {
|
||||||
|
"version": "2.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||||
|
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
|
"node_modules/ipaddr.js": {
|
||||||
|
"version": "1.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||||
|
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/media-typer": {
|
||||||
|
"version": "0.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||||
|
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/merge-descriptors": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/methods": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mime": {
|
||||||
|
"version": "1.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
|
||||||
|
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"mime": "cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mime-db": {
|
||||||
|
"version": "1.52.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||||
|
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mime-types": {
|
||||||
|
"version": "2.1.35",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||||
|
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"mime-db": "1.52.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ms": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/negotiator": {
|
||||||
|
"version": "0.6.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
|
||||||
|
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/object-inspect": {
|
||||||
|
"version": "1.12.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz",
|
||||||
|
"integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/on-finished": {
|
||||||
|
"version": "2.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
|
||||||
|
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ee-first": "1.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/parseurl": {
|
||||||
|
"version": "1.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
||||||
|
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/path-to-regexp": {
|
||||||
|
"version": "0.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
||||||
|
"integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/proxy-addr": {
|
||||||
|
"version": "2.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||||
|
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"forwarded": "0.2.0",
|
||||||
|
"ipaddr.js": "1.9.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qs": {
|
||||||
|
"version": "6.11.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
||||||
|
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"dependencies": {
|
||||||
|
"side-channel": "^1.0.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.6"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/range-parser": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/raw-body": {
|
||||||
|
"version": "2.5.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
|
||||||
|
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
|
||||||
|
"dependencies": {
|
||||||
|
"bytes": "3.1.2",
|
||||||
|
"http-errors": "2.0.0",
|
||||||
|
"iconv-lite": "0.4.24",
|
||||||
|
"unpipe": "1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/safe-buffer": {
|
||||||
|
"version": "5.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||||
|
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/safer-buffer": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||||
|
},
|
||||||
|
"node_modules/send": {
|
||||||
|
"version": "0.18.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz",
|
||||||
|
"integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"depd": "2.0.0",
|
||||||
|
"destroy": "1.2.0",
|
||||||
|
"encodeurl": "~1.0.2",
|
||||||
|
"escape-html": "~1.0.3",
|
||||||
|
"etag": "~1.8.1",
|
||||||
|
"fresh": "0.5.2",
|
||||||
|
"http-errors": "2.0.0",
|
||||||
|
"mime": "1.6.0",
|
||||||
|
"ms": "2.1.3",
|
||||||
|
"on-finished": "2.4.1",
|
||||||
|
"range-parser": "~1.2.1",
|
||||||
|
"statuses": "2.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/send/node_modules/ms": {
|
||||||
|
"version": "2.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||||
|
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/serve-static": {
|
||||||
|
"version": "1.15.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz",
|
||||||
|
"integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"encodeurl": "~1.0.2",
|
||||||
|
"escape-html": "~1.0.3",
|
||||||
|
"parseurl": "~1.3.3",
|
||||||
|
"send": "0.18.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/setprototypeof": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
|
"node_modules/side-channel": {
|
||||||
|
"version": "1.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
||||||
|
"integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"call-bind": "^1.0.0",
|
||||||
|
"get-intrinsic": "^1.0.2",
|
||||||
|
"object-inspect": "^1.9.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/statuses": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/toidentifier": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/type-is": {
|
||||||
|
"version": "1.6.18",
|
||||||
|
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
||||||
|
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"media-typer": "0.3.0",
|
||||||
|
"mime-types": "~2.1.24"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/unpipe": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/utils-merge": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/vary": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
buildServer/package.json
Normal file
11
buildServer/package.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "buildServer",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"async": "^3.2.4",
|
||||||
|
"body-parser": "^1.20.2",
|
||||||
|
"express": "^4.18.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
32
console.js
32
console.js
@@ -1,32 +0,0 @@
|
|||||||
const http = require('http');
|
|
||||||
|
|
||||||
function time() {
|
|
||||||
let now = new Date();
|
|
||||||
|
|
||||||
return `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, 0)}:${now.getSeconds().toString().padStart(2, 0)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
|
||||||
|
|
||||||
if (req.method != "POST") {
|
|
||||||
res.writeHead(400);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var id = req.url.substring(1);
|
|
||||||
|
|
||||||
let data = "";
|
|
||||||
|
|
||||||
req.on('data', chunk => {
|
|
||||||
data += chunk;
|
|
||||||
})
|
|
||||||
|
|
||||||
req.on('end', () => {
|
|
||||||
console.log(`[${time()}][${id}]${data}`);
|
|
||||||
res.writeHead(200);
|
|
||||||
res.end();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("Listening on port 8080")
|
|
||||||
server.listen(8080);
|
|
||||||
139
doc/Concepts.md
139
doc/Concepts.md
@@ -57,7 +57,7 @@ Also peripherals can be made accessible via the network. More on that later.
|
|||||||
var back = Peripheral.getRedstone("back");
|
var back = Peripheral.getRedstone("back");
|
||||||
back.setOutput(true);
|
back.setOutput(true);
|
||||||
|
|
||||||
var drive Peripheral.getDrive("drive_0");
|
var drive = Peripheral.getDrive("drive_0");
|
||||||
drive.eject();
|
drive.eject();
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -111,12 +111,143 @@ A collection of `Pixel` is called a `Canvas` which is nothing more than a 2D arr
|
|||||||
The concept of processes tryes to encapsulate programs. A process is basically an interface with the `run(handle: ProcessHandle)` method.
|
The concept of processes tryes to encapsulate programs. A process is basically an interface with the `run(handle: ProcessHandle)` method.
|
||||||
The idea is that you can register all you disposable resources in the handle and they will be disposed when the process is killed or crashes.
|
The idea is that you can register all you disposable resources in the handle and they will be disposed when the process is killed or crashes.
|
||||||
|
|
||||||
A process can be used as a command on the terminal or as a service. See [bin/HelloWorld.hx](../src/bin/HelloWorld.hx) for an example.
|
A process can be used as a command on the terminal or as a service. Basically everything that runs and is not part of the kernel is a process.
|
||||||
Basically everything that runs and is not part of the kernel is a process.
|
|
||||||
|
|
||||||
In order for you program to be used it needs to be registered in the `BinStore` and the `DCEHack` manually.
|
More on that at [Applications](#applications).
|
||||||
|
|
||||||
# EndOfLoop
|
# EndOfLoop
|
||||||
|
|
||||||
You can imagine the whole runtime like the event loop is JS. The `EndOfLoop` class is used to register callbacks that are called at the end of the loop.
|
You can imagine the whole runtime like the event loop is JS. The `EndOfLoop` class is used to register callbacks that are called at the end of the loop.
|
||||||
This is like the `setTimeout(0, callback)` in JS.
|
This is like the `setTimeout(0, callback)` in JS.
|
||||||
|
|
||||||
|
# Turtle Thread
|
||||||
|
|
||||||
|
Computercraft is mostly event-based. Listening to `Coroutine.yield()` waits for events with an option parameter for filtering events.
|
||||||
|
The problem with turtle arises when we call turtle functions like `move` or `place`. These functions wait internally for
|
||||||
|
the operation to finish with a `Coroutine.yield("turtle_response")` call. There is no way to prevent this. So in order to keep the main loop from
|
||||||
|
being blocked, we run all the turtle code in a separate thread.
|
||||||
|
|
||||||
|
There are no real threads in Lua, but we can create a coroutine for the turtles. Lua now switches between the main thread and the turtle thread.
|
||||||
|
Switching occurs when a `turtle_response` events is fired. This will be forwarded to the turtle thread. Once the turtle thread has run its code
|
||||||
|
and waits for the turtle operation to finish, we switch back to the main thread. The main thread is running normally until a `turtle_response` fires
|
||||||
|
and the circle repeats.
|
||||||
|
|
||||||
|
Be aware that no one is stopping you from running turtle commands in the main thread.
|
||||||
|
|
||||||
|
See `KernelEvents.hx` for more.
|
||||||
|
|
||||||
|
## Using Turtle threads
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```haxe
|
||||||
|
// In the context of a process
|
||||||
|
|
||||||
|
if (!handle.claimTurtleMutex()) {
|
||||||
|
Log.warn("Failed to claim turtle thread");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Btw. no one is stopping you from calling this without claiming the mutex.
|
||||||
|
TurtleMutex.runInTThread(() -> {
|
||||||
|
while(true){
|
||||||
|
Turtle.turnLeft();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
# RPC
|
||||||
|
|
||||||
|
With the help of dark and badly documented magic also known as "macros", we can create quickly create remote procedure call Classes to call functions on other
|
||||||
|
computers. A problem that arises is that since all data gets send over the network that we kinda lose the type safty. We cloud trust ourself to cast
|
||||||
|
the result of the request to the right type or we cloud just make use of macros. The RPC macro will create a RPC class that implements all functions of an
|
||||||
|
interface just that the return type is wrapped in a Promise. Now if we call a function of that RPC class it fires a request to the other computer and waits
|
||||||
|
for a response. On the other side the service makes use of that generated package handle function for the RPC class.
|
||||||
|
|
||||||
|
A simple example:
|
||||||
|
|
||||||
|
```haxe
|
||||||
|
interface IExampleRPC {
|
||||||
|
function addNumber(a:Int, b:Int):Int;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:build(macros.rpc.RPC.buildRPC(IExampleRPC))
|
||||||
|
class ExampleRPC extends RPCBase {}
|
||||||
|
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Example SRV", ["example-srv"]))
|
||||||
|
class ExampleService implements IProcess implements IExampleRPC {
|
||||||
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function run(handle:ProcessHandle) {
|
||||||
|
this.handle = handle;
|
||||||
|
|
||||||
|
kernel.net.Net.registerProto("example", (pack) -> {
|
||||||
|
ExampleRPC.handlePackage(this, pack);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addNumber(a:Int, b:Int):Int {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
var rpc = new ExampleRPC(12,"example");
|
||||||
|
|
||||||
|
rpc.addNumber(3,7).handle((p)->{
|
||||||
|
switch p {
|
||||||
|
case Success(r):
|
||||||
|
Log.info('3+7=$r');
|
||||||
|
case Failure(err):
|
||||||
|
Log.error('Error: $err');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
# Build system and flags
|
||||||
|
|
||||||
|
We use `make` to build the project. If you want a prod build just run `make` and if you want the debug build run `make debug`.
|
||||||
|
The `build` directory should contain all needed files.
|
||||||
|
|
||||||
|
- `bundle.min.lua`: The minified final file
|
||||||
|
- `bundle.polyfill.lua`: The same as above just not minified. use this when debugging.
|
||||||
|
- `haxe.lua`: Intermediate file. Polyfill not yet added.
|
||||||
|
- `haxe.zip`: The compressed `bundle.min.lua`.
|
||||||
|
- `unpack.*`: Same as the bundle files. Used to unpack and run the `haxe.zip` file.
|
||||||
|
|
||||||
|
The follwing haxe flags can be used in the code or can be set in the makefile.
|
||||||
|
|
||||||
|
- `debug`: Is set when debug
|
||||||
|
- `kv_use_native`: If set use the native CC serialize and unserialize functions instead of the Haxe ones. See [KVStore.hx](../src/lib/KVStore.hx) for more.
|
||||||
|
|
||||||
|
# Applications
|
||||||
|
|
||||||
|
If you want to make an application you just need to create a class that implements IProcess and and has no arguments in the constructor.
|
||||||
|
In order to have the programm available from the terminal you need to add the `Binstore.includeBin` macro for the class. Here is an example:
|
||||||
|
|
||||||
|
```haxe
|
||||||
|
@:build(macros.Binstore.includeBin("HelloWorld", ["hello", "helloworld"]))
|
||||||
|
class HelloWorld implements IProcess {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function run(handle:ProcessHandle) {
|
||||||
|
handle.writeLine("Hello World");
|
||||||
|
handle.close(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Let's break this down:
|
||||||
|
|
||||||
|
- The `includeBin` macro is required to automaticly inlcude the app and to defeat the DCE optimisation. In early versions refections were used but DCE did not like that
|
||||||
|
- The first argument on `includeBin` is the name of the app. Only ever used in displaying.
|
||||||
|
- The second argument are the aliases. These are used to call the app from the terminal and other places
|
||||||
|
- The constructor can't have any arguments. It's also recommended to not do any major setup stuff in there.
|
||||||
|
- The `run` method is the entry point in the app.
|
||||||
|
- The handle is used to interact with the outside world. (theoretically at least)
|
||||||
|
- The `handle.close(true)` call is required to end a process. The app does not end when the run function is finished. The first arguments represents if the app was successfull.
|
||||||
|
|
||||||
|
|||||||
10
minify.js
10
minify.js
@@ -1,10 +0,0 @@
|
|||||||
const fs = require("fs");
|
|
||||||
const luamin = require("luamin");
|
|
||||||
|
|
||||||
const haxeOutput = fs.readFileSync(process.argv[2] ?? "build/Haxe.min.lua",{encoding:"utf8"});
|
|
||||||
|
|
||||||
const minified = luamin.minify(haxeOutput);
|
|
||||||
|
|
||||||
fs.writeFileSync(process.argv[3] ?? "build/Haxe.min.lua",minified);
|
|
||||||
|
|
||||||
console.log("minified lua");
|
|
||||||
35
package-lock.json
generated
Normal file
35
package-lock.json
generated
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "haxe",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "haxe",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"luamin": "^1.0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/luamin": {
|
||||||
|
"version": "1.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/luamin/-/luamin-1.0.4.tgz",
|
||||||
|
"integrity": "sha1-lEUptY/G+k0x6s4uA1PUEhDw49M= sha512-z1h0bclRD/QGsS/Dz4Skp9z0qPTmmm+IKcrCapGmdTczPWVdN9f9jk6WqkNrcifQr8+n9Pzsm9WkwpOH1JBUAQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"luaparse": "^0.2.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"luamin": "bin/luamin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/luaparse": {
|
||||||
|
"version": "0.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/luaparse/-/luaparse-0.2.1.tgz",
|
||||||
|
"integrity": "sha1-qo9WEysN6X0388mRqd9C4OF/ZWw= sha512-VKBcryd5nJte4ZNR29NOk8F/UkMipjeb4yoxcSS51z6QAzg9DXUC2WsfLniS0J1eh3pr/ZL3e9ha6V8fhoLbBQ==",
|
||||||
|
"bin": {
|
||||||
|
"luaparse": "bin/luaparse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
pre-commit.sh
Executable file
15
pre-commit.sh
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# Run:
|
||||||
|
# ln -s ../../pre-commit.sh .git/hooks/pre-commit
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# format
|
||||||
|
|
||||||
|
make format
|
||||||
|
git diff --name-only --cached --diff-filter=d | xargs -l git add
|
||||||
|
# build
|
||||||
|
|
||||||
|
make build
|
||||||
|
|
||||||
@@ -1,10 +1,29 @@
|
|||||||
|
import kernel.ui.WindowManager;
|
||||||
|
import kernel.ps.ProcessManager;
|
||||||
|
import kernel.binstore.BinStore;
|
||||||
|
import kernel.MainTerm;
|
||||||
import lib.HomeContext;
|
import lib.HomeContext;
|
||||||
|
|
||||||
class Startup {
|
class Startup {
|
||||||
public static function main() {
|
public static function main() {
|
||||||
var main = new HomeContext();
|
#if debug
|
||||||
|
var term = BinStore.instantiate("terminal");
|
||||||
|
var pid = ProcessManager.run(term, {
|
||||||
|
// args: ["debug"]
|
||||||
|
});
|
||||||
|
var ctx = WindowManager.getContextByPID(pid);
|
||||||
|
WindowManager.focusContextToOutput(ctx[0], "main");
|
||||||
|
#else
|
||||||
|
if (MainTerm.instance.isColor()) {
|
||||||
|
var main = new HomeContext();
|
||||||
|
|
||||||
main.run();
|
main.run();
|
||||||
|
} else {
|
||||||
|
var term = BinStore.instantiate("terminal");
|
||||||
|
var pid = ProcessManager.run(term, {});
|
||||||
|
var ctx = WindowManager.getContextByPID(pid);
|
||||||
|
WindowManager.focusContextToOutput(ctx[0], "main");
|
||||||
|
}
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
29
src/Unpack.hx
Normal file
29
src/Unpack.hx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import lua.Lua;
|
||||||
|
import haxe.io.Bytes;
|
||||||
|
import kernel.fs.FS;
|
||||||
|
import haxe.zip.Uncompress;
|
||||||
|
|
||||||
|
class Unpack {
|
||||||
|
public static function main() {
|
||||||
|
var filename = "/haxe.zip";
|
||||||
|
var handle = FS.openReadBinary(filename);
|
||||||
|
var size = FS.attributes(filename).size;
|
||||||
|
var data = Bytes.alloc(size);
|
||||||
|
|
||||||
|
for (i in 0...size) {
|
||||||
|
data.set(i, handle.readByte());
|
||||||
|
}
|
||||||
|
|
||||||
|
var uncompressed = Uncompress.run(data);
|
||||||
|
|
||||||
|
var res = Lua.load(uncompressed.toString()); // FIXME: Haxe is missing some parameters. This does not work.
|
||||||
|
|
||||||
|
var f = res.func; // Required for silly haxe bug.
|
||||||
|
|
||||||
|
if (res.message == null) {
|
||||||
|
f();
|
||||||
|
} else {
|
||||||
|
trace('Failed: ${res.message}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,28 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
|
import kernel.peripherals.Drive;
|
||||||
import lib.CLIAppBase;
|
import lib.CLIAppBase;
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
using Lambda;
|
using Lambda;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Disk", ["disk"]))
|
||||||
class Disk extends CLIAppBase {
|
class Disk extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("ls", (args)->{
|
registerSyncSubcommand("ls", (args) -> {
|
||||||
Peripheral.getAllDrives().foreach(drive -> {
|
Peripheral.getAllDrives().foreach(drive -> {
|
||||||
var addr = drive.getAddr();
|
var addr = drive.getAddr();
|
||||||
var label = drive.getDiskLabel();
|
var label = drive.getDiskLabel();
|
||||||
var id = drive.getDiskID();
|
var id = drive.getDiskID();
|
||||||
|
|
||||||
if (drive.isDiskPresent()){
|
if (drive.isDiskPresent()) {
|
||||||
if (drive.hasAudio()){
|
if (drive.hasAudio()) {
|
||||||
handle.writeLine('${addr} => ${label} [AUDIO]');
|
handle.writeLine('${addr} => ${label} [AUDIO]');
|
||||||
}else{
|
} else {
|
||||||
handle.writeLine('${addr} => ${label} (${id})');
|
handle.writeLine('${addr} => ${label} (${id})');
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
handle.writeLine('${addr} => [NO DISK]');
|
handle.writeLine('${addr} => [NO DISK]');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,100 +30,71 @@ class Disk extends CLIAppBase {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("play", (args)->{
|
registerSyncSubcommand("play", (args) -> {
|
||||||
if (args.length < 1){
|
return audioDiskPlayPause(args.getString("addr"), true);
|
||||||
handle.writeLine("Missing drive address");
|
}, [Peripheral("addr", Drive.TYPE_NAME)]);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return audioDiskPlayPause(args[0], true);
|
|
||||||
},"<drive>");
|
|
||||||
|
|
||||||
registerSyncSubcommand("stop", (args) -> {
|
registerSyncSubcommand("stop", (args) -> {
|
||||||
if (args.length < 1){
|
return audioDiskPlayPause(args.getString("addr"), false);
|
||||||
handle.writeLine("Missing drive address");
|
}, [Peripheral("addr", Drive.TYPE_NAME)]);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return audioDiskPlayPause(args[0], false);
|
registerSyncSubcommand("eject", (args) -> {
|
||||||
},"<drive>");
|
var driveAddr = args.getString("addr");
|
||||||
|
|
||||||
registerSyncSubcommand("eject", (args)->{
|
|
||||||
if (args.length < 1){
|
|
||||||
handle.writeLine("Missing drive address");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var driveAddr = args[0];
|
|
||||||
var drive = Peripheral.getDrive(driveAddr);
|
var drive = Peripheral.getDrive(driveAddr);
|
||||||
|
|
||||||
if (drive == null){
|
if (!drive.isDiskPresent()) {
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
handle.writeLine("No disk in drive: " + driveAddr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
drive.ejectDisk();
|
drive.ejectDisk();
|
||||||
return true;
|
return true;
|
||||||
},"<drive>");
|
}, [Peripheral("addr", Drive.TYPE_NAME)]);
|
||||||
|
|
||||||
registerSyncSubcommand("lable",(args) -> {
|
registerSyncSubcommand("label", (args) -> {
|
||||||
if (args.length < 1){
|
var driveAddr = args.getString("addr");
|
||||||
handle.writeLine("Missing drive address");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var driveAddr = args[0];
|
|
||||||
var drive = Peripheral.getDrive(driveAddr);
|
var drive = Peripheral.getDrive(driveAddr);
|
||||||
var label:String = args[1];
|
var label:Null<String> = args.getString("label");
|
||||||
|
|
||||||
if (drive == null){
|
if (!drive.isDiskPresent()) {
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
handle.writeLine("No disk in drive: " + driveAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (label == null || label == ""){
|
if (label == null || label == "") {
|
||||||
handle.writeLine(drive.getDiskLabel());
|
handle.writeLine(drive.getDiskLabel());
|
||||||
}else{
|
} else {
|
||||||
var err = drive.setDiskLabel(label);
|
var err = drive.setDiskLabel(label);
|
||||||
if (err != null){
|
if (err != null) {
|
||||||
handle.writeLine("Failed to set lable");
|
handle.writeLine("Failed to set lable");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},"<drive> [label]");
|
}, [Peripheral("addr", Drive.TYPE_NAME), Optional(String("label"))]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function audioDiskPlayPause(driveAddr: String, play: Bool): Bool {
|
private function audioDiskPlayPause(driveAddr:String, play:Bool):Bool {
|
||||||
var drive = Peripheral.getDrive(driveAddr);
|
var drive = Peripheral.getDrive(driveAddr);
|
||||||
|
|
||||||
if (drive == null){
|
if (drive == null) {
|
||||||
handle.writeLine("Drive not found: " + driveAddr);
|
handle.writeLine("Drive not found: " + driveAddr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!drive.isDiskPresent()){
|
if (!drive.isDiskPresent()) {
|
||||||
handle.writeLine("No disk in drive: " + driveAddr);
|
handle.writeLine("No disk in drive: " + driveAddr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!drive.hasAudio()){
|
if (!drive.hasAudio()) {
|
||||||
handle.writeLine("Disk in drive: " + driveAddr + " does not have audio");
|
handle.writeLine("Disk in drive: " + driveAddr + " does not have audio");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (play){
|
if (play) {
|
||||||
drive.playAudio();
|
drive.playAudio();
|
||||||
}else{
|
} else {
|
||||||
drive.stopAudio();
|
drive.stopAudio();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,26 +2,27 @@ package bin;
|
|||||||
|
|
||||||
import lib.CLIAppBase;
|
import lib.CLIAppBase;
|
||||||
import kernel.gps.INS;
|
import kernel.gps.INS;
|
||||||
import lib.Pos3;
|
import lib.WorldPos;
|
||||||
import lib.Vec.Vec3;
|
import lib.Vec.Vec3;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("GPS", ["gps"]))
|
||||||
class GPS extends CLIAppBase {
|
class GPS extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("set", (args)->{
|
registerSyncSubcommand("set", (args) -> {
|
||||||
var x: Float = Std.parseFloat(args[0]);
|
var x:Float = args.getFloat("x");
|
||||||
var y: Float = Std.parseFloat(args[1]);
|
var y:Float = args.getFloat("y");
|
||||||
var z: Float = Std.parseFloat(args[2]);
|
var z:Float = args.getFloat("z");
|
||||||
|
|
||||||
var pos: Pos3 = new Vec3<Float>(x, y, z);
|
|
||||||
|
|
||||||
kernel.gps.GPS.setManualPosition(pos);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},"<x> <y> <z>");
|
|
||||||
|
|
||||||
registerSyncSubcommand("status",(args)->{
|
var pos:WorldPos = new Vec3<Float>(x, y, z);
|
||||||
|
|
||||||
|
kernel.gps.GPS.setManualPosition(pos);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}, [Float("x"), Float("y"), Float("z")]);
|
||||||
|
|
||||||
|
registerSyncSubcommand("status", (args) -> {
|
||||||
var pos = kernel.gps.GPS.getPosition();
|
var pos = kernel.gps.GPS.getPosition();
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
||||||
@@ -29,39 +30,40 @@ class GPS extends CLIAppBase {
|
|||||||
handle.writeLine("Position not available");
|
handle.writeLine("Position not available");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc = kernel.gps.GPS.getAccuracy();
|
var acc = kernel.gps.GPS.getAccuracy();
|
||||||
if (acc == 1){
|
if (acc == 1) {
|
||||||
handle.writeLine("Accuracy: Low");
|
handle.writeLine("Accuracy: Low");
|
||||||
} else if (acc == 2){
|
} else if (acc == 2) {
|
||||||
handle.writeLine("Accuracy: Medium");
|
handle.writeLine("Accuracy: Medium");
|
||||||
} else if (acc == 3){
|
} else if (acc == 3) {
|
||||||
handle.writeLine("Accuracy: High");
|
handle.writeLine("Accuracy: High");
|
||||||
}
|
}
|
||||||
|
|
||||||
var ins = INS.getHeading();
|
var ins = INS.getHeading();
|
||||||
if (ins != null) {
|
if (ins != null) {
|
||||||
handle.writeLine('INS heading: ${ins.x} y:${ins.y} z:${ins.z}');
|
handle.writeLine('INS heading: ${ins.x} y:${ins.y} z:${ins.z}');
|
||||||
} else {
|
} else {
|
||||||
handle.writeLine("INS heading not available");
|
handle.writeLine("INS heading not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
registerAsyncSubcommand("locate",(args)->{
|
registerAsyncSubcommand("locate", (args) -> {
|
||||||
return kernel.gps.GPS.locate().map((pos)->{
|
return kernel.gps.GPS.locate().map((result) -> {
|
||||||
if (pos != null) {
|
switch result {
|
||||||
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
case Success(pos):
|
||||||
} else {
|
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
||||||
handle.writeLine("Position not available");
|
case Failure(err):
|
||||||
|
handle.writeLine("Position not available: " + err);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
registerAsyncSubcommand("ins",(args)->{
|
registerAsyncSubcommand("ins", (args) -> {
|
||||||
return INS.align().map((_)->{
|
return INS.align().map((_) -> {
|
||||||
handle.writeLine("INS aligned");
|
handle.writeLine("INS aligned");
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
package bin;
|
|
||||||
|
|
||||||
import kernel.log.Log;
|
|
||||||
import kernel.ps.ProcessHandle;
|
|
||||||
import kernel.ps.Process;
|
|
||||||
|
|
||||||
using tink.CoreApi;
|
|
||||||
|
|
||||||
class HelloWorld implements Process {
|
|
||||||
|
|
||||||
public function new() {}
|
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
|
||||||
handle.write("Hello World!");
|
|
||||||
|
|
||||||
var c = new HelloWorldServiceRPC(0);
|
|
||||||
|
|
||||||
c.getNumber().handle((res)->{
|
|
||||||
Log.debug("Got number: " + res);
|
|
||||||
});
|
|
||||||
|
|
||||||
handle.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package bin;
|
|
||||||
|
|
||||||
import macros.rpc.RPC;
|
|
||||||
import kernel.ps.ProcessHandle;
|
|
||||||
import kernel.ps.Process;
|
|
||||||
|
|
||||||
using tink.CoreApi;
|
|
||||||
|
|
||||||
@:build(macros.rpc.RPC.buildRPC())
|
|
||||||
class HelloWorldService implements Process {
|
|
||||||
private var handle:ProcessHandle;
|
|
||||||
|
|
||||||
public function new() {}
|
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
|
||||||
this.handle = handle;
|
|
||||||
|
|
||||||
RPC.generateRPCPackageHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
@rpc
|
|
||||||
public function getNumber():Int{
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
import kernel.ps.ProcessHandle;
|
import kernel.ps.ProcessHandle;
|
||||||
import kernel.ps.Process;
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
class ID implements Process {
|
@:build(macros.Binstore.includeBin("ID", ["id"]))
|
||||||
public function new() {}
|
class ID implements IProcess {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
public function run(handle:ProcessHandle) {
|
||||||
handle.writeLine("ID: " + kernel.net.Net.networkID);
|
handle.writeLine("ID: " + kernel.net.Net.networkID);
|
||||||
handle.close();
|
handle.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,65 +3,61 @@ package bin;
|
|||||||
import kernel.KernelSettings;
|
import kernel.KernelSettings;
|
||||||
import lib.CLIAppBase;
|
import lib.CLIAppBase;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Kernel settings", ["ksettings", "kset"]))
|
||||||
class KSettings extends CLIAppBase {
|
class KSettings extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("get", (args)->{
|
registerSyncSubcommand("get", (args) -> {
|
||||||
var key = args[0];
|
var key = args.getString("key");
|
||||||
|
|
||||||
if (key == null) {
|
var value = switch (key) {
|
||||||
handle.writeLine("Key not specified");
|
case "hostname":
|
||||||
return false;
|
KernelSettings.hostname;
|
||||||
}
|
case "nameServer":
|
||||||
|
Std.string(KernelSettings.nameServer);
|
||||||
|
default:
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
|
||||||
var value = switch (key){
|
if (value == null) {
|
||||||
case "hostname":
|
handle.writeLine("Key not found or not set");
|
||||||
KernelSettings.hostname;
|
return false;
|
||||||
case "sitecontroller":
|
}
|
||||||
Std.string(KernelSettings.siteController);
|
|
||||||
default:
|
|
||||||
null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value == null) {
|
handle.writeLine(value);
|
||||||
handle.writeLine("Key not found or not set");
|
return true;
|
||||||
return false;
|
}, [String("key")]);
|
||||||
}
|
|
||||||
|
|
||||||
handle.writeLine(value);
|
registerSyncSubcommand("set", (args) -> {
|
||||||
return true;
|
var key = args.getString("key");
|
||||||
}," <key>");
|
|
||||||
|
|
||||||
registerSyncSubcommand("set", (args)->{
|
if (key == null) {
|
||||||
var key = args[0];
|
handle.writeLine("Key not specified");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (key == null) {
|
var value = args.getString("value");
|
||||||
handle.writeLine("Key not specified");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var value = args[1];
|
if (value == null) {
|
||||||
|
handle.writeLine("Value not specified");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (value == null) {
|
switch (key) {
|
||||||
handle.writeLine("Value not specified");
|
case "hostname":
|
||||||
return false;
|
KernelSettings.hostname = value;
|
||||||
}
|
case "nameServer":
|
||||||
|
KernelSettings.nameServer = Std.parseInt(value);
|
||||||
|
default:
|
||||||
|
handle.writeLine("Key not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}, [String("key"), String("value")]);
|
||||||
|
|
||||||
switch (key){
|
registerSyncSubcommand("list", (args) -> {
|
||||||
case "hostname":
|
handle.writeLine("hostname");
|
||||||
KernelSettings.hostname = value;
|
handle.writeLine("nameServer");
|
||||||
case "sitecontroller":
|
return true;
|
||||||
KernelSettings.siteController = Std.parseInt(value);
|
});
|
||||||
default:
|
}
|
||||||
handle.writeLine("Key not found");
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}," <key> <value>");
|
|
||||||
|
|
||||||
registerSyncSubcommand("list", (args)->{
|
|
||||||
handle.writeLine("hostname");
|
|
||||||
handle.writeLine("sitecontroller");
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
import kernel.ps.ProcessHandle;
|
import kernel.ps.ProcessHandle;
|
||||||
import kernel.ps.Process;
|
import kernel.ps.IProcess;
|
||||||
import lib.Color;
|
import lib.Color;
|
||||||
import lib.MathI;
|
import lib.MathI;
|
||||||
import kernel.log.Log;
|
import kernel.log.Log;
|
||||||
import kernel.ui.WindowContext;
|
import kernel.ui.WindowContext;
|
||||||
import lib.ui.UIApp;
|
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class KernelLog implements Process {
|
@:build(macros.Binstore.includeBin("Log", ["log"]))
|
||||||
private var handle: ProcessHandle;
|
class KernelLog implements IProcess {
|
||||||
private var ctx: WindowContext;
|
private var handle:ProcessHandle;
|
||||||
|
private var ctx:WindowContext;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle: ProcessHandle):Void {
|
public function run(handle:ProcessHandle):Void {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
|
||||||
var statelessCtx = handle.createStatelessWindowContext();
|
var statelessCtx = handle.createStatelessWindowContext();
|
||||||
@@ -24,23 +24,23 @@ class KernelLog implements Process {
|
|||||||
|
|
||||||
statelessCtx.setRenderFunc(this.render);
|
statelessCtx.setRenderFunc(this.render);
|
||||||
|
|
||||||
Log.onLog.handle(()->{
|
Log.onLog.handle(() -> {
|
||||||
statelessCtx.requestRender();
|
statelessCtx.requestRender();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function render() {
|
private function render() {
|
||||||
ctx.clear();
|
ctx.clear();
|
||||||
ctx.setCursorPos(0,0);
|
ctx.setCursorPos(0, 0);
|
||||||
|
|
||||||
var lines = Log.getLines();
|
var lines = Log.getLines();
|
||||||
var height = ctx.getSize().y;
|
var height = ctx.getSize().y;
|
||||||
var start = MathI.max(lines.length - height,0);
|
var start = MathI.max(lines.length - height, 0);
|
||||||
|
|
||||||
for (i in start...lines.length) {
|
for (i in start...lines.length) {
|
||||||
var line = lines[i];
|
var line = lines[i];
|
||||||
|
|
||||||
switch (line.level){
|
switch (line.level) {
|
||||||
case Info:
|
case Info:
|
||||||
ctx.setTextColor(Color.White);
|
ctx.setTextColor(Color.White);
|
||||||
ctx.write("[INFO] ");
|
ctx.write("[INFO] ");
|
||||||
@@ -59,7 +59,7 @@ class KernelLog implements Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.write(line.message);
|
ctx.write(line.message);
|
||||||
ctx.setCursorPos(0,ctx.getCursorPos().y + 1);
|
ctx.setCursorPos(0, ctx.getCursorPos().y + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,21 @@ package bin;
|
|||||||
|
|
||||||
import kernel.ps.ProcessManager;
|
import kernel.ps.ProcessManager;
|
||||||
import kernel.ps.ProcessHandle;
|
import kernel.ps.ProcessHandle;
|
||||||
import kernel.ps.Process;
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
class LSPS implements Process {
|
@:build(macros.Binstore.includeBin("LSPS", ["lsps"]))
|
||||||
public function new() {}
|
class LSPS implements IProcess {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
public function run(handle:ProcessHandle) {
|
||||||
var pids = ProcessManager.listProcesses();
|
var pids = ProcessManager.listProcesses();
|
||||||
|
|
||||||
handle.writeLine('Count: ${pids.length}');
|
handle.writeLine('Count: ${pids.length}');
|
||||||
|
|
||||||
for (pid in pids) {
|
for (pid in pids) {
|
||||||
handle.writeLine('${pid}');
|
handle.writeLine('${pid}');
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.close();
|
handle.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,19 +6,20 @@ import kernel.net.Routing;
|
|||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Net", ["net"]))
|
||||||
class Net extends CLIAppBase {
|
class Net extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("route", (args)->{
|
registerSyncSubcommand("route", (args) -> {
|
||||||
var routes = Routing.getRouteTable();
|
var routes = Routing.getRouteTable();
|
||||||
|
|
||||||
for(k => v in routes) {
|
for (k => v in routes) {
|
||||||
handle.writeLine('${k} => ${v.interf.name()}(${v.cost})');
|
handle.writeLine('${k} => ${v.interf.name()}(${v.cost})');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("iface", (args)->{
|
registerSyncSubcommand("iface", (args) -> {
|
||||||
var modems = Peripheral.getAllModems();
|
var modems = Peripheral.getAllModems();
|
||||||
|
|
||||||
for (modem in modems) {
|
for (modem in modems) {
|
||||||
@@ -28,7 +29,7 @@ class Net extends CLIAppBase {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
registerSyncSubcommand("proto",(args)->{
|
registerSyncSubcommand("proto", (args) -> {
|
||||||
var protos = kernel.net.Net.getActiveProtocols();
|
var protos = kernel.net.Net.getActiveProtocols();
|
||||||
|
|
||||||
for (proto in protos) {
|
for (proto in protos) {
|
||||||
@@ -38,20 +39,11 @@ class Net extends CLIAppBase {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
registerAsyncSubcommand("ping",(args)->{
|
registerAsyncSubcommand("ping", (args) -> {
|
||||||
if (args.length < 1) {
|
var toID:Int = args.getInt("id");
|
||||||
return Future.sync(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
var toID:Null<Int> = Std.parseInt(args[0]);
|
|
||||||
|
|
||||||
if (toID == null) {
|
|
||||||
handle.write("Invalid ID");
|
|
||||||
return Future.sync(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return kernel.net.Net.ping(toID).map(result -> {
|
return kernel.net.Net.ping(toID).map(result -> {
|
||||||
switch (result){
|
switch (result) {
|
||||||
case Success(_):
|
case Success(_):
|
||||||
handle.write("Ping succeeded");
|
handle.write("Ping succeeded");
|
||||||
case Failure(failure):
|
case Failure(failure):
|
||||||
@@ -60,6 +52,6 @@ class Net extends CLIAppBase {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
},"<id>");
|
}, [Int("id")]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package bin;
|
|
||||||
|
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
|
||||||
import lib.CLIAppBase;
|
|
||||||
|
|
||||||
class Perf extends CLIAppBase {
|
|
||||||
public function new() {
|
|
||||||
registerSyncSubcommand("inspect",(args)->{
|
|
||||||
if (args.length < 1) return false;
|
|
||||||
|
|
||||||
var result = Peripheral.inspect(args[0]);
|
|
||||||
|
|
||||||
if (result == null){
|
|
||||||
handle.writeLine("No peripheral found on side "+args[0]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
handle.writeLine("Types:");
|
|
||||||
for (type in result.types){
|
|
||||||
handle.writeLine(" "+type);
|
|
||||||
}
|
|
||||||
|
|
||||||
handle.writeLine("Methods:");
|
|
||||||
for (method in result.methods){
|
|
||||||
handle.writeLine(" "+method);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},"<side>");
|
|
||||||
|
|
||||||
registerSyncSubcommand("list",(args)->{
|
|
||||||
for (addr in Peripheral.getAllAddresses()){
|
|
||||||
handle.writeLine('$addr => ${Peripheral.getTypes(addr).join(", ")}');
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
33
src/bin/Peri.hx
Normal file
33
src/bin/Peri.hx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package bin;
|
||||||
|
|
||||||
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
|
import lib.CLIAppBase;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Peripheral", ["ph", "peripheral"]))
|
||||||
|
class Peri extends CLIAppBase {
|
||||||
|
public function new() {
|
||||||
|
registerSyncSubcommand("inspect", (args) -> {
|
||||||
|
var addr = args.getString("addr");
|
||||||
|
var result = Peripheral.inspect(addr);
|
||||||
|
|
||||||
|
handle.writeLine("Types:");
|
||||||
|
for (type in result.types) {
|
||||||
|
handle.writeLine(" " + type);
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.writeLine("Methods:");
|
||||||
|
for (method in result.methods) {
|
||||||
|
handle.writeLine(" " + method);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}, [Addr("addr")]);
|
||||||
|
|
||||||
|
registerSyncSubcommand("list", (args) -> {
|
||||||
|
for (addr in Peripheral.getAllAddresses()) {
|
||||||
|
handle.writeLine('$addr => ${Peripheral.getTypes(addr).join(", ")}');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,22 +5,23 @@ import kernel.peripherals.Peripherals.Peripheral;
|
|||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Redstone extends CLIAppBase{
|
@:build(macros.Binstore.includeBin("Redstone", ["redstone", "rs"]))
|
||||||
|
class Redstone extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("on", (args)-> {
|
registerSyncSubcommand("on", (args) -> {
|
||||||
Peripheral.getRedstone(args[0]).setOutput(true);
|
Peripheral.getRedstone(args.getString("side")).setOutput(true);
|
||||||
return true;
|
return true;
|
||||||
},"<side>");
|
}, [Side("side")]);
|
||||||
|
|
||||||
registerSyncSubcommand("off", (args)-> {
|
registerSyncSubcommand("off", (args) -> {
|
||||||
Peripheral.getRedstone(args[0]).setOutput(false);
|
Peripheral.getRedstone(args.getString("side")).setOutput(false);
|
||||||
return true;
|
return true;
|
||||||
},"<side>");
|
}, [Side("side")]);
|
||||||
|
|
||||||
registerSyncSubcommand("get", (args)-> {
|
registerSyncSubcommand("get", (args) -> {
|
||||||
var value = Peripheral.getRedstone(args[0]).getAnalogInput();
|
var value = Peripheral.getRedstone(args.getString("side")).getAnalogInput();
|
||||||
handle.write("Analog input: " + value);
|
handle.write("Analog input: " + value);
|
||||||
return true;
|
return true;
|
||||||
},"<side>");
|
}, [Side("side")]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,82 +5,56 @@ import lib.CLIAppBase;
|
|||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Service", ["srv"]))
|
||||||
class Service extends CLIAppBase {
|
class Service extends CLIAppBase {
|
||||||
public function new() {
|
public function new() {
|
||||||
registerSyncSubcommand("start", (args) ->{
|
registerSyncSubcommand("start", (args) -> {
|
||||||
if (args.length < 1) {
|
var result = ServiceManager.start(args.getString("name"));
|
||||||
return false;
|
return handleResult(result);
|
||||||
}
|
}, [String("name")]);
|
||||||
|
|
||||||
var name = args[0];
|
registerSyncSubcommand("stop", (args) -> {
|
||||||
|
var result = ServiceManager.stop(args.getString("name"));
|
||||||
|
return handleResult(result);
|
||||||
|
}, [String("name")]);
|
||||||
|
|
||||||
var result = ServiceManager.start(name);
|
registerSyncSubcommand("register", (args) -> {
|
||||||
return handleResult(result);
|
var name = args.getString("name");
|
||||||
},"<name>");
|
var binName = args.getString("binary");
|
||||||
|
var rest = args.getRest();
|
||||||
|
|
||||||
registerSyncSubcommand("stop", (args) ->{
|
var result = ServiceManager.register(name, binName, rest);
|
||||||
if (args.length < 1) {
|
return handleResult(result);
|
||||||
return false;
|
}, [String("name"), String("binary"), Rest("args")]);
|
||||||
}
|
|
||||||
|
|
||||||
var name = args[0];
|
registerSyncSubcommand("unregister", (args) -> {
|
||||||
|
var result = ServiceManager.unregister(args.getString("name"));
|
||||||
|
return handleResult(result);
|
||||||
|
}, [String("name")]);
|
||||||
|
|
||||||
var result = ServiceManager.stop(name);
|
registerSyncSubcommand("list", (args) -> {
|
||||||
return handleResult(result);
|
var list = ServiceManager.listRunning();
|
||||||
},"<name>");
|
|
||||||
|
|
||||||
registerSyncSubcommand("register", (args) ->{
|
for (name in list) {
|
||||||
if (args.length < 2) {
|
this.handle.writeLine(name);
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var name = args[0];
|
return true;
|
||||||
var binName = args[1];
|
});
|
||||||
var rest = args.slice(2);
|
|
||||||
|
|
||||||
var result = ServiceManager.register(name, binName, rest);
|
registerSyncSubcommand("enable", (args) -> {
|
||||||
return handleResult(result);
|
ServiceManager.enable(args.getString("name"));
|
||||||
},"<name> <binary> [args...]");
|
return true;
|
||||||
|
}, [String("name")]);
|
||||||
|
}
|
||||||
|
|
||||||
registerSyncSubcommand("unregister", (args) ->{
|
private function handleResult(res:Outcome<Noise, String>):Bool {
|
||||||
if (args.length < 2) {
|
switch (res) {
|
||||||
return false;
|
case Success(_):
|
||||||
}
|
return true;
|
||||||
|
case Failure(e):
|
||||||
var name = args[0];
|
this.handle.write(e);
|
||||||
|
return false;
|
||||||
var result = ServiceManager.unregister(name);
|
}
|
||||||
return handleResult(result);
|
}
|
||||||
},"<name>");
|
}
|
||||||
|
|
||||||
registerSyncSubcommand("list", (args) ->{
|
|
||||||
|
|
||||||
var list = ServiceManager.listRunning();
|
|
||||||
|
|
||||||
for (name in list) {
|
|
||||||
this.handle.writeLine(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
registerSyncSubcommand("enable", (args) ->{
|
|
||||||
if (args.length < 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceManager.enable(args[0]);
|
|
||||||
return true;
|
|
||||||
},"<name>");
|
|
||||||
}
|
|
||||||
|
|
||||||
private function handleResult(res: Outcome<Noise,String>): Bool {
|
|
||||||
switch (res) {
|
|
||||||
case Success(_):
|
|
||||||
return true;
|
|
||||||
case Failure(e):
|
|
||||||
this.handle.write(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
71
src/bin/Speaker.hx
Normal file
71
src/bin/Speaker.hx
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package bin;
|
||||||
|
|
||||||
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
|
import lib.CLIAppBase;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Speaker", ["speaker", "sp"]))
|
||||||
|
class Speaker extends CLIAppBase {
|
||||||
|
public function new() {
|
||||||
|
registerSyncSubcommand("note", (args) -> {
|
||||||
|
var sp = Peripheral.getSpeaker(args.getString("addr"));
|
||||||
|
|
||||||
|
var note = args.getString("note");
|
||||||
|
var r;
|
||||||
|
|
||||||
|
if (args.hasArg("pitch")) {
|
||||||
|
if (args.hasArg("volume")) {
|
||||||
|
r = sp.playNote(note, args.getFloat("volume"), args.getInt("pitch"));
|
||||||
|
} else {
|
||||||
|
r = sp.playNote(note, args.getFloat("volume"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
r = sp.playNote(note);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch r {
|
||||||
|
case Failure(failure):
|
||||||
|
handle.writeLine(failure);
|
||||||
|
return false;
|
||||||
|
case Success(_):
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
Peripheral("addr", kernel.peripherals.Speaker.TYPE_NAME),
|
||||||
|
String("note"),
|
||||||
|
Optional(Int("pitch")),
|
||||||
|
Optional(Float("volume"))
|
||||||
|
]);
|
||||||
|
|
||||||
|
registerSyncSubcommand("sound", (args) -> {
|
||||||
|
var sp = Peripheral.getSpeaker(args.getString("addr"));
|
||||||
|
|
||||||
|
var sound = args.getString("sound");
|
||||||
|
var r;
|
||||||
|
|
||||||
|
if (args.hasArg("volume")) {
|
||||||
|
if (args.hasArg("pitch")) {
|
||||||
|
r = sp.playSound(sound, args.getFloat("volume"), args.getFloat("pitch"));
|
||||||
|
} else {
|
||||||
|
r = sp.playSound(sound, args.getFloat("volume"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
r = sp.playSound(sound);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch r {
|
||||||
|
case Failure(failure):
|
||||||
|
handle.writeLine(failure);
|
||||||
|
return false;
|
||||||
|
case Success(_):
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
Peripheral("addr", kernel.peripherals.Speaker.TYPE_NAME),
|
||||||
|
String("sound"),
|
||||||
|
Optional(Float("pitch")),
|
||||||
|
Optional(Float("volume"))
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +1,38 @@
|
|||||||
package bin;
|
package bin;
|
||||||
|
|
||||||
|
import lib.MathI;
|
||||||
|
import kernel.EndOfLoop;
|
||||||
|
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.IProcess;
|
||||||
import kernel.ps.ProcessManager;
|
import kernel.ps.ProcessManager;
|
||||||
import lib.Color;
|
import lib.Color;
|
||||||
import kernel.ui.WindowContext;
|
import kernel.ui.WindowContext;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Terminal implements Process {
|
@:build(macros.Binstore.includeBin("Terminal", ["terminal"]))
|
||||||
|
class Terminal implements IProcess {
|
||||||
private static inline final MAX_BACKLOG:Int = 100;
|
private static inline final MAX_BACKLOG:Int = 100;
|
||||||
|
|
||||||
private var handle:ProcessHandle;
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
private var ctx:WindowContext;
|
private var ctx:WindowContext;
|
||||||
private var requestRender: () -> Void;
|
private var requestRender:() -> Void;
|
||||||
|
|
||||||
private var input:String = "";
|
private var input:String = "";
|
||||||
private var backlog:Array<String> = [];
|
private var backlog:Array<String> = [];
|
||||||
private var history:Array<String> = [];
|
private var history:Array<String> = [];
|
||||||
private var historyIndex:Int = 0;
|
private var historyIndex:Int = 0;
|
||||||
|
|
||||||
private var runningPID:PID = -1;
|
private var scrollBack = 0;
|
||||||
|
|
||||||
|
private var runningPID:PID = -1;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle: ProcessHandle): Void {
|
public function run(handle:ProcessHandle):Void {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
|
||||||
var statelessContext = handle.createStatelessWindowContext();
|
var statelessContext = handle.createStatelessWindowContext();
|
||||||
@@ -38,7 +44,8 @@ class Terminal implements Process {
|
|||||||
|
|
||||||
// Add input event handlers
|
// Add input event handlers
|
||||||
handle.addCallbackLink(this.ctx.onChar.handle(char -> {
|
handle.addCallbackLink(this.ctx.onChar.handle(char -> {
|
||||||
if (this.runningPID > 0) return;
|
if (this.runningPID > 0)
|
||||||
|
return;
|
||||||
this.input += char;
|
this.input += char;
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
}));
|
}));
|
||||||
@@ -47,14 +54,19 @@ class Terminal implements Process {
|
|||||||
handle.addCallbackLink(this.ctx.onKey.handle(e -> {
|
handle.addCallbackLink(this.ctx.onKey.handle(e -> {
|
||||||
switch (e.keyCode) {
|
switch (e.keyCode) {
|
||||||
case 259: // Backspace
|
case 259: // Backspace
|
||||||
if (this.runningPID > 0) return;
|
if (this.runningPID > 0)
|
||||||
|
return;
|
||||||
this.input = this.input.substr(0, this.input.length - 1);
|
this.input = this.input.substr(0, this.input.length - 1);
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
case 257: // Enter
|
case 257: // Enter
|
||||||
if (this.runningPID > 0) return;
|
if (this.runningPID > 0)
|
||||||
|
return;
|
||||||
this.backlog.push("> " + this.input);
|
this.backlog.push("> " + this.input);
|
||||||
|
this.backlog.push("");
|
||||||
|
|
||||||
var command = this.input;
|
var command = this.input;
|
||||||
this.input = "";
|
this.input = "";
|
||||||
|
this.scrollBack = 0;
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
this.historyIndex = 0;
|
this.historyIndex = 0;
|
||||||
this.invokeCommand(command);
|
this.invokeCommand(command);
|
||||||
@@ -66,10 +78,27 @@ class Terminal implements Process {
|
|||||||
this.input = this.history[this.history.length - this.historyIndex];
|
this.input = this.history[this.history.length - this.historyIndex];
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
}
|
}
|
||||||
|
case 266: // PAGE UP
|
||||||
|
this.scrollBack = MathI.min(scrollBack + 1, this.backlog.length - 1);
|
||||||
|
this.requestRender();
|
||||||
|
case 267: // PAGE DOWN
|
||||||
|
this.scrollBack = MathI.max(scrollBack - 1, 0);
|
||||||
|
this.requestRender();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
|
|
||||||
|
if (handle.args.length > 0) {
|
||||||
|
var arg1 = handle.args[0];
|
||||||
|
|
||||||
|
this.backlog.push("> " + arg1);
|
||||||
|
this.backlog.push("");
|
||||||
|
|
||||||
|
EndOfLoop.endOfLoop(() -> {
|
||||||
|
this.invokeCommand(arg1);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function stopCurrentPS() {
|
private function stopCurrentPS() {
|
||||||
@@ -84,7 +113,8 @@ class Terminal implements Process {
|
|||||||
var size = this.ctx.getSize();
|
var size = this.ctx.getSize();
|
||||||
var linesAvailable = size.y - 1;
|
var linesAvailable = size.y - 1;
|
||||||
|
|
||||||
var start:Int = this.backlog.length - linesAvailable;
|
var withoutScrollBack = (this.backlog.length - linesAvailable);
|
||||||
|
var start:Int = withoutScrollBack - scrollBack;
|
||||||
|
|
||||||
for (i in 0...linesAvailable) {
|
for (i in 0...linesAvailable) {
|
||||||
var line = this.backlog[start + i];
|
var line = this.backlog[start + i];
|
||||||
@@ -136,41 +166,31 @@ 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 = BinStore.instantiate(commandName);
|
||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
this.backlog.push("Unknown command: " + commandName);
|
this.backlog.push("Unknown command: " + commandName);
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.runningPID = ProcessManager.run(ps,{
|
this.runningPID = ProcessManager.run(ps, {
|
||||||
args: commandArgs,
|
args: commandArgs,
|
||||||
onWrite: (s:String) -> {
|
onWrite: (s:String) -> {
|
||||||
if (s == "") {
|
if (s == "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hadInput) {
|
var splits = s.split("\n");
|
||||||
// Add a new line, so that the input is not on the same line as the command
|
|
||||||
this.backlog.push("");
|
|
||||||
hadInput = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (line in s.split("\n")) {
|
for (i => split in splits) {
|
||||||
if (line == ""){
|
if (i == 0) {
|
||||||
this.backlog.push("");
|
this.backlog[this.backlog.length - 1] += split;
|
||||||
} else {
|
} else {
|
||||||
this.backlog[this.backlog.length - 1] += s;
|
this.backlog.push(split);
|
||||||
}
|
|
||||||
|
|
||||||
// Trim the backlog if it's too long
|
|
||||||
if (this.backlog.length > MAX_BACKLOG) {
|
|
||||||
this.backlog.shift();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
},
|
},
|
||||||
onExit: (success:Bool) -> {
|
onExit: (success:Bool) -> {
|
||||||
@@ -199,15 +219,6 @@ class Terminal implements Process {
|
|||||||
this.requestRender();
|
this.requestRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getProgByName(name:String):Process {
|
|
||||||
var bin = BinStore.getBinByAlias(name);
|
|
||||||
if (bin == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Type.createInstance(bin.c,[]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function moveCursorToInput() {
|
private function moveCursorToInput() {
|
||||||
var size = this.ctx.getSize();
|
var size = this.ctx.getSize();
|
||||||
this.ctx.setCursorPos(this.input.length + 2, size.y - 1);
|
this.ctx.setCursorPos(this.input.length + 2, size.y - 1);
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
package bin;
|
|
||||||
|
|
||||||
import lib.CLIAppBase;
|
|
||||||
|
|
||||||
using tink.CoreApi;
|
|
||||||
|
|
||||||
class Turtle extends CLIAppBase {
|
|
||||||
public function new() {
|
|
||||||
registerSyncSubcommand("forward", (args)->{
|
|
||||||
return perform(kernel.turtle.Turtle.instance.forward());
|
|
||||||
});
|
|
||||||
|
|
||||||
registerSyncSubcommand("back", (args)->{
|
|
||||||
return perform(kernel.turtle.Turtle.instance.back());
|
|
||||||
});
|
|
||||||
|
|
||||||
registerSyncSubcommand("left", (args)->{
|
|
||||||
return perform(kernel.turtle.Turtle.instance.turnLeft());
|
|
||||||
});
|
|
||||||
|
|
||||||
registerSyncSubcommand("right", (args)->{
|
|
||||||
return perform(kernel.turtle.Turtle.instance.turnRight());
|
|
||||||
});
|
|
||||||
|
|
||||||
registerSyncSubcommand("up", (args)->{
|
|
||||||
return perform(kernel.turtle.Turtle.instance.up());
|
|
||||||
});
|
|
||||||
|
|
||||||
registerSyncSubcommand("down", (args)->{
|
|
||||||
return perform(kernel.turtle.Turtle.instance.down());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function perform(outcome: Outcome<Noise,String>): Bool {
|
|
||||||
switch outcome {
|
|
||||||
case Success(_):
|
|
||||||
return true;
|
|
||||||
case Failure(error):
|
|
||||||
handle.write(error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
180
src/bin/TurtleCtl.hx
Normal file
180
src/bin/TurtleCtl.hx
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
package bin;
|
||||||
|
|
||||||
|
import kernel.turtle.Types.ToolSide;
|
||||||
|
import lib.turtle.Helper;
|
||||||
|
import kernel.turtle.TurtleMutex;
|
||||||
|
import kernel.turtle.Turtle;
|
||||||
|
import lib.turtle.InvManager;
|
||||||
|
import lib.CLIAppBase;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Turtle", ["turtle", "t"]))
|
||||||
|
class TurtleCtl extends CLIAppBase {
|
||||||
|
public function new() {
|
||||||
|
registerAsyncSubcommand("f", (args) -> {
|
||||||
|
return asynPerform(Turtle.forward, args.getInt("times") ?? 1);
|
||||||
|
}, [Optional(Int("times"))]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("b", (args) -> {
|
||||||
|
return asynPerform(Turtle.back, args.getInt("times") ?? 1);
|
||||||
|
}, [Optional(Int("times"))]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("l", (args) -> {
|
||||||
|
return asynPerform(Turtle.turnLeft, args.getInt("times") ?? 1);
|
||||||
|
}, [Optional(Int("times"))]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("r", (args) -> {
|
||||||
|
return asynPerform(Turtle.turnRight, args.getInt("times") ?? 1);
|
||||||
|
}, [Optional(Int("times"))]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("u", (args) -> {
|
||||||
|
return asynPerform(Turtle.up, args.getInt("times") ?? 1);
|
||||||
|
}, [Optional(Int("times"))]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("d", (args) -> {
|
||||||
|
return asynPerform(Turtle.down, args.getInt("times") ?? 1);
|
||||||
|
}, [Optional(Int("times"))]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("defrag", (args) -> {
|
||||||
|
return asynPerform(() -> {
|
||||||
|
// TODO: when defrag can fail return that error
|
||||||
|
InvManager.defrag();
|
||||||
|
return Success(null);
|
||||||
|
}, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSyncSubcommand("fuel", (args) -> {
|
||||||
|
var lvl = Turtle.getFuelLevel();
|
||||||
|
var limit = Turtle.getFuelLimit();
|
||||||
|
handle.writeLine('${lvl}/${limit} (${(lvl / limit) * 100}%)');
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
registerAsyncSubcommand("fuel-sources", (args) -> {
|
||||||
|
return asynPerform(() -> {
|
||||||
|
var items = InvManager.getCombustableItems();
|
||||||
|
|
||||||
|
for (i in items) {
|
||||||
|
handle.writeLine(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Success(null);
|
||||||
|
}, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
registerAsyncSubcommand("refuel", (args) -> {
|
||||||
|
var refuelTo = Turtle.getFuelLimit();
|
||||||
|
var arg = args.getString("to");
|
||||||
|
if (arg != null) {
|
||||||
|
var split = arg.split("%");
|
||||||
|
|
||||||
|
if (split.length > 1) {
|
||||||
|
// Is percentage
|
||||||
|
var parsed = Std.parseFloat(split[0]);
|
||||||
|
|
||||||
|
if (parsed == null) {
|
||||||
|
handle.writeLine("Failed to parse ammount");
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
refuelTo = Math.round(refuelTo * (parsed / 100));
|
||||||
|
} else {
|
||||||
|
// Is absolute
|
||||||
|
var parsed = Std.parseInt(arg);
|
||||||
|
|
||||||
|
if (parsed == null) {
|
||||||
|
handle.writeLine("Failed to parse ammount");
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
refuelTo = parsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return asynPerform(() -> {
|
||||||
|
InvManager.refuel(refuelTo, []);
|
||||||
|
|
||||||
|
return Success(null);
|
||||||
|
}, 1);
|
||||||
|
}, [Optional(String("to"))]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("dig", (args) -> {
|
||||||
|
var direction = args.getString("direction");
|
||||||
|
switch (direction) {
|
||||||
|
case "front" | "f":
|
||||||
|
return asynPerform(() -> Turtle.dig(Front), 1);
|
||||||
|
case "top" | "t" | "up" | "u":
|
||||||
|
return asynPerform(() -> Turtle.dig(Up), 1);
|
||||||
|
case "bot" | "bottom" | "b" | "down" | "d":
|
||||||
|
return asynPerform(() -> Turtle.dig(Down), 1);
|
||||||
|
default:
|
||||||
|
return Future.sync(false);
|
||||||
|
}
|
||||||
|
}, [String("direction")]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("tunnel", (args) -> {
|
||||||
|
var len = args.getInt("length");
|
||||||
|
return asynPerform(Helper.combine.bind([Turtle.digEmpty.bind(Front), Turtle.forward, Turtle.digEmpty.bind(Up)]), len);
|
||||||
|
}, [Int("length")]);
|
||||||
|
|
||||||
|
registerSyncSubcommand("inspect", (args) -> {
|
||||||
|
var res = Turtle.inspect(Front);
|
||||||
|
|
||||||
|
switch res {
|
||||||
|
case Failure(err):
|
||||||
|
handle.writeLine("Failed: " + err);
|
||||||
|
return false;
|
||||||
|
case Success(data):
|
||||||
|
handle.writeLine('Name: ${data.name}');
|
||||||
|
handle.writeLine("Tags:");
|
||||||
|
|
||||||
|
for (tag in data.tags.sortByName()) {
|
||||||
|
handle.writeLine(' ${tag}');
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.writeLine("State:");
|
||||||
|
handle.writeLine(data.state);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function asynPerform(op:Void->Outcome<Noise, String>, times:Int):Future<Bool> {
|
||||||
|
return new Future<Bool>((wakeup) -> {
|
||||||
|
if (times == 0) {
|
||||||
|
wakeup(false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Turtle.isTurtle()) {
|
||||||
|
handle.write("This is not a turtle!");
|
||||||
|
wakeup(false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!handle.claimTurtleMutex()) {
|
||||||
|
handle.writeLine("Failed to claim mutex");
|
||||||
|
wakeup(false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
TurtleMutex.runInTThread(() -> {
|
||||||
|
for (i in 0...times) {
|
||||||
|
switch op() {
|
||||||
|
case Success(_):
|
||||||
|
case Failure(failure):
|
||||||
|
handle.writeLine('Failed: $failure');
|
||||||
|
wakeup(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wakeup(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
41
src/bin/debug/Debug.hx
Normal file
41
src/bin/debug/Debug.hx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package bin.debug;
|
||||||
|
|
||||||
|
import kernel.log.Log;
|
||||||
|
import lib.turtle.InvManager;
|
||||||
|
import kernel.ps.ProcessHandle;
|
||||||
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use this to test whatever you are working on. It will also print debug statements.
|
||||||
|
IDK if you commit changes in this file. It will not be included in non debug build.
|
||||||
|
**/
|
||||||
|
#if debug
|
||||||
|
@:build(macros.Binstore.includeBin("Debug", ["dbg", "debug"]))
|
||||||
|
#end
|
||||||
|
class Debug implements IProcess {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function run(handle:ProcessHandle) {
|
||||||
|
var link = Log.onLog.handle((line) -> {
|
||||||
|
handle.writeLine('[${line.level}] ${line.message}');
|
||||||
|
});
|
||||||
|
|
||||||
|
handle.addDeferFunc(() -> {
|
||||||
|
link.cancel();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add your stuff here
|
||||||
|
// -----
|
||||||
|
|
||||||
|
var rpc = new bin.debug.DebugRPC.DebugRPCImpl(1, "debug");
|
||||||
|
|
||||||
|
var a = rpc.addNumber(1, 2);
|
||||||
|
|
||||||
|
// rpc.addNumber(1,2).handle((e)->{
|
||||||
|
// Log.debug(e);
|
||||||
|
// handle.close();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// -----
|
||||||
|
}
|
||||||
|
}
|
||||||
10
src/bin/debug/DebugRPC.hx
Normal file
10
src/bin/debug/DebugRPC.hx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package bin.debug;
|
||||||
|
|
||||||
|
import macros.rpc.RPCBase;
|
||||||
|
|
||||||
|
interface DebugRPC {
|
||||||
|
function addNumber(a:Int, b:Int):Int;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:build(macros.rpc.RPC.buildRPC(DebugRPC))
|
||||||
|
class DebugRPCImpl extends RPCBase {}
|
||||||
27
src/bin/debug/DebugService.hx
Normal file
27
src/bin/debug/DebugService.hx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package bin.debug;
|
||||||
|
|
||||||
|
import bin.debug.DebugRPC.DebugRPCImpl;
|
||||||
|
import macros.rpc.RPC;
|
||||||
|
import kernel.ps.ProcessHandle;
|
||||||
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
|
#if debug
|
||||||
|
@:build(macros.Binstore.includeBin("Debug SRV", ["dbg-srv", "debug-srv"]))
|
||||||
|
#end
|
||||||
|
class DebugService implements IProcess implements DebugRPC {
|
||||||
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function run(handle:ProcessHandle) {
|
||||||
|
this.handle = handle;
|
||||||
|
|
||||||
|
kernel.net.Net.registerProto("debug", (pack) -> {
|
||||||
|
DebugRPCImpl.handlePackage(this, pack);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addNumber(a:Int, b:Int):Int {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
}
|
||||||
67
src/bin/exporter/Exporter.hx
Normal file
67
src/bin/exporter/Exporter.hx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package bin.exporter;
|
||||||
|
|
||||||
|
import kernel.net.Package.GenericPackage;
|
||||||
|
import kernel.peripherals.exports.RedstoneExport;
|
||||||
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
|
import kernel.ps.ProcessHandle;
|
||||||
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A service to expose local peripherals to the network.
|
||||||
|
**/
|
||||||
|
@:build(macros.Binstore.includeBin("Exporter", ["exporter"]))
|
||||||
|
class Exporter implements IProcess {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function run(handle:ProcessHandle) {
|
||||||
|
if (handle.args.length < 2) {
|
||||||
|
handle.writeLine("Not enough args: <addr> <type>");
|
||||||
|
handle.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var addr = handle.args[0];
|
||||||
|
var expectedType = handle.args[1];
|
||||||
|
|
||||||
|
// Check if peripheral is present. Not the case for redstone.
|
||||||
|
if (expectedType != kernel.peripherals.Redstone.TYPE_NAME && !Peripheral.isPresent(addr)) {
|
||||||
|
handle.writeLine('Address: $addr not present');
|
||||||
|
handle.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var types = Peripheral.getTypes(addr);
|
||||||
|
|
||||||
|
// Check if the correct type is present. Not the case for redstone.
|
||||||
|
if (expectedType != kernel.peripherals.Redstone.TYPE_NAME && !types.contains(expectedType)) {
|
||||||
|
handle.writeLine('Expected type not machted on address: $addr. Wanted $expectedType got $types');
|
||||||
|
handle.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var peri = Peripheral.getFromType(addr, expectedType);
|
||||||
|
|
||||||
|
if (peri == null) {
|
||||||
|
handle.writeLine('Failed to create peripheral for address: $addr');
|
||||||
|
handle.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var handePackFunc:(GenericPackage) -> Bool = null;
|
||||||
|
|
||||||
|
// Cast to RPC class
|
||||||
|
// TODO: There must be a smarter way to do this.
|
||||||
|
switch expectedType {
|
||||||
|
case kernel.peripherals.Redstone.TYPE_NAME:
|
||||||
|
handePackFunc = (p) -> {
|
||||||
|
return RedstoneExport.handlePackage(cast peri, p);
|
||||||
|
};
|
||||||
|
// TODO: More peripherals
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.writeLine('Listening on export:$addr with type $expectedType');
|
||||||
|
|
||||||
|
// Listen for packages
|
||||||
|
kernel.net.Net.registerProto('export:$addr', (p) -> {
|
||||||
|
if (!handePackFunc(p)) {
|
||||||
|
handle.writeLine("Failed handle package on export");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
package bin.exporter;
|
|
||||||
|
|
||||||
import lib.exporter.Export;
|
|
||||||
import lib.exporter.IExportable;
|
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
|
||||||
import kernel.service.ServiceManager;
|
|
||||||
import lib.exporter.Import;
|
|
||||||
import lib.CLIAppBase;
|
|
||||||
|
|
||||||
class Res extends CLIAppBase {
|
|
||||||
public function new() {
|
|
||||||
registerAsyncSubcommand("get", (args)->{
|
|
||||||
var url = args[0];
|
|
||||||
|
|
||||||
return Import.get(url).map((res)->{
|
|
||||||
switch (res){
|
|
||||||
case Success(data):
|
|
||||||
handle.writeLine(Std.string(data));
|
|
||||||
case Failure(err):
|
|
||||||
handle.writeLine("Error: ");
|
|
||||||
handle.writeLine(Std.string(err));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
},"<url>");
|
|
||||||
|
|
||||||
registerAsyncSubcommand("register",(args)->{
|
|
||||||
var srv: Null<ResManager> = ServiceManager.get("resmgr");
|
|
||||||
|
|
||||||
var addr = args[0];
|
|
||||||
var name = args[1];
|
|
||||||
|
|
||||||
if (srv == null) {
|
|
||||||
handle.writeLine("Error: resmgr not found");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var perf: kernel.peripherals.Redstone = Peripheral.getRedstone(addr);
|
|
||||||
|
|
||||||
if (perf == null) {
|
|
||||||
handle.writeLine("Error: peripheral not found");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return srv.register(name,new Export(perf)).map((res)->{
|
|
||||||
switch (res){
|
|
||||||
case Success(_):
|
|
||||||
handle.writeLine("Success");
|
|
||||||
return true;
|
|
||||||
case Failure(err):
|
|
||||||
handle.writeLine("Error: ");
|
|
||||||
handle.writeLine(Std.string(err));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},"<addr> <name>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
package bin.exporter;
|
|
||||||
|
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
|
||||||
import lib.KVStore;
|
|
||||||
import lib.exporter.Request;
|
|
||||||
import kernel.ps.ProcessHandle;
|
|
||||||
import lib.RessourceNames;
|
|
||||||
import lib.exporter.Export;
|
|
||||||
import kernel.ps.Process;
|
|
||||||
import kernel.net.Package;
|
|
||||||
import kernel.net.Net;
|
|
||||||
import kernel.net.Package.GenericPackage;
|
|
||||||
|
|
||||||
using tink.CoreApi;
|
|
||||||
|
|
||||||
class ResManager implements Process {
|
|
||||||
private var handle:ProcessHandle;
|
|
||||||
private var exports:Map<String,Export> = [];
|
|
||||||
|
|
||||||
public function new() {}
|
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
|
||||||
this.handle = handle;
|
|
||||||
Net.registerProto("res",handlePackage);
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function register(id: String, export: Export): Promise<Noise>{
|
|
||||||
if (exports.exists(id)){
|
|
||||||
return Promise.reject(new Error("Ressource already exists: " + id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return registerName(id).next((success)->{
|
|
||||||
exports.set(id,export);
|
|
||||||
persist();
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function handlePackage(pack: GenericPackage){
|
|
||||||
var requestPack: Package<Request> = cast pack;
|
|
||||||
var id = requestPack.data.id;
|
|
||||||
|
|
||||||
if (!exports.exists(id)){
|
|
||||||
requestPack.respond(lib.exporter.Response.NotFound);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var export = exports.get(id);
|
|
||||||
var response = export.handleRequest(requestPack.data);
|
|
||||||
|
|
||||||
requestPack.respond(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function registerName(id: String){
|
|
||||||
return RessourceNames.register(id, Net.networkID);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function persist(){
|
|
||||||
var store = new KVStore("export");
|
|
||||||
|
|
||||||
var saveExports: Array<{name: String, addr: String, type: String}> =
|
|
||||||
[for (k => v in this.exports) {name: k, addr: v.getAddr(), type: v.getType()}];
|
|
||||||
|
|
||||||
store.set("exports",saveExports);
|
|
||||||
|
|
||||||
store.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function load(){
|
|
||||||
var store = new KVStore("export");
|
|
||||||
|
|
||||||
var savedExports: Array<{name: String, addr: String, type: String}> = store.get("exports",[]);
|
|
||||||
|
|
||||||
for (export in savedExports){
|
|
||||||
var perph = Peripheral.getFromType(export.addr,export.type);
|
|
||||||
|
|
||||||
if (perph == null){
|
|
||||||
handle.writeLine('Could not load export: ${export.name} on ${export.addr}');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// I dont know if cast is the best way to do this
|
|
||||||
// But since we know that this is a IExportable we can do this (I think)
|
|
||||||
exports.set(export.name, new Export(cast perph));
|
|
||||||
|
|
||||||
handle.writeLine('Loaded export: ${export.name} on ${export.addr}');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
71
src/bin/ns/NameSystem.hx
Normal file
71
src/bin/ns/NameSystem.hx
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package bin.ns;
|
||||||
|
|
||||||
|
import lib.KVStore;
|
||||||
|
import haxe.ds.StringMap;
|
||||||
|
import kernel.net.Package.NetworkID;
|
||||||
|
import bin.ns.NameSystemRPC.INameSystemRPC;
|
||||||
|
import kernel.ps.ProcessHandle;
|
||||||
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
|
using Lambda;
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("NameSystem", ["ns", "namesystem"]))
|
||||||
|
class NameSystem implements IProcess implements INameSystemRPC {
|
||||||
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
|
private var idRecords:StringMap<NetworkID> = new StringMap();
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function run(handle:ProcessHandle) {
|
||||||
|
this.handle = handle;
|
||||||
|
|
||||||
|
this.load();
|
||||||
|
|
||||||
|
kernel.net.Net.registerProto("ns", (p) -> {
|
||||||
|
NameSystemRPC.handlePackage(this, p);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function load() {
|
||||||
|
var kv = new KVStore("NameSystem");
|
||||||
|
kv.load();
|
||||||
|
|
||||||
|
this.idRecords = kv.get("idRecords", new StringMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function save() {
|
||||||
|
var kv = new KVStore("NameSystem");
|
||||||
|
|
||||||
|
kv.set("idRecords", this.idRecords);
|
||||||
|
|
||||||
|
kv.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIDRecord(name:String, id:NetworkID):Noise {
|
||||||
|
this.idRecords.set(name, id);
|
||||||
|
this.save();
|
||||||
|
return Noise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIDRecord(name:String):Null<NetworkID> {
|
||||||
|
return this.idRecords.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeIDRecord(name:String):Noise {
|
||||||
|
this.idRecords.remove(name);
|
||||||
|
this.save();
|
||||||
|
return Noise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listIDRecords():Array<{name:String, id:NetworkID}> {
|
||||||
|
var rtn = [];
|
||||||
|
|
||||||
|
for (k => v in this.idRecords) {
|
||||||
|
rtn.push({name: k, id: v});
|
||||||
|
}
|
||||||
|
|
||||||
|
return rtn;
|
||||||
|
}
|
||||||
|
}
|
||||||
71
src/bin/ns/NameSystemCLI.hx
Normal file
71
src/bin/ns/NameSystemCLI.hx
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package bin.ns;
|
||||||
|
|
||||||
|
import lib.CLIAppBase;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("NameSystemCLI", ["ns-cli"]))
|
||||||
|
class NameSystemCLI extends CLIAppBase {
|
||||||
|
public function new() {
|
||||||
|
registerAsyncSubcommand("get", (args) -> {
|
||||||
|
var ns = NameSystemRPC.getDefault();
|
||||||
|
|
||||||
|
return ns.getIDRecord(args.getString("name")).map((r) -> {
|
||||||
|
switch r {
|
||||||
|
case Success(data):
|
||||||
|
handle.writeLine('Resolved: $data');
|
||||||
|
case Failure(failure):
|
||||||
|
handle.writeLine('Failed: $failure');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}, [String("name")]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("register", (args) -> {
|
||||||
|
var id = args.getInt("id");
|
||||||
|
var ns = NameSystemRPC.getDefault();
|
||||||
|
|
||||||
|
return ns.setIDRecord(args.getString("name"), id).map((r) -> {
|
||||||
|
switch r {
|
||||||
|
case Success(_):
|
||||||
|
handle.writeLine('Set');
|
||||||
|
case Failure(failure):
|
||||||
|
handle.writeLine('Failed: $failure');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}, [String("name"), Int("id")]);
|
||||||
|
|
||||||
|
registerAsyncSubcommand("list", (args) -> {
|
||||||
|
var ns = NameSystemRPC.getDefault();
|
||||||
|
|
||||||
|
return ns.listIDRecords().map((r) -> {
|
||||||
|
switch r {
|
||||||
|
case Success(data):
|
||||||
|
handle.writeLine('List: $data');
|
||||||
|
case Failure(failure):
|
||||||
|
handle.writeLine('Failed: $failure');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
registerAsyncSubcommand("unregister", (args) -> {
|
||||||
|
var ns = NameSystemRPC.getDefault();
|
||||||
|
|
||||||
|
return ns.removeIDRecord(args.getString("name")).map((r) -> {
|
||||||
|
switch r {
|
||||||
|
case Success(_):
|
||||||
|
handle.writeLine('Unregisterd');
|
||||||
|
case Failure(failure):
|
||||||
|
handle.writeLine('Failed: $failure');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}, [String("name")]);
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/bin/ns/NameSystemRPC.hx
Normal file
31
src/bin/ns/NameSystemRPC.hx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package bin.ns;
|
||||||
|
|
||||||
|
import kernel.KernelSettings;
|
||||||
|
import macros.rpc.RPCBase;
|
||||||
|
import kernel.net.Package.NetworkID;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
interface INameSystemRPC {
|
||||||
|
function setIDRecord(name:String, id:NetworkID):Noise;
|
||||||
|
function getIDRecord(name:String):Null<NetworkID>;
|
||||||
|
function removeIDRecord(name:String):Noise;
|
||||||
|
function listIDRecords():Array<{name:String, id:NetworkID}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:build(macros.rpc.RPC.buildRPC(INameSystemRPC))
|
||||||
|
class NameSystemRPC extends RPCBase {
|
||||||
|
public static function getDefault():NameSystemRPC {
|
||||||
|
return new NameSystemRPC(KernelSettings.nameServer, "ns");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function resolve(input:String):Promise<Null<NetworkID>> {
|
||||||
|
if (input == "12345") {
|
||||||
|
return Promise.resolve(Std.parseInt(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
var ns = getDefault();
|
||||||
|
|
||||||
|
return ns.getIDRecord(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,54 +1,59 @@
|
|||||||
package bin.pathfinder;
|
package bin.pathfinder;
|
||||||
|
|
||||||
import lib.Pos3;
|
import lib.WorldPos;
|
||||||
import lib.ui.elements.UIElement;
|
import lib.ui.elements.IUIElement;
|
||||||
import lib.ui.elements.TextElement;
|
import lib.ui.elements.TextElement;
|
||||||
import lib.ui.elements.RootElement;
|
import lib.ui.elements.RootElement;
|
||||||
import kernel.ui.WindowContext;
|
import kernel.ui.WindowContext;
|
||||||
import kernel.ps.ProcessHandle;
|
import kernel.ps.ProcessHandle;
|
||||||
import kernel.ps.Process;
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
class PFClient implements Process {
|
class PFClient implements IProcess {
|
||||||
private var handle:ProcessHandle;
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
private var ctx: WindowContext;
|
private var ctx:WindowContext;
|
||||||
private var requestRender:Void -> Void;
|
private var requestRender:Void->Void;
|
||||||
private var root:RootElement;
|
private var root:RootElement;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
public function run(handle:ProcessHandle) {
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
|
|
||||||
var stateless = handle.createStatelessWindowContext();
|
var stateless = handle.createStatelessWindowContext();
|
||||||
this.ctx = stateless.ctx;
|
this.ctx = stateless.ctx;
|
||||||
this.requestRender = stateless.requestRender;
|
this.requestRender = stateless.requestRender;
|
||||||
|
|
||||||
stateless.setRenderFunc(this.render);
|
stateless.setRenderFunc(this.render);
|
||||||
|
|
||||||
this.root = new RootElement();
|
this.root = new RootElement();
|
||||||
this.root.setTitle("Pathfinder");
|
this.root.setTitle("Pathfinder");
|
||||||
|
|
||||||
this.ctx.delegateEvents(this.root);
|
this.ctx.delegateEvents(this.root);
|
||||||
|
|
||||||
this.requestRender();
|
this.requestRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function render() {
|
private function render() {
|
||||||
var acc = kernel.gps.GPS.getAccuracy();
|
var acc = kernel.gps.GPS.getAccuracy();
|
||||||
var pos: Pos3 = kernel.gps.GPS.getPosition() ?? {x: 0, y: 0, z: 0};
|
var pos:WorldPos = kernel.gps.GPS.getPosition() ?? {x: 0, y: 0, z: 0};
|
||||||
|
|
||||||
var childre: Array<UIElement> = [
|
var childre:Array<IUIElement> = [
|
||||||
new TextElement('Acc: ${acc}'),
|
new TextElement('Acc: ${acc}'),
|
||||||
new TextElement('Pos: X:${pos.x} Y:${pos.y} Z:${pos.z}'),
|
new TextElement('Pos: X:${pos.x} Y:${pos.y} Z:${pos.z}'),
|
||||||
new TextElement('UPDATE', { style: {bgColor: Gray}, uiEvents: {onClick: () -> {
|
new TextElement('UPDATE', {
|
||||||
kernel.gps.GPS.locate().handle((pos) ->{
|
style: {bgColor: Gray},
|
||||||
this.requestRender();
|
uiEvents: {
|
||||||
});
|
onClick: () -> {
|
||||||
}}}),
|
kernel.gps.GPS.locate().handle((pos) -> {
|
||||||
];
|
this.requestRender();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
this.root.setChildren(childre);
|
this.root.setChildren(childre);
|
||||||
this.root.render(ctx.getSize()).renderToContext(ctx);
|
this.root.render(ctx.getSize()).renderToContext(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
package bin.srsc;
|
|
||||||
|
|
||||||
import kernel.net.Package.NetworkID;
|
|
||||||
import lib.RessourceNames;
|
|
||||||
import lib.CLIAppBase;
|
|
||||||
|
|
||||||
using tink.CoreApi;
|
|
||||||
|
|
||||||
class CLI extends CLIAppBase {
|
|
||||||
public function new() {
|
|
||||||
registerAsyncSubcommand("get", (args) -> {
|
|
||||||
if (args.length < 1) {
|
|
||||||
handle.writeLine("Not enough arguments");
|
|
||||||
return Future.sync(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return RessourceNames.get(args[0]).map((res) -> {
|
|
||||||
switch (res) {
|
|
||||||
case Success(data):
|
|
||||||
if (data == null) {
|
|
||||||
handle.writeLine("Not found");
|
|
||||||
} else {
|
|
||||||
handle.writeLine("Found: " + data);
|
|
||||||
}
|
|
||||||
case Failure(error):
|
|
||||||
handle.writeLine("Error: " + error);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}, "<name>");
|
|
||||||
|
|
||||||
registerAsyncSubcommand("register", (args) -> {
|
|
||||||
if (args.length < 2) {
|
|
||||||
handle.writeLine("Not enough arguments");
|
|
||||||
return Future.sync(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
var id:NetworkID = Std.parseInt(args[1]);
|
|
||||||
if (id == null) {
|
|
||||||
handle.writeLine("Invalid id");
|
|
||||||
return Future.sync(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return RessourceNames.register(args[0], id).map((res) -> {
|
|
||||||
switch (res) {
|
|
||||||
case Success(data):
|
|
||||||
handle.writeLine("Success");
|
|
||||||
case Failure(error):
|
|
||||||
handle.writeLine("Error: " + error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}, "<name> <id>");
|
|
||||||
|
|
||||||
registerAsyncSubcommand("unregister", (args) -> {
|
|
||||||
if (args.length < 1) {
|
|
||||||
handle.writeLine("Not enough arguments");
|
|
||||||
return Future.sync(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return RessourceNames.unregister(args[0]).map((res) -> {
|
|
||||||
switch (res) {
|
|
||||||
case Success(data):
|
|
||||||
handle.writeLine("Success");
|
|
||||||
case Failure(error):
|
|
||||||
handle.writeLine("Error: " + error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}, "<name>");
|
|
||||||
|
|
||||||
registerAsyncSubcommand("list", (args) -> {
|
|
||||||
return RessourceNames.list().map((res) -> {
|
|
||||||
switch (res) {
|
|
||||||
case Success(data):
|
|
||||||
for (name in data) {
|
|
||||||
handle.writeLine(name);
|
|
||||||
}
|
|
||||||
case Failure(error):
|
|
||||||
handle.writeLine("Error: " + error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package bin.srsc;
|
|
||||||
|
|
||||||
import kernel.net.Package.NetworkID;
|
|
||||||
|
|
||||||
typedef GetRequest = {
|
|
||||||
public var ?type:String;
|
|
||||||
public var name:String;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef GetResponse = {
|
|
||||||
public var success:Bool;
|
|
||||||
public var netID:NetworkID;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef RegisterRequest = {
|
|
||||||
public var ?type:String;
|
|
||||||
public var name:String;
|
|
||||||
public var netID:NetworkID;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef RegisterResponse = {
|
|
||||||
public var success:Bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef UnregisterRequest = {
|
|
||||||
public var ?type:String;
|
|
||||||
public var name:String;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef UnregisterResponse = {
|
|
||||||
public var success:Bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef ListRequest = {
|
|
||||||
public var ?type:String;
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package bin.srsc;
|
|
||||||
|
|
||||||
import lib.KVStore;
|
|
||||||
import bin.srsc.PackageTypes;
|
|
||||||
import kernel.net.Package;
|
|
||||||
import kernel.ps.ProcessHandle;
|
|
||||||
import kernel.ps.Process;
|
|
||||||
|
|
||||||
/**
|
|
||||||
The SiteRessourceController is responsible for the management of ressources on the site.
|
|
||||||
It makes sure that ressources are have a unique id and that they are not duplicated.
|
|
||||||
It also keeps track of the responsible NetID for each ressource. Kinda like a DNS.
|
|
||||||
**/
|
|
||||||
class SiteRessourceController implements Process {
|
|
||||||
public static inline final SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO:String = "srsc";
|
|
||||||
|
|
||||||
private var handle:ProcessHandle;
|
|
||||||
private var ressources:Map<String, NetworkID>;
|
|
||||||
|
|
||||||
public function new() {}
|
|
||||||
|
|
||||||
public function run(handle:ProcessHandle) {
|
|
||||||
this.handle = handle;
|
|
||||||
|
|
||||||
load();
|
|
||||||
|
|
||||||
// Register proto
|
|
||||||
kernel.net.Net.registerProto(SITE_CONTROLLER_RESSOURCE_MANAGER_PROTO, this.handleMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function handleMsg(pkg:GenericPackage) {
|
|
||||||
/*
|
|
||||||
There are 3 types of messages:
|
|
||||||
- Register a new ressource name
|
|
||||||
- Unregister a ressource name
|
|
||||||
- Get the responsible NetID for a ressource name
|
|
||||||
*/
|
|
||||||
|
|
||||||
switch (pkg.data.type) {
|
|
||||||
case "register":
|
|
||||||
pkg.respond(handleRegister(cast pkg.data));
|
|
||||||
case "unregister":
|
|
||||||
pkg.respond(handleUnregister(cast pkg.data));
|
|
||||||
case "get":
|
|
||||||
pkg.respond(handleGet(cast pkg.data));
|
|
||||||
case "list":
|
|
||||||
pkg.respond(list());
|
|
||||||
default:
|
|
||||||
handle.writeLine("Unknown message type: " + pkg.data.type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function handleGet(data:GetRequest):GetResponse {
|
|
||||||
var res = get(data.name);
|
|
||||||
return {success: res != null, netID: res};
|
|
||||||
}
|
|
||||||
|
|
||||||
private function handleRegister(data:RegisterRequest):RegisterResponse {
|
|
||||||
var res = register(data.name, data.netID);
|
|
||||||
return {success: res};
|
|
||||||
}
|
|
||||||
|
|
||||||
private function handleUnregister(data:UnregisterRequest):UnregisterResponse {
|
|
||||||
unregister(data.name);
|
|
||||||
return {success: true};
|
|
||||||
}
|
|
||||||
|
|
||||||
public function register(name:String, netID:NetworkID):Bool {
|
|
||||||
if (ressources.exists(name) && ressources.get(name) != netID) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ressources.set(name, netID);
|
|
||||||
save();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function unregister(name:String) {
|
|
||||||
if (ressources.exists(name)) {
|
|
||||||
ressources.remove(name);
|
|
||||||
}
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get(name:String):Null<NetworkID> {
|
|
||||||
return ressources.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline function list():Array<String> {
|
|
||||||
return [ for (k in ressources.keys()) k];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function load() {
|
|
||||||
var store = KVStore.getStoreForClass();
|
|
||||||
var data:Null<Map<String, NetworkID>> = store.get("ressources");
|
|
||||||
|
|
||||||
if (data != null) {
|
|
||||||
this.ressources = data;
|
|
||||||
} else {
|
|
||||||
this.ressources = new Map<String, NetworkID>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function save() {
|
|
||||||
var store = KVStore.getStoreForClass();
|
|
||||||
store.set("ressources", this.ressources);
|
|
||||||
store.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
158
src/bin/turtle/CircleMine.hx
Normal file
158
src/bin/turtle/CircleMine.hx
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
package bin.turtle;
|
||||||
|
|
||||||
|
import kernel.turtle.Turtle;
|
||||||
|
import lib.turtle.TurtleAppBase;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Circle Mine", ["circle-mine", "cm"]))
|
||||||
|
class CircleMine extends TurtleAppBase {
|
||||||
|
private var rings:Int;
|
||||||
|
private var skip:Int = 0;
|
||||||
|
private var depth:Int = 0;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super(initFunc, turtleFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function initFunc() {
|
||||||
|
if (handle.args.length < 1) {
|
||||||
|
handle.writeLine("Not enough args");
|
||||||
|
handle.close(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rings = Std.parseInt(handle.args[0]);
|
||||||
|
if (this.rings == null) {
|
||||||
|
handle.writeLine("Failed to parse args");
|
||||||
|
handle.close(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle.args.length > 1) {
|
||||||
|
this.skip = Std.parseInt(handle.args[1]);
|
||||||
|
if (this.skip == null) {
|
||||||
|
handle.writeLine("Failed to parse args");
|
||||||
|
handle.close(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function turtleFunc() {
|
||||||
|
// Go down 1 layer
|
||||||
|
if (skip == 0) {
|
||||||
|
Turtle.dig(Down);
|
||||||
|
Turtle.down();
|
||||||
|
Turtle.dig(Down);
|
||||||
|
} else {
|
||||||
|
// Move to outer ring
|
||||||
|
for (i in 0...(skip * 3) - 1) {
|
||||||
|
Turtle.forward();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start mining
|
||||||
|
for (i in skip...(rings + skip)) {
|
||||||
|
if (i == 0) {
|
||||||
|
center();
|
||||||
|
handle.writeLine("Center done");
|
||||||
|
} else {
|
||||||
|
circle(i * 3 + 1);
|
||||||
|
handle.writeLine('Ring $i done');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Go back to starting pos.
|
||||||
|
for (i in 0...((rings + skip) * 3 - 1)) {
|
||||||
|
Turtle.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function circle(radius:Int) {
|
||||||
|
step();
|
||||||
|
step();
|
||||||
|
frontDig();
|
||||||
|
|
||||||
|
// Do a 1/2 of a side of a ring
|
||||||
|
Turtle.turnRight();
|
||||||
|
for (i in 0...radius) {
|
||||||
|
step();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do the other 2 sides
|
||||||
|
for (s in 0...3) {
|
||||||
|
Turtle.turnRight();
|
||||||
|
for (i in 0...radius) {
|
||||||
|
step();
|
||||||
|
}
|
||||||
|
|
||||||
|
middle();
|
||||||
|
|
||||||
|
for (i in 0...radius) {
|
||||||
|
step();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Complete the 1/2 of the first side
|
||||||
|
Turtle.turnRight();
|
||||||
|
for (i in 0...radius) {
|
||||||
|
step();
|
||||||
|
}
|
||||||
|
|
||||||
|
Turtle.turnLeft();
|
||||||
|
Turtle.forward();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function middle() {
|
||||||
|
Turtle.turnRight();
|
||||||
|
|
||||||
|
Turtle.dig(Front);
|
||||||
|
Turtle.down();
|
||||||
|
Turtle.dig(Front);
|
||||||
|
|
||||||
|
Turtle.turnLeft();
|
||||||
|
Turtle.turnLeft();
|
||||||
|
|
||||||
|
Turtle.dig(Front);
|
||||||
|
Turtle.up();
|
||||||
|
Turtle.dig(Front);
|
||||||
|
|
||||||
|
Turtle.turnRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function step() {
|
||||||
|
Turtle.dig(Front);
|
||||||
|
Turtle.forward();
|
||||||
|
Turtle.dig(Down);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function frontDig() {
|
||||||
|
Turtle.dig(Front);
|
||||||
|
Turtle.down();
|
||||||
|
Turtle.dig(Front);
|
||||||
|
Turtle.up();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function center() {
|
||||||
|
Turtle.dig(Down);
|
||||||
|
step();
|
||||||
|
frontDig();
|
||||||
|
Turtle.turnRight();
|
||||||
|
|
||||||
|
for (i in 0...3) {
|
||||||
|
step();
|
||||||
|
Turtle.turnRight();
|
||||||
|
step();
|
||||||
|
Turtle.turnLeft();
|
||||||
|
frontDig();
|
||||||
|
Turtle.turnRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
step();
|
||||||
|
Turtle.turnRight();
|
||||||
|
Turtle.forward();
|
||||||
|
Turtle.turnLeft();
|
||||||
|
Turtle.forward();
|
||||||
|
}
|
||||||
|
}
|
||||||
56
src/bin/turtle/CircleMinePlan.hx
Normal file
56
src/bin/turtle/CircleMinePlan.hx
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package bin.turtle;
|
||||||
|
|
||||||
|
import lib.turtle.planner.Plan;
|
||||||
|
import kernel.ps.ProcessHandle;
|
||||||
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
|
@:build(macros.Binstore.includeBin("Circle Mine Plan", ["cmp"]))
|
||||||
|
class CircleMinePlan implements IProcess {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function run(handle:ProcessHandle) {
|
||||||
|
var rings:Int = 3;
|
||||||
|
var skip:Int = 0;
|
||||||
|
|
||||||
|
var p = Plan.newPlan();
|
||||||
|
|
||||||
|
p = p.repeat([Forward], (skip * 3) - 1); // Move to outer ring or stay if none skiped
|
||||||
|
|
||||||
|
for (i in skip...(rings + skip)) {
|
||||||
|
if (i == 0) {
|
||||||
|
p = p.act([Clear(Down), Down, Clear(Down)]) // Move down a layer
|
||||||
|
.subplan(center());
|
||||||
|
} else {
|
||||||
|
p = p.subplan(circle(i * 3 + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p.repeat([Back], (rings + skip) * 3 - 1);
|
||||||
|
|
||||||
|
p.begin(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function circle(radius:Int):Plan {
|
||||||
|
return Plan.newPlan()
|
||||||
|
.act([FullTunnel, FullTunnel, HalfTunnel])
|
||||||
|
.act([TurnRight])
|
||||||
|
.repeat([FullTunnel], radius)
|
||||||
|
.repateSubplan(Plan.newPlan().act([TurnRight]).repeat([FullTunnel], radius).act([
|
||||||
|
TurnRight, Clear(Front), Down, Clear(Front), TurnLeft, TurnLeft, Clear(Front), Up, Clear(Front), TurnRight
|
||||||
|
]).repeat([FullTunnel], radius), 3)
|
||||||
|
.act([TurnRight])
|
||||||
|
.repeat([FullTunnel], radius)
|
||||||
|
.act([TurnLeft, Forward]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function center():Plan {
|
||||||
|
return Plan.newPlan()
|
||||||
|
.act([Clear(Down)])
|
||||||
|
.act([FullTunnel])
|
||||||
|
.act([Clear(Front), Down, Clear(Front), Up])
|
||||||
|
.act([TurnRight])
|
||||||
|
.repeat([FullTunnel, TurnRight, FullTunnel, TurnLeft, HalfTunnel, TurnRight], 3)
|
||||||
|
.act([FullTunnel])
|
||||||
|
.act([TurnRight, Forward, TurnLeft, Forward]);
|
||||||
|
}
|
||||||
|
}
|
||||||
67
src/bin/turtle/Excavate.hx
Normal file
67
src/bin/turtle/Excavate.hx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package bin.turtle;
|
||||||
|
|
||||||
|
import lib.turtle.Helper;
|
||||||
|
import lib.turtle.TurtleAppBase;
|
||||||
|
|
||||||
|
class Excavate extends TurtleAppBase {
|
||||||
|
private var x:Int = 0;
|
||||||
|
private var y:Int = 0;
|
||||||
|
private var z:Int = 0;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super(init, turtleFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function init() {
|
||||||
|
if (handle.args.length < 2) {
|
||||||
|
handle.writeLine("Usage: excavate <front> <right> <down>");
|
||||||
|
handle.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var parsedX = Std.parseInt(handle.args[0]);
|
||||||
|
var parsedY = Std.parseInt(handle.args[1]);
|
||||||
|
var parsedZ = Std.parseInt(handle.args[2]);
|
||||||
|
|
||||||
|
if (parsedX == null || parsedY == null || parsedZ == null) {
|
||||||
|
handle.writeLine("Invalid arguments");
|
||||||
|
handle.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.x = parsedX;
|
||||||
|
this.y = parsedY;
|
||||||
|
this.z = parsedZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function turtleFunction() {
|
||||||
|
for (z in 0...this.z) {
|
||||||
|
for (y in 0...this.y) {
|
||||||
|
for (x in 0...this.x) {
|
||||||
|
kernel.turtle.Turtle.dig(Down);
|
||||||
|
|
||||||
|
if (x < this.x - 1) {
|
||||||
|
kernel.turtle.Turtle.forward();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y < this.y - 1) {
|
||||||
|
if (y % 2 == 0) {
|
||||||
|
kernel.turtle.Turtle.turnRight();
|
||||||
|
kernel.turtle.Turtle.forward();
|
||||||
|
kernel.turtle.Turtle.turnRight();
|
||||||
|
} else {
|
||||||
|
kernel.turtle.Turtle.turnLeft();
|
||||||
|
kernel.turtle.Turtle.forward();
|
||||||
|
kernel.turtle.Turtle.turnLeft();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kernel.turtle.Turtle.dig(Down);
|
||||||
|
kernel.turtle.Turtle.down();
|
||||||
|
|
||||||
|
Helper.times(kernel.turtle.Turtle.turnLeft, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.close(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/bin/turtle/Patrol.hx
Normal file
31
src/bin/turtle/Patrol.hx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package bin.turtle;
|
||||||
|
|
||||||
|
import kernel.turtle.TurtleMutex;
|
||||||
|
import kernel.ps.ProcessHandle;
|
||||||
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
|
class Patrol implements IProcess {
|
||||||
|
private var handle:ProcessHandle;
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function run(handle:ProcessHandle) {
|
||||||
|
this.handle = handle;
|
||||||
|
|
||||||
|
if (!handle.claimTurtleMutex()) {
|
||||||
|
handle.writeLine("Failed to claim turtle mutex");
|
||||||
|
handle.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.writeLine("Patroling");
|
||||||
|
|
||||||
|
TurtleMutex.runInTThread(() -> {
|
||||||
|
while (true) {
|
||||||
|
kernel.turtle.Turtle.forward();
|
||||||
|
kernel.turtle.Turtle.forward();
|
||||||
|
kernel.turtle.Turtle.forward();
|
||||||
|
kernel.turtle.Turtle.turnLeft();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package kernel;
|
|
||||||
|
|
||||||
@:keep
|
|
||||||
class DCEHack {
|
|
||||||
// Dont actually call this
|
|
||||||
public static function load():Array<kernel.ps.Process>{
|
|
||||||
macros.DCEHack.dceGenerateCreate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,22 +3,26 @@ package kernel;
|
|||||||
import cc.OS;
|
import cc.OS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Make sure that a function is called at the end of the current event loop.
|
Make sure that a function is called at the end of the current event loop.
|
||||||
Like setTimeout(func, 0) in JavaScript.
|
Like setTimeout(func, 0) in JavaScript.
|
||||||
**/
|
**/
|
||||||
class EndOfLoop {
|
class EndOfLoop {
|
||||||
private static var backlog:Array<Void -> Void> = [];
|
private static var backlog:Array<Void->Void> = [];
|
||||||
private static var isQueued = false;
|
private static var isQueued = false;
|
||||||
|
|
||||||
public static function endOfLoop(func: Void -> Void) {
|
public static function endOfLoop(func:Void->Void) {
|
||||||
backlog.push(func);
|
backlog.push(func);
|
||||||
if (!isQueued) { OS.queueEvent("endofloop", null); }
|
if (!isQueued) {
|
||||||
}
|
OS.queueEvent("endofloop", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@:allow(kernel.KernelEvents)
|
@:allow(kernel.KernelEvents)
|
||||||
private static function run() {
|
private static function run() {
|
||||||
for (func in backlog) { func(); }
|
for (func in backlog) {
|
||||||
backlog = [];
|
func();
|
||||||
isQueued = false;
|
}
|
||||||
}
|
backlog = [];
|
||||||
|
isQueued = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,17 @@ class Entrypoint {
|
|||||||
public static function main() {
|
public static function main() {
|
||||||
try {
|
try {
|
||||||
Init.initKernel();
|
Init.initKernel();
|
||||||
}catch(e){
|
} catch (e) {
|
||||||
Log.error('Error in init: ${e.toString()}');
|
Log.error('Error in init: ${e.toString()}');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Startup.main();
|
Startup.main();
|
||||||
}catch(e){
|
} catch (e) {
|
||||||
Log.error('Error in startup: ${e.toString()}');
|
Log.error('Error in startup: ${e.toString()}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KernelEvents.startEventLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,18 @@
|
|||||||
package kernel;
|
package kernel;
|
||||||
|
|
||||||
|
#if debug
|
||||||
|
import lib.Debug;
|
||||||
|
#end
|
||||||
import kernel.service.ServiceManager;
|
import kernel.service.ServiceManager;
|
||||||
import kernel.binstore.BinStore;
|
|
||||||
import kernel.gps.INS;
|
|
||||||
import kernel.fs.FS;
|
import kernel.fs.FS;
|
||||||
import kernel.gps.GPS;
|
import kernel.gps.GPS;
|
||||||
import kernel.log.Log;
|
import kernel.log.Log;
|
||||||
import kernel.turtle.Turtle;
|
|
||||||
import haxe.MainLoop;
|
|
||||||
import kernel.net.Routing;
|
import kernel.net.Routing;
|
||||||
import cc.OS;
|
|
||||||
import lib.Debug;
|
|
||||||
import kernel.ui.WindowManager;
|
import kernel.ui.WindowManager;
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
|
||||||
import kernel.net.Net;
|
import kernel.net.Net;
|
||||||
|
|
||||||
import kernel.DCEHack; // Important for DCE hack
|
|
||||||
|
|
||||||
class Init {
|
class Init {
|
||||||
|
|
||||||
@:allow(kernel.KernelEvents)
|
@:allow(kernel.KernelEvents)
|
||||||
private static var mainEvent:MainEvent;
|
|
||||||
|
|
||||||
public static function initKernel() {
|
public static function initKernel() {
|
||||||
// Init singeltons here because haxe is confused about the order to create them.
|
// Init singeltons here because haxe is confused about the order to create them.
|
||||||
Log.init();
|
Log.init();
|
||||||
@@ -30,30 +21,24 @@ class Init {
|
|||||||
WindowManager.init();
|
WindowManager.init();
|
||||||
MainTerm.instance = new MainTerm();
|
MainTerm.instance = new MainTerm();
|
||||||
|
|
||||||
if (Turtle.isTurtle()){
|
|
||||||
Turtle.instance = new Turtle();
|
|
||||||
}
|
|
||||||
|
|
||||||
Routing.init();
|
Routing.init();
|
||||||
Net.init();
|
Net.init();
|
||||||
|
|
||||||
GPS.init();
|
GPS.init();
|
||||||
|
|
||||||
// Register default terminate handler
|
// Register default terminate handler
|
||||||
KernelEvents.onTerminate.handle(_->{
|
KernelEvents.onTerminate.handle(_ -> {
|
||||||
KernelEvents.shutdown();
|
KernelEvents.shutdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#if debug
|
||||||
Debug.printBuildInfo();
|
Debug.printBuildInfo();
|
||||||
|
#end
|
||||||
|
|
||||||
if (!FS.exists("/var/ns")) {
|
if (!FS.exists("/var/ns")) {
|
||||||
FS.makeDir("/var/ns");
|
FS.makeDir("/var/ns");
|
||||||
}
|
}
|
||||||
|
|
||||||
Init.mainEvent = MainLoop.add(()->{
|
|
||||||
KernelEvents.startEventLoop();
|
|
||||||
});
|
|
||||||
|
|
||||||
ServiceManager.init();
|
ServiceManager.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package kernel;
|
package kernel;
|
||||||
|
|
||||||
|
import kernel.turtle.TurtleMutex;
|
||||||
|
import kernel.turtle.Turtle;
|
||||||
import kernel.peripherals.Peripherals.Peripheral;
|
import kernel.peripherals.Peripherals.Peripheral;
|
||||||
import kernel.log.Log;
|
import kernel.log.Log;
|
||||||
import lib.Pos;
|
import lib.ScreenPos;
|
||||||
import cc.HTTP.HTTPResponse;
|
import cc.HTTP.HTTPResponse;
|
||||||
import lua.TableTools;
|
import lua.TableTools;
|
||||||
import lua.Coroutine;
|
import lua.Coroutine;
|
||||||
@@ -19,6 +21,7 @@ class KernelEvents {
|
|||||||
Depends on: (Nothing)
|
Depends on: (Nothing)
|
||||||
**/
|
**/
|
||||||
public static var onAlarm(default, null):Signal<Int>;
|
public static var onAlarm(default, null):Signal<Int>;
|
||||||
|
|
||||||
public static var onChar(default, null):Signal<String>;
|
public static var onChar(default, null):Signal<String>;
|
||||||
public static var onDisk(default, null):Signal<String>;
|
public static var onDisk(default, null):Signal<String>;
|
||||||
public static var onDiskEject(default, null):Signal<String>;
|
public static var onDiskEject(default, null):Signal<String>;
|
||||||
@@ -35,11 +38,11 @@ class KernelEvents {
|
|||||||
distance:Null<Float>
|
distance:Null<Float>
|
||||||
}>;
|
}>;
|
||||||
public static var onMonitorResize(default, null):Signal<String>;
|
public static var onMonitorResize(default, null):Signal<String>;
|
||||||
public static var onMonitorTouch(default, null):Signal<{addr:String, pos:Pos}>;
|
public static var onMonitorTouch(default, null):Signal<{addr:String, pos:ScreenPos}>;
|
||||||
public static var onMouseClick(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
public static var onMouseClick(default, null):Signal<{button:ButtonType, pos:ScreenPos}>;
|
||||||
public static var onMouseDrag(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
public static var onMouseDrag(default, null):Signal<{button:ButtonType, pos:ScreenPos}>;
|
||||||
public static var onMouseScroll(default, null):Signal<{dir:Int, pos:Pos}>;
|
public static var onMouseScroll(default, null):Signal<{dir:Int, pos:ScreenPos}>;
|
||||||
public static var onMouseUp(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
public static var onMouseUp(default, null):Signal<{button:ButtonType, pos:ScreenPos}>;
|
||||||
public static var onPaste(default, null):Signal<String>;
|
public static var onPaste(default, null):Signal<String>;
|
||||||
public static var onPeripheral(default, null):Signal<String>;
|
public static var onPeripheral(default, null):Signal<String>;
|
||||||
public static var onPeripheralDetach(default, null):Signal<String>;
|
public static var onPeripheralDetach(default, null):Signal<String>;
|
||||||
@@ -72,11 +75,11 @@ class KernelEvents {
|
|||||||
distance:Null<Float>
|
distance:Null<Float>
|
||||||
}> = Signal.trigger();
|
}> = Signal.trigger();
|
||||||
private static final onMonitorResizeTrigger:SignalTrigger<String> = Signal.trigger();
|
private static final onMonitorResizeTrigger:SignalTrigger<String> = Signal.trigger();
|
||||||
private static final onMonitorTouchTrigger:SignalTrigger<{addr:String, pos:Pos}> = Signal.trigger();
|
private static final onMonitorTouchTrigger:SignalTrigger<{addr:String, pos:ScreenPos}> = Signal.trigger();
|
||||||
private static final onMouseClickTrigger:SignalTrigger<{button:ButtonType, pos:Pos}> = Signal.trigger();
|
private static final onMouseClickTrigger:SignalTrigger<{button:ButtonType, pos:ScreenPos}> = Signal.trigger();
|
||||||
private static final onMouseDragTrigger:SignalTrigger<{button:ButtonType, pos:Pos}> = Signal.trigger();
|
private static final onMouseDragTrigger:SignalTrigger<{button:ButtonType, pos:ScreenPos}> = Signal.trigger();
|
||||||
private static final onMouseScrollTrigger:SignalTrigger<{dir:Int, pos:Pos}> = Signal.trigger();
|
private static final onMouseScrollTrigger:SignalTrigger<{dir:Int, pos:ScreenPos}> = Signal.trigger();
|
||||||
private static final onMouseUpTrigger:SignalTrigger<{button:ButtonType, pos:Pos}> = Signal.trigger();
|
private static final onMouseUpTrigger:SignalTrigger<{button:ButtonType, pos:ScreenPos}> = Signal.trigger();
|
||||||
private static final onPasteTrigger:SignalTrigger<String> = Signal.trigger();
|
private static final onPasteTrigger:SignalTrigger<String> = Signal.trigger();
|
||||||
private static final onPeripheralTrigger:SignalTrigger<String> = Signal.trigger();
|
private static final onPeripheralTrigger:SignalTrigger<String> = Signal.trigger();
|
||||||
private static final onPeripheralDetachTrigger:SignalTrigger<String> = Signal.trigger();
|
private static final onPeripheralDetachTrigger:SignalTrigger<String> = Signal.trigger();
|
||||||
@@ -93,10 +96,11 @@ class KernelEvents {
|
|||||||
private static final onWebsocketMessageTrigger:SignalTrigger<{url:String, message:String, isBinary:Bool}> = Signal.trigger();
|
private static final onWebsocketMessageTrigger:SignalTrigger<{url:String, message:String, isBinary:Bool}> = Signal.trigger();
|
||||||
private static final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
private static final onWebsocketSuccessTrigger:SignalTrigger<{url:String, handle:Any}> = Signal.trigger();
|
||||||
|
|
||||||
private static var stopLoop:Bool = false;
|
private static var stopLoop:Bool = false;
|
||||||
|
private static var turtleCoroutine:Coroutine<Dynamic>;
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
onAlarm = onAlarmTrigger.asSignal();
|
onAlarm = onAlarmTrigger.asSignal();
|
||||||
onChar = onCharTrigger.asSignal();
|
onChar = onCharTrigger.asSignal();
|
||||||
onDisk = onDiskTrigger.asSignal();
|
onDisk = onDiskTrigger.asSignal();
|
||||||
@@ -132,22 +136,68 @@ class KernelEvents {
|
|||||||
/**
|
/**
|
||||||
Start pulling events. Blocking.
|
Start pulling events. Blocking.
|
||||||
**/
|
**/
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Entrypoint)
|
||||||
private static function startEventLoop() {
|
private static function startEventLoop() {
|
||||||
|
if (Turtle.isTurtle()) {
|
||||||
|
turtleLoop();
|
||||||
|
} else {
|
||||||
|
runMainLoop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:allow(kernel.turtle.TurtleMutex)
|
||||||
|
private static function startTurtleCoroutine() {
|
||||||
|
turtleCoroutine = Coroutine.create(runTurtleLoop);
|
||||||
|
Coroutine.resume(turtleCoroutine);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function turtleLoop() {
|
||||||
|
startTurtleCoroutine();
|
||||||
|
|
||||||
|
while (!stopLoop) {
|
||||||
|
var eventData = pullEvents();
|
||||||
|
|
||||||
|
if (eventData[1] == "turtle_response" || eventData[1] == "tthread") {
|
||||||
|
var result = Coroutine.resume(turtleCoroutine, TableTools.unpack(eventData));
|
||||||
|
|
||||||
|
if (!result.success) {
|
||||||
|
Log.error('Error while running turtle thread: ${result.result}');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Coroutine.status(turtleCoroutine) == Dead) {
|
||||||
|
Log.error('Turtle thread died');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fireSignal(eventData[1], eventData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function runTurtleLoop() {
|
||||||
|
while (!stopLoop) {
|
||||||
|
if ((TableTools.pack(Coroutine.yield()))[1] != "tthread")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (stopLoop)
|
||||||
|
continue;
|
||||||
|
TurtleMutex.runThreadFunc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function runMainLoop() {
|
||||||
while (!stopLoop) {
|
while (!stopLoop) {
|
||||||
var event:Table<Int, Dynamic> = pullEvents();
|
var event:Table<Int, Dynamic> = pullEvents();
|
||||||
|
|
||||||
var eventName:String = event[1];
|
var eventName:String = event[1];
|
||||||
try {
|
try {
|
||||||
fireSignal(eventName,event);
|
fireSignal(eventName, event);
|
||||||
}catch(e:Dynamic) {
|
} catch (e:Dynamic) {
|
||||||
Log.error('Error while handling event: $eventName: ${e}');
|
Log.error('Error while handling event: $eventName: ${e}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function shutdown() {
|
public static function shutdown() {
|
||||||
|
|
||||||
// clearing screens
|
// clearing screens
|
||||||
for (screen in Peripheral.getAllScreens()) {
|
for (screen in Peripheral.getAllScreens()) {
|
||||||
screen.reset();
|
screen.reset();
|
||||||
@@ -156,14 +206,13 @@ class KernelEvents {
|
|||||||
Log.info('Shutting down event loop');
|
Log.info('Shutting down event loop');
|
||||||
stopLoop = true;
|
stopLoop = true;
|
||||||
MainTerm.instance.reset();
|
MainTerm.instance.reset();
|
||||||
Init.mainEvent.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function pullEvents():Table<Int, Dynamic> {
|
private static function pullEvents():Table<Int, Dynamic> {
|
||||||
return cast TableTools.pack(Coroutine.yield(null));
|
return cast TableTools.pack(Coroutine.yield(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function fireSignal(eventName: String,event:Table<Int, Dynamic> ) {
|
private static function fireSignal(eventName:String, event:Table<Int, Dynamic>) {
|
||||||
switch eventName {
|
switch eventName {
|
||||||
case "alarm":
|
case "alarm":
|
||||||
onAlarmTrigger.trigger(event[2]);
|
onAlarmTrigger.trigger(event[2]);
|
||||||
@@ -252,36 +301,66 @@ class KernelEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:allow(lib.Debug)
|
@:allow(lib.Debug)
|
||||||
private static function printListenerCount() {
|
private static function printListenerCount() {
|
||||||
if (onAlarmTrigger.getLength() > 0) Log.debug("onAlarm: " + onAlarmTrigger.getLength());
|
if (onAlarmTrigger.getLength() > 0)
|
||||||
if (onCharTrigger.getLength() > 0) Log.debug("onChar: " + onCharTrigger.getLength());
|
Log.debug("onAlarm: " + onAlarmTrigger.getLength());
|
||||||
if (onDiskTrigger.getLength() > 0) Log.debug("onDisk: " + onDiskTrigger.getLength());
|
if (onCharTrigger.getLength() > 0)
|
||||||
if (onDiskEjectTrigger.getLength() > 0) Log.debug("onDiskEject: " + onDiskEjectTrigger.getLength());
|
Log.debug("onChar: " + onCharTrigger.getLength());
|
||||||
if (onHttpCheckTrigger.getLength() > 0) Log.debug("onHttpCheck: " + onHttpCheckTrigger.getLength());
|
if (onDiskTrigger.getLength() > 0)
|
||||||
if (onHttpFailureTrigger.getLength() > 0) Log.debug("onHttpFailure: " + onHttpFailureTrigger.getLength());
|
Log.debug("onDisk: " + onDiskTrigger.getLength());
|
||||||
if (onHttpSuccessTrigger.getLength() > 0) Log.debug("onHttpSuccess: " + onHttpSuccessTrigger.getLength());
|
if (onDiskEjectTrigger.getLength() > 0)
|
||||||
if (onKeyTrigger.getLength() > 0) Log.debug("onKey: " + onKeyTrigger.getLength());
|
Log.debug("onDiskEject: " + onDiskEjectTrigger.getLength());
|
||||||
if (onKeyUpTrigger.getLength() > 0) Log.debug("onKeyUp: " + onKeyUpTrigger.getLength());
|
if (onHttpCheckTrigger.getLength() > 0)
|
||||||
if (onModemMessageTrigger.getLength() > 0) Log.debug("onModemMessage: " + onModemMessageTrigger.getLength());
|
Log.debug("onHttpCheck: " + onHttpCheckTrigger.getLength());
|
||||||
if (onMonitorResizeTrigger.getLength() > 0) Log.debug("onMonitorResize: " + onMonitorResizeTrigger.getLength());
|
if (onHttpFailureTrigger.getLength() > 0)
|
||||||
if (onMonitorTouchTrigger.getLength() > 0) Log.debug("onMonitorTouch: " + onMonitorTouchTrigger.getLength());
|
Log.debug("onHttpFailure: " + onHttpFailureTrigger.getLength());
|
||||||
if (onMouseClickTrigger.getLength() > 0) Log.debug("onMouseClick: " + onMouseClickTrigger.getLength());
|
if (onHttpSuccessTrigger.getLength() > 0)
|
||||||
if (onMouseDragTrigger.getLength() > 0) Log.debug("onMouseDrag: " + onMouseDragTrigger.getLength());
|
Log.debug("onHttpSuccess: " + onHttpSuccessTrigger.getLength());
|
||||||
if (onMouseScrollTrigger.getLength() > 0) Log.debug("onMouseScroll: " + onMouseScrollTrigger.getLength());
|
if (onKeyTrigger.getLength() > 0)
|
||||||
if (onMouseUpTrigger.getLength() > 0) Log.debug("onMouseUp: " + onMouseUpTrigger.getLength());
|
Log.debug("onKey: " + onKeyTrigger.getLength());
|
||||||
if (onPasteTrigger.getLength() > 0) Log.debug("onPaste: " + onPasteTrigger.getLength());
|
if (onKeyUpTrigger.getLength() > 0)
|
||||||
if (onPeripheralTrigger.getLength() > 0) Log.debug("onPeripheral: " + onPeripheralTrigger.getLength());
|
Log.debug("onKeyUp: " + onKeyUpTrigger.getLength());
|
||||||
if (onPeripheralDetachTrigger.getLength() > 0) Log.debug("onPeripheralDetach: " + onPeripheralDetachTrigger.getLength());
|
if (onModemMessageTrigger.getLength() > 0)
|
||||||
if (onRedstoneTrigger.getLength() > 0) Log.debug("onRedstone: " + onRedstoneTrigger.getLength());
|
Log.debug("onModemMessage: " + onModemMessageTrigger.getLength());
|
||||||
if (onSpeakerAudioEmptyTrigger.getLength() > 0) Log.debug("onSpeakerAudioEmpty: " + onSpeakerAudioEmptyTrigger.getLength());
|
if (onMonitorResizeTrigger.getLength() > 0)
|
||||||
if (onTaskCompleteTrigger.getLength() > 0) Log.debug("onTaskComplete: " + onTaskCompleteTrigger.getLength());
|
Log.debug("onMonitorResize: " + onMonitorResizeTrigger.getLength());
|
||||||
if (onTermResizeTrigger.getLength() > 0) Log.debug("onTermResize: " + onTermResizeTrigger.getLength());
|
if (onMonitorTouchTrigger.getLength() > 0)
|
||||||
if (onTerminateTrigger.getLength() > 0) Log.debug("onTerminate: " + onTerminateTrigger.getLength());
|
Log.debug("onMonitorTouch: " + onMonitorTouchTrigger.getLength());
|
||||||
if (onTimerTrigger.getLength() > 0) Log.debug("onTimer: " + onTimerTrigger.getLength());
|
if (onMouseClickTrigger.getLength() > 0)
|
||||||
if (onTurtleInventoryTrigger.getLength() > 0) Log.debug("onTurtleInventory: " + onTurtleInventoryTrigger.getLength());
|
Log.debug("onMouseClick: " + onMouseClickTrigger.getLength());
|
||||||
if (onWebsocketCloseTrigger.getLength() > 0) Log.debug("onWebsocketClose: " + onWebsocketCloseTrigger.getLength());
|
if (onMouseDragTrigger.getLength() > 0)
|
||||||
if (onWebsocketFailureTrigger.getLength() > 0) Log.debug("onWebsocketFailure: " + onWebsocketFailureTrigger.getLength());
|
Log.debug("onMouseDrag: " + onMouseDragTrigger.getLength());
|
||||||
if (onWebsocketMessageTrigger.getLength() > 0) Log.debug("onWebsocketMessage: " + onWebsocketMessageTrigger.getLength());
|
if (onMouseScrollTrigger.getLength() > 0)
|
||||||
if (onWebsocketSuccessTrigger.getLength() > 0) Log.debug("onWebsocketSuccess: " + onWebsocketSuccessTrigger.getLength());
|
Log.debug("onMouseScroll: " + onMouseScrollTrigger.getLength());
|
||||||
|
if (onMouseUpTrigger.getLength() > 0)
|
||||||
|
Log.debug("onMouseUp: " + onMouseUpTrigger.getLength());
|
||||||
|
if (onPasteTrigger.getLength() > 0)
|
||||||
|
Log.debug("onPaste: " + onPasteTrigger.getLength());
|
||||||
|
if (onPeripheralTrigger.getLength() > 0)
|
||||||
|
Log.debug("onPeripheral: " + onPeripheralTrigger.getLength());
|
||||||
|
if (onPeripheralDetachTrigger.getLength() > 0)
|
||||||
|
Log.debug("onPeripheralDetach: " + onPeripheralDetachTrigger.getLength());
|
||||||
|
if (onRedstoneTrigger.getLength() > 0)
|
||||||
|
Log.debug("onRedstone: " + onRedstoneTrigger.getLength());
|
||||||
|
if (onSpeakerAudioEmptyTrigger.getLength() > 0)
|
||||||
|
Log.debug("onSpeakerAudioEmpty: " + onSpeakerAudioEmptyTrigger.getLength());
|
||||||
|
if (onTaskCompleteTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTaskComplete: " + onTaskCompleteTrigger.getLength());
|
||||||
|
if (onTermResizeTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTermResize: " + onTermResizeTrigger.getLength());
|
||||||
|
if (onTerminateTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTerminate: " + onTerminateTrigger.getLength());
|
||||||
|
if (onTimerTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTimer: " + onTimerTrigger.getLength());
|
||||||
|
if (onTurtleInventoryTrigger.getLength() > 0)
|
||||||
|
Log.debug("onTurtleInventory: " + onTurtleInventoryTrigger.getLength());
|
||||||
|
if (onWebsocketCloseTrigger.getLength() > 0)
|
||||||
|
Log.debug("onWebsocketClose: " + onWebsocketCloseTrigger.getLength());
|
||||||
|
if (onWebsocketFailureTrigger.getLength() > 0)
|
||||||
|
Log.debug("onWebsocketFailure: " + onWebsocketFailureTrigger.getLength());
|
||||||
|
if (onWebsocketMessageTrigger.getLength() > 0)
|
||||||
|
Log.debug("onWebsocketMessage: " + onWebsocketMessageTrigger.getLength());
|
||||||
|
if (onWebsocketSuccessTrigger.getLength() > 0)
|
||||||
|
Log.debug("onWebsocketSuccess: " + onWebsocketSuccessTrigger.getLength());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,51 +6,53 @@ import lib.KVStore;
|
|||||||
import cc.Settings;
|
import cc.Settings;
|
||||||
|
|
||||||
class KernelSettings {
|
class KernelSettings {
|
||||||
private static inline function setAllowStartup(value: Bool) {
|
private static inline function setAllowStartup(value:Bool) {
|
||||||
Settings.set("shell.allow_startup", value);
|
Settings.set("shell.allow_startup", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static inline function setAllowStartupFromFloppy(value: Bool) {
|
private static inline function setAllowStartupFromFloppy(value:Bool) {
|
||||||
Settings.set("shell.allow_disk_startup", value);
|
Settings.set("shell.allow_disk_startup", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function set(name: String, value: Dynamic) {
|
private static function set(name:String, value:Dynamic) {
|
||||||
var kvstore = new KVStore("kernel");
|
var kvstore = new KVStore("kernel");
|
||||||
kvstore.set(name, value);
|
kvstore.set(name, value);
|
||||||
kvstore.save();
|
kvstore.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function get(name: String): Null<Dynamic> {
|
private static function get(name:String):Null<Dynamic> {
|
||||||
var kvstore = new KVStore("kernel");
|
var kvstore = new KVStore("kernel");
|
||||||
return kvstore.get(name);
|
return kvstore.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var hostname(get,set): String;
|
public static var hostname(get, set):String;
|
||||||
private static var _hostname:String = get("hostname");
|
private static var _hostname:String = get("hostname");
|
||||||
private static inline function get_hostname():String {
|
|
||||||
|
private static inline function get_hostname():String {
|
||||||
return _hostname;
|
return _hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static inline function set_hostname(value:String):String {
|
private static inline function set_hostname(value:String):String {
|
||||||
OS.setComputerLabel(value);
|
OS.setComputerLabel(value);
|
||||||
set("hostname", value);
|
set("hostname", value);
|
||||||
_hostname = value;
|
_hostname = value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var siteController(get,set): NetworkID;
|
public static var nameServer(get, set):NetworkID;
|
||||||
private static var _siteController:NetworkID = get("siteController");
|
private static var _nameServer:NetworkID = get("nameServer");
|
||||||
private static function get_siteController():NetworkID {
|
|
||||||
return _siteController;
|
private static function get_nameServer():NetworkID {
|
||||||
|
return _nameServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function set_siteController(value:NetworkID):NetworkID {
|
private static function set_nameServer(value:NetworkID):NetworkID {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return get_siteController();
|
return get_nameServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
set("siteController", value);
|
set("nameServer", value);
|
||||||
_siteController = value;
|
_nameServer = value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package kernel;
|
package kernel;
|
||||||
|
|
||||||
import lib.Pos;
|
import lib.ScreenPos;
|
||||||
import kernel.ui.TermWriteable;
|
import kernel.ui.ITermWriteable;
|
||||||
import cc.Term;
|
import cc.Term;
|
||||||
import lib.Vec.Vec2;
|
import lib.Vec.Vec2;
|
||||||
import lib.Color;
|
import lib.Color;
|
||||||
@@ -11,7 +11,7 @@ using tink.CoreApi;
|
|||||||
/**
|
/**
|
||||||
Represents the main computer screen.
|
Represents the main computer screen.
|
||||||
**/
|
**/
|
||||||
class MainTerm implements TermWriteable {
|
class MainTerm implements ITermWriteable {
|
||||||
/**
|
/**
|
||||||
Depends on: KernelEvents,
|
Depends on: KernelEvents,
|
||||||
**/
|
**/
|
||||||
@@ -39,7 +39,7 @@ class MainTerm implements TermWriteable {
|
|||||||
Term.scroll(y);
|
Term.scroll(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCursorPos():Pos {
|
public function getCursorPos():ScreenPos {
|
||||||
var rtn = Term.getCursorPos();
|
var rtn = Term.getCursorPos();
|
||||||
return {
|
return {
|
||||||
x: rtn.x - 1,
|
x: rtn.x - 1,
|
||||||
@@ -60,7 +60,7 @@ class MainTerm implements TermWriteable {
|
|||||||
Term.setCursorBlink(blink);
|
Term.setCursorBlink(blink);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSize():Pos {
|
public function getSize():ScreenPos {
|
||||||
var rtn = Term.getSize();
|
var rtn = Term.getSize();
|
||||||
return {
|
return {
|
||||||
x: rtn.width,
|
x: rtn.width,
|
||||||
@@ -100,6 +100,6 @@ class MainTerm implements TermWriteable {
|
|||||||
this.setBackgroundColor(Black);
|
this.setBackgroundColor(Black);
|
||||||
this.setTextColor(White);
|
this.setTextColor(White);
|
||||||
this.clear();
|
this.clear();
|
||||||
this.setCursorPos(0,0);
|
this.setCursorPos(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package kernel.binstore;
|
package kernel.binstore;
|
||||||
|
|
||||||
import kernel.ps.Process;
|
import kernel.ps.IProcess;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Represents a callable program.
|
Represents a callable program.
|
||||||
**/
|
**/
|
||||||
typedef Bin = {
|
typedef Bin = {
|
||||||
c: Class<Process>,
|
c:Void->IProcess,
|
||||||
name: String,
|
name:String,
|
||||||
aliases: Array<String>,
|
aliases:Array<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +1,45 @@
|
|||||||
package kernel.binstore;
|
package kernel.binstore;
|
||||||
|
|
||||||
import bin.pathfinder.PFClient;
|
import kernel.ps.IProcess;
|
||||||
import bin.ID;
|
import macros.Binstore;
|
||||||
import bin.exporter.Res;
|
|
||||||
import bin.exporter.ResManager;
|
|
||||||
import bin.KSettings;
|
|
||||||
import bin.Perf;
|
|
||||||
import bin.srsc.CLI;
|
|
||||||
import bin.srsc.SiteRessourceController;
|
|
||||||
import bin.HelloWorldService;
|
|
||||||
import bin.Service;
|
|
||||||
import bin.LSPS;
|
|
||||||
import bin.Turtle;
|
|
||||||
import bin.Terminal;
|
|
||||||
import bin.Redstone;
|
|
||||||
import bin.Net;
|
|
||||||
import bin.KernelLog;
|
|
||||||
import bin.HelloWorld;
|
|
||||||
import bin.GPS;
|
|
||||||
import bin.Disk;
|
|
||||||
import haxe.ds.ReadOnlyArray;
|
|
||||||
|
|
||||||
class BinStore {
|
class BinStore {
|
||||||
private static final store:ReadOnlyArray<Bin> = [
|
private static final bins:Array<Bin> = populateStore();
|
||||||
{c: Disk, name: "Disk", aliases: ["disk"]},
|
|
||||||
{c: GPS, name: "GPS", aliases: ["gps"]},
|
|
||||||
{c: HelloWorld, name: "HelloWorld", aliases: ["hello"]},
|
|
||||||
{c: KernelLog, name: "KernelLog", aliases: ["log"]},
|
|
||||||
{c: Net, name: "Net", aliases: ["net"]},
|
|
||||||
{c: Redstone, name: "Redstone", aliases: ["redstone","rs"]},
|
|
||||||
{c: Terminal, name: "Terminal", aliases: ["terminal","term"]},
|
|
||||||
{c: Turtle, name: "Turtle", aliases: ["turtle"]},
|
|
||||||
{c: LSPS, name: "PM", aliases: ["lsps"]},
|
|
||||||
{c: Service, name: "Service", aliases: ["service","srv"]},
|
|
||||||
{c: HelloWorldService, name: "HelloWorldService", aliases: ["hello-service"] },
|
|
||||||
{c: SiteRessourceController, name: "SiteRessourceController", aliases: ["srsc"]},
|
|
||||||
{c: CLI, name: "SRSC CLI", aliases: ["srsc-cli"]},
|
|
||||||
{c: Perf, name: "Perf", aliases: ["perf"]},
|
|
||||||
{c: KSettings, name: "KSettings", aliases: ["ksettings","ks"]},
|
|
||||||
{c: ResManager, name: "ResManager", aliases: ["resmanager","resmgr"]},
|
|
||||||
{c: Res, name: "Res", aliases: ["res"]},
|
|
||||||
{c: ID , name: "ID", aliases: ["id"]},
|
|
||||||
{c: PFClient, name: "PFClient", aliases: ["pfclient"]}
|
|
||||||
];
|
|
||||||
|
|
||||||
public static function getBinByName(name:String):Null<Bin> {
|
private static function populateStore()
|
||||||
for (bin in store) {
|
return {
|
||||||
if (bin.name == name) {
|
var bins:Array<Bin> = [];
|
||||||
return bin;
|
Binstore.generateBinStore();
|
||||||
}
|
return bins;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getBinByAlias(alias:String):Null<Bin> {
|
public static function instantiate(alias:String):Null<IProcess> {
|
||||||
for (bin in store) {
|
for (bin in bins) {
|
||||||
for (a in bin.aliases) {
|
for (a in bin.aliases) {
|
||||||
if (a == alias) {
|
if (a == alias) {
|
||||||
return bin;
|
return bin.c();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getNameByAlias(alias: String): String {
|
private static function getBinByAlias(alias:String):Null<Bin> {
|
||||||
var bin = getBinByAlias(alias);
|
for (bin in bins) {
|
||||||
if (bin == null) {
|
for (a in bin.aliases) {
|
||||||
return null;
|
if (a == alias) {
|
||||||
}
|
return bin;
|
||||||
return bin.name;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNameByAlias(alias:String):Null<String> {
|
||||||
|
var bin = getBinByAlias(alias);
|
||||||
|
if (bin == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return bin.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,79 +13,79 @@ 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):ReadOnlyArray<String> {
|
public static inline function list(path:String):ReadOnlyArray<String> {
|
||||||
return FileSystem.list(path).toArray();
|
return FileSystem.list(path).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function combine(base: String, part: String): String {
|
public static inline function combine(base:String, part:String):String {
|
||||||
return FileSystem.combine(base,part);
|
return FileSystem.combine(base, part);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function getName(path: String): String {
|
public static inline function getName(path:String):String {
|
||||||
return FileSystem.getName(path);
|
return FileSystem.getName(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function getDir(path: String): String {
|
public static inline function getDir(path:String):String {
|
||||||
return FileSystem.getDir(path);
|
return FileSystem.getDir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function getSize(path: String):Int {
|
public static inline function getSize(path:String):Int {
|
||||||
return FileSystem.getSize(path);
|
return FileSystem.getSize(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function exists(path: String):Bool {
|
public static inline function exists(path:String):Bool {
|
||||||
return FileSystem.exists(path);
|
return FileSystem.exists(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function isDir(path: String): Bool {
|
public static inline function isDir(path:String):Bool {
|
||||||
return FileSystem.isDir(path);
|
return FileSystem.isDir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function isReadOnly(path: String):Bool {
|
public static inline function isReadOnly(path:String):Bool {
|
||||||
return FileSystem.isReadOnly(path);
|
return FileSystem.isReadOnly(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function makeDir(path: String):Void {
|
public static inline function makeDir(path:String):Void {
|
||||||
FileSystem.makeDir(path);
|
FileSystem.makeDir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function move(src:String,dest:String):Void {
|
public static inline function move(src:String, dest:String):Void {
|
||||||
FileSystem.move(src,dest);
|
FileSystem.move(src, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function copy(src:String,dest:String):Void {
|
public static inline function copy(src:String, dest:String):Void {
|
||||||
FileSystem.copy(src,dest);
|
FileSystem.copy(src, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function delete(path: String):Void {
|
public static inline function delete(path:String):Void {
|
||||||
FileSystem.delete(path);
|
FileSystem.delete(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openRead(path:String): ReadHandle{
|
public static inline function openRead(path:String):ReadHandle {
|
||||||
return FileSystem.open(path,Read);
|
return FileSystem.open(path, Read);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openWrite(path: String): WriteHandle {
|
public static inline function openWrite(path:String):WriteHandle {
|
||||||
return FileSystem.open(path,Write);
|
return FileSystem.open(path, Write);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openAppend(path: String): WriteHandle {
|
public static inline function openAppend(path:String):WriteHandle {
|
||||||
return FileSystem.open(path,Append);
|
return FileSystem.open(path, Append);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openReadBinary(path:String): ReadBinaryHandle {
|
public static inline function openReadBinary(path:String):ReadBinaryHandle {
|
||||||
return FileSystem.open(path,BinaryRead);
|
return FileSystem.open(path, BinaryRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openWriteBinary(path: String): WriteBinaryHandle {
|
public static inline function openWriteBinary(path:String):WriteBinaryHandle {
|
||||||
return FileSystem.open(path,BinaryWrite);
|
return FileSystem.open(path, BinaryWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function openAppendBinary(path: String): WriteBinaryHandle {
|
public static inline function openAppendBinary(path:String):WriteBinaryHandle {
|
||||||
return FileSystem.open(path,BinaryAppend);
|
return FileSystem.open(path, BinaryAppend);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function find(pattern: String):ReadOnlyArray<String> {
|
public static inline function find(pattern:String):ReadOnlyArray<String> {
|
||||||
return FileSystem.find(pattern).toArray();
|
return FileSystem.find(pattern).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ class FS {
|
|||||||
return FileSystem.getCapacity(path);
|
return FileSystem.getCapacity(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static inline function attributes(path: String):FileAttributes {
|
public static inline function attributes(path:String):FileAttributes {
|
||||||
return FileSystem.attributes(path);
|
return FileSystem.attributes(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,107 +5,103 @@ import cc.FileSystem.FileHandle;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
abstract ReadHandle(FileHandle) from FileHandle {
|
abstract ReadHandle(FileHandle) from FileHandle {
|
||||||
|
|
||||||
public inline function new(handle:FileHandle) {
|
public inline function new(handle:FileHandle) {
|
||||||
this = handle;
|
this = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readLine(?withTrailing:Bool = false):Null<String>{
|
public inline function readLine(?withTrailing:Bool = false):Null<String> {
|
||||||
return this.readLine(withTrailing);
|
return this.readLine(withTrailing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readAll():Null<String>{
|
public inline function readAll():Null<String> {
|
||||||
return this.readAll();
|
return this.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function read(?count:Int = 1):Null<String>{
|
public inline function read(?count:Int = 1):Null<String> {
|
||||||
return this.read(count);
|
return this.read(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function close():Void{
|
public inline function close():Void {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract WriteHandle(FileHandle) from FileHandle {
|
abstract WriteHandle(FileHandle) from FileHandle {
|
||||||
|
|
||||||
public inline function new(handle:FileHandle) {
|
public inline function new(handle:FileHandle) {
|
||||||
this = handle;
|
this = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function write(data:String):Void{
|
public inline function write(data:String):Void {
|
||||||
this.write(data);
|
this.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function writeLine(data:String):Void{
|
public inline function writeLine(data:String):Void {
|
||||||
this.writeLine(data);
|
this.writeLine(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function flush():Void{
|
public inline function flush():Void {
|
||||||
this.flush();
|
this.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function close():Void{
|
public inline function close():Void {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract ReadBinaryHandle(FileHandle) from FileHandle {
|
abstract ReadBinaryHandle(FileHandle) from FileHandle {
|
||||||
|
|
||||||
public inline function new(handle:FileHandle) {
|
public inline function new(handle:FileHandle) {
|
||||||
this = handle;
|
this = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readLine(?withTrailing:Bool = false):Null<String>{
|
public inline function readLine(?withTrailing:Bool = false):Null<String> {
|
||||||
return this.readLine(withTrailing);
|
return this.readLine(withTrailing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readAll():Null<String>{
|
public inline function readAll():Null<String> {
|
||||||
return this.readAll();
|
return this.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function read(count:Int):Null<String>{
|
public inline function read(count:Int):Null<String> {
|
||||||
return this.read(count);
|
return this.read(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function readByte():Null<Int>{
|
public inline function readByte():Null<Int> {
|
||||||
return this.read();
|
return this.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void{
|
public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void {
|
||||||
this.seek(whence,offset);
|
this.seek(whence, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function close():Void{
|
public inline function close():Void {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract WriteBinaryHandle(FileHandle) from FileHandle {
|
abstract WriteBinaryHandle(FileHandle) from FileHandle {
|
||||||
|
|
||||||
public inline function new(handle:FileHandle) {
|
public inline function new(handle:FileHandle) {
|
||||||
this = handle;
|
this = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function write(data: String):Void{
|
public inline function write(data:String):Void {
|
||||||
this.write(data);
|
this.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
public inline function writeByte(data: Int):Void{
|
public inline function writeByte(data:Int):Void {
|
||||||
// this.write(data);
|
// this.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function flush():Void{
|
public inline function flush():Void {
|
||||||
this.flush();
|
this.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function close():Void{
|
public inline function close():Void {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void{
|
public inline function seek(?whence:BinarySeekWhence = Current, ?offset:Int):Void {
|
||||||
this.seek(whence,offset);
|
this.seek(whence, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package kernel.gps;
|
package kernel.gps;
|
||||||
|
|
||||||
|
import lib.SingleTimeoutPromise;
|
||||||
import kernel.log.Log;
|
import kernel.log.Log;
|
||||||
import lib.KVStore;
|
import lib.KVStore;
|
||||||
import kernel.net.Net;
|
import kernel.net.Net;
|
||||||
import kernel.net.INetworkInterface;
|
import kernel.net.INetworkInterface;
|
||||||
import kernel.net.Package;
|
import kernel.net.Package;
|
||||||
import lib.Pos3;
|
import lib.WorldPos;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
@@ -15,22 +16,24 @@ using tink.CoreApi;
|
|||||||
You need at least 3 computers that know their position to determine the position of the computer.
|
You need at least 3 computers that know their position to determine the position of the computer.
|
||||||
**/
|
**/
|
||||||
class GPS {
|
class GPS {
|
||||||
|
private static inline final TIMEOUT:Int = 1;
|
||||||
|
|
||||||
private static var shouldRespond = true;
|
private static var shouldRespond = true;
|
||||||
private static var shouldDoWholeNumberCheck = true;
|
private static var shouldDoWholeNumberCheck = true;
|
||||||
private static var posAccuracy = 0; // 0 = unkown, 1 = (ins,best guess), 2 = (stored/manual,should be right), 3 = (gps,confirmed)
|
private static var posAccuracy = 0; // 0 = unkown, 1 = (ins,best guess), 2 = (stored/manual,should be right), 3 = (gps,confirmed)
|
||||||
private static var cachedPosition:Pos3;
|
private static var cachedPosition:WorldPos;
|
||||||
private static var lastPositionResponse: Array<{pos:Pos3,dist:Float}> = [];
|
private static var lastPositionResponse:Array<{pos:WorldPos, dist:Float}> = [];
|
||||||
|
|
||||||
private static var futureResolve: (pos:Null<Pos3>) -> Void = null;
|
private static final locatePromise:SingleTimeoutPromise<WorldPos> = new SingleTimeoutPromise(TIMEOUT, brodcastPositionRequest);
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
loadCachedPosition();
|
loadCachedPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setManualPosition(pos:Pos3) {
|
public static function setManualPosition(pos:WorldPos) {
|
||||||
var kvstore = new KVStore("gps");
|
var kvstore = new KVStore("gps");
|
||||||
kvstore.set("mpos",pos);
|
kvstore.set("mpos", pos);
|
||||||
kvstore.save();
|
kvstore.save();
|
||||||
|
|
||||||
if (cachedPosition == null) {
|
if (cachedPosition == null) {
|
||||||
@@ -40,12 +43,12 @@ class GPS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:allow(kernel.gps.INS)
|
@:allow(kernel.gps.INS)
|
||||||
private static function setINSPosition(pos:Pos3) {
|
private static function setINSPosition(pos:WorldPos) {
|
||||||
cachedPosition = pos;
|
cachedPosition = pos;
|
||||||
posAccuracy = 1;
|
posAccuracy = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPosition():Null<Pos3> {
|
public static function getPosition():Null<WorldPos> {
|
||||||
return cachedPosition;
|
return cachedPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,25 +61,16 @@ class GPS {
|
|||||||
posAccuracy = 0;
|
posAccuracy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function locate():Future<Null<Pos3>> {
|
public static function locate():Promise<WorldPos> {
|
||||||
// TODO: implenet a timeout
|
return locatePromise.request();
|
||||||
// TODO: dont send a request twice if the last one is still pending or we moved
|
|
||||||
return new Future<Null<Pos3>>((resolve)->{
|
|
||||||
futureResolve = resolve;
|
|
||||||
sendPositionRequest();
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function resolveFuture(pos:Null<Pos3>) {
|
|
||||||
futureResolve(pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function persistCachedPositon() {
|
private static function persistCachedPositon() {
|
||||||
if (cachedPosition == null) return;
|
if (cachedPosition == null)
|
||||||
|
return;
|
||||||
var kvstore = new KVStore("gps");
|
var kvstore = new KVStore("gps");
|
||||||
|
|
||||||
kvstore.set("cpos",cachedPosition);
|
kvstore.set("cpos", cachedPosition);
|
||||||
kvstore.save();
|
kvstore.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +78,8 @@ class GPS {
|
|||||||
var kvstore = new KVStore("gps");
|
var kvstore = new KVStore("gps");
|
||||||
kvstore.load();
|
kvstore.load();
|
||||||
|
|
||||||
var mPos:Null<Pos3> = kvstore.get("mpos"); // Manual set position
|
var mPos:Null<WorldPos> = kvstore.get("mpos"); // Manual set position
|
||||||
var cPos:Null<Pos3> = kvstore.get("cpos"); // Cached position
|
var cPos:Null<WorldPos> = kvstore.get("cpos"); // Cached position
|
||||||
|
|
||||||
if (mPos != null && cPos != null && mPos == cPos) {
|
if (mPos != null && cPos != null && mPos == cPos) {
|
||||||
// Both are the same, so we can use the cached position
|
// Both are the same, so we can use the cached position
|
||||||
@@ -94,7 +88,7 @@ class GPS {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPos != null && cPos != null && mPos != cPos){
|
if (mPos != null && cPos != null && mPos != cPos) {
|
||||||
// Both are different, so we can use the manual position
|
// Both are different, so we can use the manual position
|
||||||
cachedPosition = mPos;
|
cachedPosition = mPos;
|
||||||
posAccuracy = 1;
|
posAccuracy = 1;
|
||||||
@@ -114,51 +108,62 @@ class GPS {
|
|||||||
posAccuracy = 2;
|
posAccuracy = 2;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function sendPositionRequest() {
|
private static function brodcastPositionRequest() {
|
||||||
Net.brodcastGPSRequest();
|
Net.brodcastGPSRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@:allow(kernel.net.Net)
|
@:allow(kernel.net.Net)
|
||||||
private static function handlePackage(pack:Package<Noise>, dist: Float,iface: INetworkInterface) {
|
private static function handlePackage(pack:Package<Noise>, dist:Null<Float>, iface:INetworkInterface) {
|
||||||
|
if (dist == null) {
|
||||||
|
// Message comes from another dimension and has no distance.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (pack.type) {
|
switch (pack.type) {
|
||||||
case GPSRequest:
|
case GPSRequest:
|
||||||
if (!shouldRespond) return;
|
if (!shouldRespond)
|
||||||
if (posAccuracy < 2) return;
|
return;
|
||||||
if (cachedPosition == null) return;
|
if (posAccuracy < 2)
|
||||||
|
return;
|
||||||
|
if (cachedPosition == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var response = new Package(Net.networkID,pack.fromID, pack.msgID, GPSResponse(cachedPosition),null,0);
|
var response = new Package(Net.networkID, pack.fromID, pack.msgID, GPSResponse(cachedPosition.x, cachedPosition.y, cachedPosition.z,), null, 0);
|
||||||
iface.send(pack.fromID,Net.networkID,response);
|
iface.send(pack.fromID, Net.networkID, response);
|
||||||
case GPSResponse(pos):
|
case GPSResponse(x, y, z):
|
||||||
if (lastPositionResponse.contains({pos:pos,dist:dist})) return; // Ignore duplicate responses
|
if (lastPositionResponse.contains({pos: {x: x, y: y, z: z}, dist: dist}))
|
||||||
|
return; // Ignore duplicate responses
|
||||||
|
|
||||||
lastPositionResponse.push({pos:pos,dist:dist});
|
lastPositionResponse.push({pos: {x: x, y: y, z: z}, dist: dist});
|
||||||
|
|
||||||
// TODO: wait for a few seconds before calculating the position, so we can get more responses
|
// TODO: wait for a few seconds before calculating the position, so we can get more responses
|
||||||
|
|
||||||
if (lastPositionResponse.length < 4) return; // We need at least 3 responses to calculate the position
|
if (lastPositionResponse.length < 4)
|
||||||
|
return; // We need at least 3 responses to calculate the position
|
||||||
|
|
||||||
var calculatedPosition = calculatePosition();
|
var calculatedPosition = calculatePosition();
|
||||||
|
|
||||||
if (calculatedPosition != null){
|
if (calculatedPosition != null) {
|
||||||
calculatedPosition = calculatedPosition.round();
|
calculatedPosition = calculatedPosition.round();
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPositionResponse = []; // Reset the response array
|
lastPositionResponse = []; // Reset the response array
|
||||||
|
|
||||||
if (calculatedPosition == null) return;
|
if (calculatedPosition == null)
|
||||||
|
return;
|
||||||
cachedPosition = calculatedPosition;
|
cachedPosition = calculatedPosition;
|
||||||
posAccuracy = 3;
|
posAccuracy = 3;
|
||||||
|
|
||||||
resolveFuture(calculatedPosition);
|
locatePromise.resolve(calculatedPosition);
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function calculatePosition():Null<Pos3> {
|
private static function calculatePosition():Null<WorldPos> {
|
||||||
if (lastPositionResponse.length < 3) return null;
|
if (lastPositionResponse.length < 3)
|
||||||
|
return null;
|
||||||
|
|
||||||
// do a simple trilateration with the last 3 responses for now
|
// do a simple trilateration with the last 3 responses for now
|
||||||
var p1 = lastPositionResponse[0].pos;
|
var p1 = lastPositionResponse[0].pos;
|
||||||
@@ -169,13 +174,14 @@ class GPS {
|
|||||||
var r2 = lastPositionResponse[1].dist;
|
var r2 = lastPositionResponse[1].dist;
|
||||||
var r3 = lastPositionResponse[2].dist;
|
var r3 = lastPositionResponse[2].dist;
|
||||||
|
|
||||||
var result = trilateration(p1,p2,p3,r1,r2,r3);
|
var result = trilateration(p1, p2, p3, r1, r2, r3);
|
||||||
|
|
||||||
if (result.a.close(result.b)) return result.a;
|
if (result.a.close(result.b))
|
||||||
|
return result.a;
|
||||||
|
|
||||||
// If we have more than 3 responses, we can use the 4th response to determine which of the two positions is correct
|
// If we have more than 3 responses, we can use the 4th response to determine which of the two positions is correct
|
||||||
// TODO: if this is a pocket computer we cant use this since it can move freely
|
// TODO: if this is a pocket computer we cant use this since it can move freely
|
||||||
if (lastPositionResponse.length > 3){
|
if (lastPositionResponse.length > 3) {
|
||||||
var err1 = Math.abs(result.a.distance(lastPositionResponse[3].pos) - lastPositionResponse[3].dist);
|
var err1 = Math.abs(result.a.distance(lastPositionResponse[3].pos) - lastPositionResponse[3].dist);
|
||||||
var err2 = Math.abs(result.b.distance(lastPositionResponse[3].pos) - lastPositionResponse[3].dist);
|
var err2 = Math.abs(result.b.distance(lastPositionResponse[3].pos) - lastPositionResponse[3].dist);
|
||||||
|
|
||||||
@@ -184,12 +190,15 @@ class GPS {
|
|||||||
return null; // The two positions are essentially the same, so we cant determine which one is correct
|
return null; // The two positions are essentially the same, so we cant determine which one is correct
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err1 < err2) return result.a;
|
if (err1 < err2)
|
||||||
if (err2 < err1) return result.b;
|
return result.a;
|
||||||
|
if (err2 < err1)
|
||||||
|
return result.b;
|
||||||
}
|
}
|
||||||
|
|
||||||
// last resort, just use the position that is closest to a whole number (whithin a resonable margin of error)
|
// last resort, just use the position that is closest to a whole number (whithin a resonable margin of error)
|
||||||
if (!shouldDoWholeNumberCheck) return null;
|
if (!shouldDoWholeNumberCheck)
|
||||||
|
return null;
|
||||||
|
|
||||||
// TODO: mark the position as not so accurate if we use this method
|
// TODO: mark the position as not so accurate if we use this method
|
||||||
|
|
||||||
@@ -208,7 +217,7 @@ class GPS {
|
|||||||
/**
|
/**
|
||||||
Determines the position(s) of a point given 3 other points and the distance to each of them.
|
Determines the position(s) of a point given 3 other points and the distance to each of them.
|
||||||
**/
|
**/
|
||||||
private static function trilateration(p1:Pos3,p2:Pos3,p3: Pos3,r1:Float,r2:Float,r3:Float):Pair<Pos3,Pos3> {
|
private static function trilateration(p1:WorldPos, p2:WorldPos, p3:WorldPos, r1:Float, r2:Float, r3:Float):Pair<WorldPos, WorldPos> {
|
||||||
var a2b = p2 - p1;
|
var a2b = p2 - p1;
|
||||||
var a2c = p3 - p1;
|
var a2c = p3 - p1;
|
||||||
|
|
||||||
@@ -217,7 +226,7 @@ class GPS {
|
|||||||
var i = ex.dot(a2c);
|
var i = ex.dot(a2c);
|
||||||
var ey = (a2c - ex * i).normalize();
|
var ey = (a2c - ex * i).normalize();
|
||||||
var j = ey.dot(a2c);
|
var j = ey.dot(a2c);
|
||||||
var ez = ex.cross(ey);
|
var ez:WorldPos = ex.cross(ey);
|
||||||
|
|
||||||
var x = (r1 * r1 - r2 * r2 + d * d) / (2 * d);
|
var x = (r1 * r1 - r2 * r2 + d * d) / (2 * d);
|
||||||
var y = (r1 * r1 - r3 * r3 - x * x + (x - i) * (x - i) + j * j) / (2 * j);
|
var y = (r1 * r1 - r3 * r3 - x * x + (x - i) * (x - i) + j * j) / (2 * j);
|
||||||
@@ -227,9 +236,9 @@ class GPS {
|
|||||||
var zSquared = r1 * r1 - x * x - y * y;
|
var zSquared = r1 * r1 - x * x - y * y;
|
||||||
if (zSquared > 0) {
|
if (zSquared > 0) {
|
||||||
var z = Math.sqrt(zSquared);
|
var z = Math.sqrt(zSquared);
|
||||||
return new Pair(result + (ez * z),result - (ez * z));
|
return new Pair(result + (ez * z), result - (ez * z));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Pair(result,result);
|
return new Pair(result, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package kernel.gps;
|
package kernel.gps;
|
||||||
|
|
||||||
import kernel.log.Log;
|
import lib.SinglePromise;
|
||||||
import kernel.turtle.Turtle;
|
import kernel.turtle.Turtle;
|
||||||
import lib.Pos3;
|
import lib.WorldPos;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class INS {
|
class INS {
|
||||||
private static var heading: Null<Pos3> = null;
|
private static var heading:Null<WorldPos> = null;
|
||||||
private static var alingment: Int = 1; // 0 = degraded, 1 = not aligned, 2 = aligned
|
private static var alingment:Int = 1; // 0 = degraded, 1 = not aligned, 2 = aligned
|
||||||
|
private static final alignPromise:SinglePromise<Noise> = new SinglePromise(startAlign);
|
||||||
|
|
||||||
@:allow(kernel.turtle.Turtle)
|
@:allow(kernel.turtle.Turtle)
|
||||||
private static function moveForward() {
|
private static function moveForward() {
|
||||||
@@ -40,7 +41,8 @@ class INS {
|
|||||||
|
|
||||||
@:allow(kernel.turtle.Turtle)
|
@:allow(kernel.turtle.Turtle)
|
||||||
private static function turnLeft() {
|
private static function turnLeft() {
|
||||||
if (heading == null) return;
|
if (heading == null)
|
||||||
|
return;
|
||||||
if (heading.x == 0 && heading.z == -1) {
|
if (heading.x == 0 && heading.z == -1) {
|
||||||
heading = {x: -1, y: 0, z: 0};
|
heading = {x: -1, y: 0, z: 0};
|
||||||
} else if (heading.x == -1 && heading.z == 0) {
|
} else if (heading.x == -1 && heading.z == 0) {
|
||||||
@@ -54,7 +56,8 @@ class INS {
|
|||||||
|
|
||||||
@:allow(kernel.turtle.Turtle)
|
@:allow(kernel.turtle.Turtle)
|
||||||
private static function turnRight() {
|
private static function turnRight() {
|
||||||
if (heading == null) return;
|
if (heading == null)
|
||||||
|
return;
|
||||||
if (heading.x == 0 && heading.z == -1) {
|
if (heading.x == 0 && heading.z == -1) {
|
||||||
heading = {x: 1, y: 0, z: 0};
|
heading = {x: 1, y: 0, z: 0};
|
||||||
} else if (heading.x == -1 && heading.z == 0) {
|
} else if (heading.x == -1 && heading.z == 0) {
|
||||||
@@ -66,81 +69,78 @@ class INS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function move(dir: Null<Pos3>) {
|
private static function move(dir:Null<WorldPos>) {
|
||||||
Log.debug('INS move: $dir');
|
if (alignPromise.isRunning()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var pos = GPS.getPosition();
|
var pos = GPS.getPosition();
|
||||||
|
if (pos == null || dir == null)
|
||||||
|
return;
|
||||||
var newPos = pos + dir;
|
var newPos = pos + dir;
|
||||||
GPS.setINSPosition(newPos);
|
GPS.setINSPosition(newPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getHeading():Null<Pos3> {
|
public static function getHeading():Null<WorldPos> {
|
||||||
return heading;
|
return heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function align(): Promise<Noise> {
|
public static function align():Promise<Noise> {
|
||||||
Log.info("Aligning INS");
|
return alignPromise.request();
|
||||||
return new Promise<Noise>((resolve,reject)->{
|
}
|
||||||
|
|
||||||
if (Turtle.instance.getFuelLevel() < 2){
|
public static function startAlign():Void {
|
||||||
Log.warn("Not enough fuel to align");
|
if (Turtle.getFuelLevel() < 2) {
|
||||||
reject(new Error("Not enough fuel to align"));
|
alignPromise.reject(new Error("Not enough fuel to align"));
|
||||||
return null;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GPS.locate().handle((result) -> {
|
||||||
|
switch result {
|
||||||
|
case Failure(err):
|
||||||
|
alignPromise.reject(new Error("Failed to locate 1st positon: " + err));
|
||||||
|
return;
|
||||||
|
case Success(pos1):
|
||||||
|
var moved = tryMoving();
|
||||||
|
|
||||||
|
if (moved == -1) {
|
||||||
|
alignPromise.reject(new Error("Can't move"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GPS.locate().handle((result2) -> {
|
||||||
|
switch result2 {
|
||||||
|
case Failure(err):
|
||||||
|
alignPromise.reject(new Error("GPS not available for 2nd position: " + err));
|
||||||
|
return;
|
||||||
|
case Success(pos2):
|
||||||
|
var cHeading = calcHeading(pos1, pos2, moved);
|
||||||
|
if (cHeading == null) {
|
||||||
|
alignPromise.reject(new Error("Can't calculate heading"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
heading = cHeading;
|
||||||
|
moveBack(moved);
|
||||||
|
GPS.setINSPosition(pos1);
|
||||||
|
|
||||||
|
alignPromise.resolve(Noise);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
GPS.locate().handle((pos1)->{
|
|
||||||
Log.debug('pos1: $pos1');
|
|
||||||
if (pos1 == null) {
|
|
||||||
Log.warn("GPS not available for 1st position");
|
|
||||||
reject(new Error("GPS not available"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var moved = tryMoving();
|
|
||||||
|
|
||||||
if (moved == -1) {
|
|
||||||
Log.warn("Can't move");
|
|
||||||
reject(new Error("Can't move"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GPS.locate().handle((pos2)->{
|
|
||||||
Log.debug('pos2: $pos2');
|
|
||||||
if (pos2 == null) {
|
|
||||||
Log.warn("GPS not available for 2nd position");
|
|
||||||
reject(new Error("GPS not available for 2nd position"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var cHeading = calcHeading(pos1,pos2,moved);
|
|
||||||
if (cHeading == null) {
|
|
||||||
Log.error("Can't calculate heading");
|
|
||||||
reject(new Error("Can't calculate heading"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
heading = cHeading;
|
|
||||||
moveBack(moved);
|
|
||||||
GPS.setINSPosition(pos1);
|
|
||||||
|
|
||||||
resolve(Noise);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// -1 = not moved, 0 = back, 1 = forward, 2 = left, 3 = right
|
// -1 = not moved, 0 = back, 1 = forward, 2 = left, 3 = right
|
||||||
private static function tryMoving():Int {
|
private static function tryMoving():Int {
|
||||||
if (Turtle.instance.back().isSuccess()) {
|
if (Turtle.back().isSuccess()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (Turtle.instance.forward().isSuccess()) {
|
} else if (Turtle.forward().isSuccess()) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
Turtle.instance.turnLeft(); // TODO: Check if successfull
|
Turtle.turnLeft(); // TODO: Check if successfull
|
||||||
if (Turtle.instance.forward().isSuccess()){
|
if (Turtle.forward().isSuccess()) {
|
||||||
return 2;
|
return 2;
|
||||||
} else if (Turtle.instance.back().isSuccess()) {
|
} else if (Turtle.back().isSuccess()) {
|
||||||
return 3;
|
return 3;
|
||||||
} else {
|
} else {
|
||||||
// Can't move
|
// Can't move
|
||||||
@@ -149,7 +149,7 @@ class INS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function calcHeading(pos1: Pos3,pos2:Pos3,moved:Int): Null<Pos3> {
|
private static function calcHeading(pos1:WorldPos, pos2:WorldPos, moved:Int):Null<WorldPos> {
|
||||||
if (moved == 0) {
|
if (moved == 0) {
|
||||||
return pos1 - pos2;
|
return pos1 - pos2;
|
||||||
} else if (moved == 1) {
|
} else if (moved == 1) {
|
||||||
@@ -165,25 +165,19 @@ class INS {
|
|||||||
|
|
||||||
private static function moveBack(moved:Int) {
|
private static function moveBack(moved:Int) {
|
||||||
if (moved == 0) {
|
if (moved == 0) {
|
||||||
Turtle.instance.forward();
|
Turtle.forward();
|
||||||
// cc.Turtle.forward();
|
|
||||||
} else if (moved == 1) {
|
} else if (moved == 1) {
|
||||||
Turtle.instance.back();
|
Turtle.back();
|
||||||
// cc.Turtle.back();
|
|
||||||
} else if (moved == 2) {
|
} else if (moved == 2) {
|
||||||
Turtle.instance.back();
|
Turtle.back();
|
||||||
// cc.Turtle.back();
|
Turtle.turnRight();
|
||||||
Turtle.instance.turnRight();
|
|
||||||
// cc.Turtle.turnRight();
|
|
||||||
} else if (moved == 3) {
|
} else if (moved == 3) {
|
||||||
Turtle.instance.forward();
|
Turtle.forward();
|
||||||
// cc.Turtle.forward();
|
Turtle.turnRight();
|
||||||
Turtle.instance.turnRight();
|
|
||||||
// cc.Turtle.turnRight();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function rotatePos3ToRight(pos:Pos3):Pos3 {
|
private static function rotatePos3ToRight(pos:WorldPos):WorldPos {
|
||||||
if (pos.x == 0 && pos.z == -1) {
|
if (pos.x == 0 && pos.z == -1) {
|
||||||
return {x: 1, y: 0, z: 0};
|
return {x: 1, y: 0, z: 0};
|
||||||
} else if (pos.x == -1 && pos.z == 0) {
|
} else if (pos.x == -1 && pos.z == 0) {
|
||||||
@@ -197,8 +191,7 @@ class INS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function rotatePos3ToLeft(pos3:Pos3):Pos3 {
|
private static function rotatePos3ToLeft(pos3:WorldPos):WorldPos {
|
||||||
return rotatePos3ToRight(rotatePos3ToRight(rotatePos3ToRight(pos3)));
|
return rotatePos3ToRight(rotatePos3ToRight(rotatePos3ToRight(pos3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,15 @@ package kernel.http;
|
|||||||
using lua.Table;
|
using lua.Table;
|
||||||
|
|
||||||
class HTTPFailure {
|
class HTTPFailure {
|
||||||
|
|
||||||
public final reason:String;
|
public final reason:String;
|
||||||
public final statusCode:Null<StatusCode>;
|
public final statusCode:Null<StatusCode>;
|
||||||
public final headers:Map<String,String>;
|
public final headers:Map<String, String>;
|
||||||
public final body:String;
|
public final body:String;
|
||||||
|
|
||||||
@:allow(kernel.http)
|
@:allow(kernel.http)
|
||||||
private function new(failReason: String, ?handle: cc.HTTP.HTTPResponse) {
|
private function new(failReason:String, ?handle:cc.HTTP.HTTPResponse) {
|
||||||
this.reason = failReason;
|
this.reason = failReason;
|
||||||
if (handle != null){
|
if (handle != null) {
|
||||||
this.statusCode = handle.getResponseCode();
|
this.statusCode = handle.getResponseCode();
|
||||||
this.headers = handle.getResponseHeaders().toMap();
|
this.headers = handle.getResponseHeaders().toMap();
|
||||||
this.body = handle.readAll();
|
this.body = handle.readAll();
|
||||||
|
|||||||
@@ -6,21 +6,21 @@ using tink.CoreApi;
|
|||||||
Wrapper for the native HTTP request function.
|
Wrapper for the native HTTP request function.
|
||||||
**/
|
**/
|
||||||
class Http {
|
class Http {
|
||||||
public static function request(url:String,?body:String,?options: String):Future<Outcome<HTTPResponse,HTTPFailure>> {
|
public static function request(url:String, ?body:String, ?options:String):Future<Outcome<HTTPResponse, HTTPFailure>> {
|
||||||
return new Future<Outcome<HTTPResponse,HTTPFailure>>((resolve) -> {
|
return new Future<Outcome<HTTPResponse, HTTPFailure>>((resolve) -> {
|
||||||
KernelEvents.onHttpFailure.handle((params)->{
|
KernelEvents.onHttpFailure.handle((params) -> {
|
||||||
if (params.url == url){
|
if (params.url == url) {
|
||||||
resolve(Failure(new HTTPFailure(params.failReason,params.handle)));
|
resolve(Failure(new HTTPFailure(params.failReason, params.handle)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.onHttpSuccess.handle((params) -> {
|
KernelEvents.onHttpSuccess.handle((params) -> {
|
||||||
if (params.url == url){
|
if (params.url == url) {
|
||||||
resolve(Success(new HTTPResponse(params.handle)));
|
resolve(Success(new HTTPResponse(params.handle)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cc.HTTP.request(url,body);
|
cc.HTTP.request(url, body);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ package kernel.http;
|
|||||||
using lua.Table;
|
using lua.Table;
|
||||||
|
|
||||||
class HTTPResponse {
|
class HTTPResponse {
|
||||||
|
|
||||||
public final statusCode:StatusCode;
|
public final statusCode:StatusCode;
|
||||||
public final headers:Map<String,String>;
|
public final headers:Map<String, String>;
|
||||||
public final body:String;
|
public final body:String;
|
||||||
|
|
||||||
@:allow(kernel.http)
|
@:allow(kernel.http)
|
||||||
private function new(handle: cc.HTTP.HTTPResponse) {
|
private function new(handle:cc.HTTP.HTTPResponse) {
|
||||||
this.statusCode = handle.getResponseCode();
|
this.statusCode = handle.getResponseCode();
|
||||||
this.headers = handle.getResponseHeaders().toMap();
|
this.headers = handle.getResponseHeaders().toMap();
|
||||||
this.body = handle.readAll();
|
this.body = handle.readAll();
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package kernel.log;
|
package kernel.log;
|
||||||
|
|
||||||
import haxe.ds.ReadOnlyArray;
|
import haxe.ds.ReadOnlyArray;
|
||||||
#if webconsole
|
import haxe.macro.Context;
|
||||||
|
#if (webconsole && !macro)
|
||||||
import lib.Debug;
|
import lib.Debug;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
@@ -21,32 +22,62 @@ class Log {
|
|||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
onLog = onLogTrigger.asSignal();
|
onLog = onLogTrigger.asSignal();
|
||||||
}
|
|
||||||
|
|
||||||
public static function info(msg:Dynamic, ?pos:haxe.PosInfos) {
|
|
||||||
log({level: Info, message: Std.string(msg),time: 0},pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function warn(msg:Dynamic, ?pos:haxe.PosInfos) {
|
|
||||||
log({level: Warn, message: Std.string(msg),time: 0},pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function error(msg:Dynamic, ?pos:haxe.PosInfos) {
|
|
||||||
log({level: Error, message: Std.string(msg),time: 0},pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function debug(msg:Dynamic, ?pos:haxe.PosInfos) {
|
|
||||||
#if debug
|
#if debug
|
||||||
log({level: Debug, message: Std.string(msg),time: 0},pos);
|
haxe.Log.trace = function(v:Dynamic, ?infos:haxe.PosInfos) {
|
||||||
|
Log._debug(v, infos.className);
|
||||||
|
}
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function silly(msg:Dynamic, ?pos:haxe.PosInfos) {
|
public static function _info(msg:Dynamic, ?origin:String) {
|
||||||
log({level: Silly, message: Std.string(msg),time: 0},pos);
|
log({
|
||||||
|
level: Info,
|
||||||
|
message: Std.string(msg),
|
||||||
|
time: 0,
|
||||||
|
origin: origin
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function log(line: LogLine, ?pos:haxe.PosInfos) {
|
public static function _warn(msg:Dynamic, ?origin:String) {
|
||||||
line.origin = pos.className;
|
log({
|
||||||
|
level: Warn,
|
||||||
|
message: Std.string(msg),
|
||||||
|
time: 0,
|
||||||
|
origin: origin
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function _error(msg:Dynamic, ?origin:String) {
|
||||||
|
log({
|
||||||
|
level: Error,
|
||||||
|
message: Std.string(msg),
|
||||||
|
time: 0,
|
||||||
|
origin: origin
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function _debug(msg:Dynamic, ?origin:String) {
|
||||||
|
#if debug
|
||||||
|
log({
|
||||||
|
level: Debug,
|
||||||
|
message: Std.string(msg),
|
||||||
|
time: 0,
|
||||||
|
origin: origin
|
||||||
|
});
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function _silly(msg:Dynamic, ?origin:String) {
|
||||||
|
log({
|
||||||
|
level: Silly,
|
||||||
|
message: Std.string(msg),
|
||||||
|
time: 0,
|
||||||
|
origin: origin
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function log(line:LogLine) {
|
||||||
logLines.push(line);
|
logLines.push(line);
|
||||||
|
|
||||||
if (logLines.length > MAX_LINES) {
|
if (logLines.length > MAX_LINES) {
|
||||||
@@ -54,12 +85,49 @@ class Log {
|
|||||||
}
|
}
|
||||||
onLogTrigger.trigger(line);
|
onLogTrigger.trigger(line);
|
||||||
|
|
||||||
#if webconsole
|
#if (webconsole && !macro)
|
||||||
Debug.printWeb('[${Std.string(line.level)}][${line.origin}] ${line.message}');
|
Debug.logToWebconsole(line);
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getLines():ReadOnlyArray<LogLine> {
|
public static function getLines():ReadOnlyArray<LogLine> {
|
||||||
return logLines;
|
return logLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if macro
|
||||||
|
private static function getOrigin():String {
|
||||||
|
var localClass = Context.getLocalClass().get();
|
||||||
|
return localClass.name;
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
public macro static function info(msg:ExprOf<Dynamic>) {
|
||||||
|
return macro {
|
||||||
|
Log._info(${msg}, $v{getOrigin()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public macro static function warn(msg:ExprOf<Dynamic>) {
|
||||||
|
return macro {
|
||||||
|
Log._warn(${msg}, $v{getOrigin()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public macro static function error(msg:ExprOf<Dynamic>) {
|
||||||
|
return macro {
|
||||||
|
Log._error(${msg}, $v{getOrigin()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public macro static function debug(msg:ExprOf<Dynamic>) {
|
||||||
|
return macro {
|
||||||
|
Log._debug(${msg}, $v{getOrigin()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public macro static function silly(msg:ExprOf<Dynamic>) {
|
||||||
|
return macro {
|
||||||
|
Log._silly(${msg}, $v{getOrigin()});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package kernel.log;
|
package kernel.log;
|
||||||
|
|
||||||
typedef LogLine = {
|
typedef LogLine = {
|
||||||
level: LogLevel,
|
level:LogLevel,
|
||||||
message: String,
|
message:String,
|
||||||
time: Int,
|
time:Int,
|
||||||
?origin: String,
|
?origin:String,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
package kernel.net;
|
package kernel.net;
|
||||||
|
|
||||||
import kernel.net.Package.GenericPackage;
|
import kernel.net.Package.GenericPackage;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A object that is able to send and receive messages.
|
A object that is able to send and receive messages.
|
||||||
**/
|
**/
|
||||||
interface INetworkInterface {
|
interface INetworkInterface {
|
||||||
public function listen(chan: Int):Void;
|
public function listen(chan:Int):Void;
|
||||||
public function close(chan: Int):Void;
|
public function close(chan:Int):Void;
|
||||||
public function isListening(chan: Int): Bool;
|
public function isListening(chan:Int):Bool;
|
||||||
public function closeAll(): Void;
|
public function closeAll():Void;
|
||||||
public function send(chan: Int,replyChan: Int,payload: Any):Void;
|
public function send(chan:Int, replyChan:Int, payload:Any):Void;
|
||||||
public function name():String;
|
public function name():String;
|
||||||
public function getBaseRoutingCost():Int;
|
public function getBaseRoutingCost():Int;
|
||||||
public var onMessage (default, null): Signal<{pack:GenericPackage,?dist:Float}>;
|
public var onMessage(default, null):Signal<{pack:GenericPackage, ?dist:Float}>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package kernel.net;
|
|||||||
|
|
||||||
import kernel.net.Package.GenericPackage;
|
import kernel.net.Package.GenericPackage;
|
||||||
import kernel.log.Log;
|
import kernel.log.Log;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,17 +11,17 @@ using tink.CoreApi;
|
|||||||
class Loopback implements INetworkInterface {
|
class Loopback implements INetworkInterface {
|
||||||
public static final instance:Loopback = new Loopback();
|
public static final instance:Loopback = new Loopback();
|
||||||
|
|
||||||
public var onMessage(default, null):Signal<{pack:GenericPackage,dist:Null<Float>}>;
|
public var onMessage(default, null):Signal<{pack:GenericPackage, dist:Null<Float>}>;
|
||||||
|
|
||||||
private final onMessageTrigger: SignalTrigger<{pack:GenericPackage,dist:Null<Float>}> = Signal.trigger();
|
private final onMessageTrigger:SignalTrigger<{pack:GenericPackage, dist:Null<Float>}> = Signal.trigger();
|
||||||
private var openChans: Array<Int> = [];
|
private var openChans:Array<Int> = [];
|
||||||
|
|
||||||
private function new() {
|
private function new() {
|
||||||
this.onMessage = onMessageTrigger.asSignal();
|
this.onMessage = onMessageTrigger.asSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listen(chan:Int) {
|
public function listen(chan:Int) {
|
||||||
if (!this.openChans.contains(chan)){
|
if (!this.openChans.contains(chan)) {
|
||||||
this.openChans.push(chan);
|
this.openChans.push(chan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,9 +39,9 @@ class Loopback implements INetworkInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function send(chan:Int, replyChan:Int, payload:Any) {
|
public function send(chan:Int, replyChan:Int, payload:Any) {
|
||||||
if (this.openChans.contains(chan)){
|
if (this.openChans.contains(chan)) {
|
||||||
this.onMessageTrigger.trigger({pack:payload,dist:null});
|
this.onMessageTrigger.trigger({pack: payload, dist: null});
|
||||||
}else{
|
} else {
|
||||||
Log.silly("Loopback got package on non open channel");
|
Log.silly("Loopback got package on non open channel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,23 +21,53 @@ class Net {
|
|||||||
Depends on: KernelEvents
|
Depends on: KernelEvents
|
||||||
**/
|
**/
|
||||||
public static inline final BRODCAST_PORT:Int = 65533;
|
public static inline final BRODCAST_PORT:Int = 65533;
|
||||||
|
|
||||||
public static inline final MESSAGE_TIMEOUT:Int = 3;
|
public static inline final MESSAGE_TIMEOUT:Int = 3;
|
||||||
public static inline final DEFAULT_TTL:Int = 10;
|
public static inline final DEFAULT_TTL:Int = 10;
|
||||||
|
|
||||||
public static final networkID:NetworkID = OS.getComputerID();
|
public static final networkID:NetworkID = OS.getComputerID();
|
||||||
private static final responseBus:Map<Int, Callback<Outcome<GenericPackage,Error>>> = new Map();
|
private static final responseBus:Map<Int, Callback<Outcome<GenericPackage, Error>>> = new Map();
|
||||||
private static final protoHandlers:Map<String, Callback<GenericPackage>> = new Map();
|
private static final protoHandlers:Map<String, Callback<GenericPackage>> = new Map();
|
||||||
private static var interfaces:Array<INetworkInterface>;
|
private static var interfaces:Array<INetworkInterface>;
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
interfaces = [for (e in Peripheral.getAllModems()) e ]; // TODO: is this the way to do it?
|
interfaces = [for (e in Peripheral.getAllModems()) e]; // TODO: is this the way to do it?
|
||||||
interfaces.push(Loopback.instance);
|
interfaces.push(Loopback.instance);
|
||||||
|
|
||||||
for (interf in interfaces){
|
for (interf in interfaces) {
|
||||||
setupInterf(interf);
|
setupInterf(interf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle when a modem has been removed
|
||||||
|
KernelEvents.onPeripheralDetach.handle((addr) -> {
|
||||||
|
var idx = interfaces.findIndex((i) -> {
|
||||||
|
return i.name() == addr;
|
||||||
|
});
|
||||||
|
if (idx == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.debug('Removed modem on addr: $addr');
|
||||||
|
|
||||||
|
interfaces.splice(idx, 1);
|
||||||
|
Routing.removeInterface(addr);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle when a new modem is connected
|
||||||
|
KernelEvents.onPeripheral.handle((addr) -> {
|
||||||
|
if (!Peripheral.getTypes(addr).contains("modem")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.debug('Added modem on addr: $addr');
|
||||||
|
|
||||||
|
var modem = Peripheral.getModem(addr);
|
||||||
|
interfaces.push(modem);
|
||||||
|
setupInterf(modem);
|
||||||
|
Routing.addInterface(modem);
|
||||||
|
});
|
||||||
|
|
||||||
setupPingHandle();
|
setupPingHandle();
|
||||||
|
|
||||||
Routing.setup();
|
Routing.setup();
|
||||||
@@ -61,8 +91,11 @@ class Net {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function setupInterf(interf: INetworkInterface) {
|
/**
|
||||||
interf.onMessage.handle(e -> handle(e.pack,interf,e.dist));
|
Enables the interface to receive messages.
|
||||||
|
**/
|
||||||
|
private static function setupInterf(interf:INetworkInterface) {
|
||||||
|
interf.onMessage.handle(e -> handle(e.pack, interf, e.dist));
|
||||||
interf.listen(networkID);
|
interf.listen(networkID);
|
||||||
interf.listen(BRODCAST_PORT);
|
interf.listen(BRODCAST_PORT);
|
||||||
}
|
}
|
||||||
@@ -70,8 +103,8 @@ class Net {
|
|||||||
/**
|
/**
|
||||||
Called when a new package comes in.
|
Called when a new package comes in.
|
||||||
**/
|
**/
|
||||||
private static function handle(pack:GenericPackage,interf: INetworkInterface, ?dist: Float) {
|
private static function handle(pack:GenericPackage, interf:INetworkInterface, ?dist:Float) {
|
||||||
if (pack.toID == networkID || pack.toID == Net.BRODCAST_PORT){
|
if (pack.toID == networkID || pack.toID == Net.BRODCAST_PORT) {
|
||||||
switch pack.type {
|
switch pack.type {
|
||||||
case Data(_) | DataNoResponse(_):
|
case Data(_) | DataNoResponse(_):
|
||||||
// Let a local proccess handle it
|
// Let a local proccess handle it
|
||||||
@@ -83,16 +116,16 @@ class Net {
|
|||||||
}
|
}
|
||||||
case RouteDiscover(_) | RouteDiscoverResponse(_) | RouteDiscoverUpdate(_):
|
case RouteDiscover(_) | RouteDiscoverResponse(_) | RouteDiscoverUpdate(_):
|
||||||
// Delegate to Routing
|
// Delegate to Routing
|
||||||
Routing.handleRoutePackage(cast pack,interf);
|
Routing.handleRoutePackage(cast pack, interf);
|
||||||
case GPSRequest | GPSResponse(_):
|
case GPSRequest | GPSResponse(_):
|
||||||
if (dist == null) {
|
if (dist == null) {
|
||||||
Log.silly("Got a GPS package but no distance was provided");
|
Log.silly("Got a GPS package but no distance was provided");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Delegate to GPS
|
// Delegate to GPS
|
||||||
GPS.handlePackage(cast pack,dist,interf);
|
GPS.handlePackage(cast pack, dist, interf);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
// New message received but its not ment for us. Forward if possible.
|
// New message received but its not ment for us. Forward if possible.
|
||||||
forwardPackage(pack);
|
forwardPackage(pack);
|
||||||
}
|
}
|
||||||
@@ -118,13 +151,12 @@ class Net {
|
|||||||
sendRaw(pack);
|
sendRaw(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function forwardPackage(pack: GenericPackage) {
|
private static function forwardPackage(pack:GenericPackage) {
|
||||||
if (pack.ttl == 0){
|
if (pack.ttl == 0) {
|
||||||
|
|
||||||
if (pack.type.match(Data(_))) {
|
if (pack.type.match(Data(_))) {
|
||||||
// If the package is a data package and the ttl hits 0
|
// If the package is a data package and the ttl hits 0
|
||||||
// we send a "died" message to the sender
|
// we send a "died" message to the sender
|
||||||
sendAndForget(pack.fromID, "icmp", {type:"died", msgID: pack.msgID});
|
sendAndForget(pack.fromID, "icmp", {type: "died", msgID: pack.msgID});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop package
|
// Drop package
|
||||||
@@ -133,14 +165,15 @@ class Net {
|
|||||||
|
|
||||||
pack.ttl--;
|
pack.ttl--;
|
||||||
|
|
||||||
if (!sendRaw(pack)){
|
if (!sendRaw(pack)) {
|
||||||
// Cant forward
|
// Cant forward
|
||||||
|
Log.silly('Received a message that could not be forwarded to ${pack.toID}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function respondTo(pack:GenericPackage, data:Dynamic) {
|
public static function respondTo(pack:GenericPackage, data:Dynamic) {
|
||||||
if (pack.type.match(DataNoResponse(_))) {
|
if (!pack.type.match(Data(_))) {
|
||||||
Log.warn("Responed to a no response package. Ignoring");
|
Log.warn("Responding to a package that does require responding. Ignoring.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,13 +207,13 @@ class Net {
|
|||||||
Just send the package to the right modem.
|
Just send the package to the right modem.
|
||||||
Returns true if message was send
|
Returns true if message was send
|
||||||
**/
|
**/
|
||||||
private static function sendRaw(pack:GenericPackage): Bool {
|
private static function sendRaw(pack:GenericPackage):Bool {
|
||||||
var route = Routing.getRouteToID(pack.toID);
|
var route = Routing.getRouteToID(pack.toID);
|
||||||
if (route == null){
|
if (route == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
route.interf.send(route.rep,networkID,pack);
|
route.interf.send(route.rep, networkID, pack);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,8 +233,7 @@ class Net {
|
|||||||
|
|
||||||
var timeout:Timer = null;
|
var timeout:Timer = null;
|
||||||
|
|
||||||
responseBus[pack.msgID] = ((reponse:Outcome<GenericPackage,Error>) -> {
|
responseBus[pack.msgID] = ((reponse:Outcome<GenericPackage, Error>) -> {
|
||||||
|
|
||||||
switch reponse {
|
switch reponse {
|
||||||
case Success(pack):
|
case Success(pack):
|
||||||
resolve(pack);
|
resolve(pack);
|
||||||
@@ -213,14 +245,16 @@ class Net {
|
|||||||
if (timeout != null) {
|
if (timeout != null) {
|
||||||
timeout.cancle();
|
timeout.cancle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
responseBus.remove(pack.msgID);
|
||||||
});
|
});
|
||||||
|
|
||||||
timeout = new Timer(MESSAGE_TIMEOUT, () -> {
|
timeout = new Timer(MESSAGE_TIMEOUT, () -> {
|
||||||
responseBus.remove(pack.msgID);
|
responseBus.remove(pack.msgID);
|
||||||
reject(new Error(InternalError,"Message timeout"));
|
reject(new Error(InternalError, "Message timeout"));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!sendRaw(pack)){
|
if (!sendRaw(pack)) {
|
||||||
reject(new Error("ID unreachable"));
|
reject(new Error("ID unreachable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,9 +280,9 @@ class Net {
|
|||||||
/**
|
/**
|
||||||
Sends a ping package to the given id. Returns true if there was a response.
|
Sends a ping package to the given id. Returns true if there was a response.
|
||||||
**/
|
**/
|
||||||
public static function ping(toID: NetworkID): Promise<Noise> {
|
public static function ping(toID:NetworkID):Promise<Noise> {
|
||||||
return new Promise<Noise>((resolve,reject)->{
|
return new Promise<Noise>((resolve, reject) -> {
|
||||||
sendAndAwait(toID,"icmp",{type:"ping"}).handle(pack -> {
|
sendAndAwait(toID, "icmp", {type: "ping"}).handle(pack -> {
|
||||||
switch pack {
|
switch pack {
|
||||||
case Success(_):
|
case Success(_):
|
||||||
resolve(Noise);
|
resolve(Noise);
|
||||||
@@ -260,7 +294,7 @@ class Net {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getActiveProtocols(): ReadOnlyArray<String> {
|
public static function getActiveProtocols():ReadOnlyArray<String> {
|
||||||
var arr = new Array<String>();
|
var arr = new Array<String>();
|
||||||
|
|
||||||
for (proto in protoHandlers.keys()) {
|
for (proto in protoHandlers.keys()) {
|
||||||
@@ -272,7 +306,7 @@ class Net {
|
|||||||
|
|
||||||
@:allow(kernel.gps.GPS)
|
@:allow(kernel.gps.GPS)
|
||||||
private static function brodcastGPSRequest() {
|
private static function brodcastGPSRequest() {
|
||||||
var pack: Package<Noise> = {
|
var pack:Package<Noise> = {
|
||||||
fromID: networkID,
|
fromID: networkID,
|
||||||
toID: Net.BRODCAST_PORT,
|
toID: Net.BRODCAST_PORT,
|
||||||
ttl: 0, // Prevent forwarding
|
ttl: 0, // Prevent forwarding
|
||||||
@@ -282,7 +316,8 @@ class Net {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (modem in Peripheral.getAllModems()) {
|
for (modem in Peripheral.getAllModems()) {
|
||||||
if (!modem.isWireless()) continue;
|
if (!modem.isWireless())
|
||||||
|
continue;
|
||||||
modem.send(Net.BRODCAST_PORT, networkID, pack);
|
modem.send(Net.BRODCAST_PORT, networkID, pack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
package kernel.net;
|
package kernel.net;
|
||||||
|
|
||||||
import lib.Pos3;
|
|
||||||
|
|
||||||
typedef NetworkID = Int;
|
typedef NetworkID = Int;
|
||||||
typedef GenericPackage = Package<Dynamic> ;
|
typedef GenericPackage = Package<Dynamic>;
|
||||||
|
|
||||||
enum PackageTypes {
|
enum PackageTypes {
|
||||||
Data(proto:String);
|
Data(proto:String);
|
||||||
DataNoResponse(proto:String);
|
DataNoResponse(proto:String);
|
||||||
Response;
|
Response;
|
||||||
RouteDiscover(reachableIDs: Array<{id:NetworkID,cost:Int}>);
|
RouteDiscover(reachableIDs:Array<{id:NetworkID, cost:Int}>);
|
||||||
RouteDiscoverResponse(reachableIDs: Array<{id:NetworkID,cost:Int}>);
|
RouteDiscoverResponse(reachableIDs:Array<{id:NetworkID, cost:Int}>);
|
||||||
RouteDiscoverUpdate(reachableIDs: Array<{id:NetworkID,cost:Int}>);
|
RouteDiscoverUpdate(reachableIDs:Array<{id:NetworkID, cost:Int}>);
|
||||||
GPSResponse(pos:Pos3);
|
GPSResponse(x:Float, y:Float, z:Float);
|
||||||
GPSRequest();
|
GPSRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +23,7 @@ enum PackageTypes {
|
|||||||
public final msgID:Int;
|
public final msgID:Int;
|
||||||
public final type:PackageTypes;
|
public final type:PackageTypes;
|
||||||
public final data:T;
|
public final data:T;
|
||||||
public var ttl: Int;
|
public var ttl:Int;
|
||||||
|
|
||||||
public function new(fromID:NetworkID, toID:NetworkID, msgID:Int, type:PackageTypes, data:T, ttl:Int) {
|
public function new(fromID:NetworkID, toID:NetworkID, msgID:Int, type:PackageTypes, data:T, ttl:Int) {
|
||||||
this.fromID = fromID;
|
this.fromID = fromID;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ class Routing {
|
|||||||
/**
|
/**
|
||||||
Depends on: Peripheral
|
Depends on: Peripheral
|
||||||
**/
|
**/
|
||||||
|
|
||||||
public static inline final UPDATE_WAIT_TIME:Float = 1;
|
public static inline final UPDATE_WAIT_TIME:Float = 1;
|
||||||
|
|
||||||
public static var onNewNeigbor(default, null):Signal<Int>;
|
public static var onNewNeigbor(default, null):Signal<Int>;
|
||||||
@@ -75,42 +74,37 @@ class Routing {
|
|||||||
private static function handleRoutePackage(pack:Package<Noise>, interf:INetworkInterface):Void {
|
private static function handleRoutePackage(pack:Package<Noise>, interf:INetworkInterface):Void {
|
||||||
addPossibleRoute(pack.fromID, interf, 0, pack.fromID);
|
addPossibleRoute(pack.fromID, interf, 0, pack.fromID);
|
||||||
|
|
||||||
var shouldRespond:Bool = switch pack.type {
|
switch pack.type {
|
||||||
case RouteDiscoverResponse(routes):
|
case RouteDiscoverResponse(routes):
|
||||||
|
// A request for routes has been answerd
|
||||||
for (route in routes) {
|
for (route in routes) {
|
||||||
addPossibleRoute(route.id, interf, route.cost, pack.fromID);
|
addPossibleRoute(route.id, interf, route.cost, pack.fromID);
|
||||||
}
|
}
|
||||||
false;
|
|
||||||
case RouteDiscover(routes):
|
case RouteDiscover(routes):
|
||||||
|
// Received a request for available routes
|
||||||
for (route in routes) {
|
for (route in routes) {
|
||||||
addPossibleRoute(route.id, interf, route.cost, pack.fromID);
|
addPossibleRoute(route.id, interf, route.cost, pack.fromID);
|
||||||
}
|
}
|
||||||
true;
|
|
||||||
|
// Respond to peer
|
||||||
|
var response:Package<Noise> = {
|
||||||
|
toID: pack.fromID,
|
||||||
|
fromID: Net.networkID,
|
||||||
|
msgID: null,
|
||||||
|
type: RouteDiscoverResponse(genRouteList()),
|
||||||
|
data: null,
|
||||||
|
ttl: 0, // Prevent forwarding
|
||||||
|
}
|
||||||
|
|
||||||
|
interf.send(response.toID, Net.networkID, response);
|
||||||
case RouteDiscoverUpdate(routes):
|
case RouteDiscoverUpdate(routes):
|
||||||
|
// Received an update of routes
|
||||||
for (route in routes) {
|
for (route in routes) {
|
||||||
addPossibleRoute(route.id, interf, route.cost, pack.fromID);
|
addPossibleRoute(route.id, interf, route.cost, pack.fromID);
|
||||||
}
|
}
|
||||||
false;
|
|
||||||
default:
|
default:
|
||||||
Log.error("Expected package to be a Route discover package");
|
Log.silly("Expected package to be a Route discover package");
|
||||||
false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!shouldRespond) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Respond to peer
|
|
||||||
var response:Package<Noise> = {
|
|
||||||
toID: pack.fromID,
|
|
||||||
fromID: Net.networkID,
|
|
||||||
msgID: null,
|
|
||||||
type: RouteDiscoverResponse(genRouteList()),
|
|
||||||
data: null,
|
|
||||||
ttl: 0, // Prevent forwarding
|
|
||||||
}
|
|
||||||
|
|
||||||
interf.send(response.toID, Net.networkID, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,6 +121,9 @@ class Routing {
|
|||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a new packate to brodcast our routes.
|
||||||
|
**/
|
||||||
private static function newRoutDiscoverPackage():Package<Noise> {
|
private static function newRoutDiscoverPackage():Package<Noise> {
|
||||||
var pack:Package<Noise> = {
|
var pack:Package<Noise> = {
|
||||||
type: RouteDiscover(genRouteList()),
|
type: RouteDiscover(genRouteList()),
|
||||||
@@ -180,4 +177,28 @@ class Routing {
|
|||||||
public static function getRouteTable():Map<NetworkID, Route> {
|
public static function getRouteTable():Map<NetworkID, Route> {
|
||||||
return routingTable;
|
return routingTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Call when an interface is no longer available.
|
||||||
|
Will rebrodcast routing requests.
|
||||||
|
**/
|
||||||
|
@:allow(kernel.net.Net)
|
||||||
|
private static function removeInterface(addr:String) {
|
||||||
|
// Remove the interface from the routing table
|
||||||
|
for (to => modem in routingTable) {
|
||||||
|
if (modem.interf.name() == addr) {
|
||||||
|
routingTable.remove(to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since some routes to some host could be lost
|
||||||
|
// we rebrodcast on all interfaces again
|
||||||
|
brodcastRoutingTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@:allow(kernel.net.Net)
|
||||||
|
private static function addInterface(iface:INetworkInterface) {
|
||||||
|
var pack = newRoutDiscoverPackage();
|
||||||
|
iface.send(Net.BRODCAST_PORT, Net.networkID, pack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,8 +168,7 @@ class BigReactor implements IPeripheral {
|
|||||||
// getFuelStats
|
// getFuelStats
|
||||||
// getEnergyStats
|
// getEnergyStats
|
||||||
// getCoolantFluidStats
|
// getCoolantFluidStats
|
||||||
// getHotFluidStats
|
// getHotFluidStats
|
||||||
|
|
||||||
// TODO: need research
|
// TODO: need research
|
||||||
// isMethodAvailable(method: String): Bool
|
// isMethodAvailable(method: String): Bool
|
||||||
// mbGetMaximumCoordinate(): Pos3
|
// mbGetMaximumCoordinate(): Pos3
|
||||||
|
|||||||
@@ -4,47 +4,47 @@ import cc.Peripheral;
|
|||||||
import kernel.net.Package.NetworkID;
|
import kernel.net.Package.NetworkID;
|
||||||
|
|
||||||
class Computer implements IPeripheral {
|
class Computer implements IPeripheral {
|
||||||
public static inline final TYPE_NAME:String = "computer";
|
public static inline final TYPE_NAME:String = "computer";
|
||||||
|
|
||||||
private final addr:String;
|
private final addr:String;
|
||||||
|
|
||||||
@:allow(kernel.peripherals)
|
@:allow(kernel.peripherals)
|
||||||
private function new(addr: String) {
|
private function new(addr:String) {
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAddr():String {
|
public function getAddr():String {
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getType():String {
|
public function getType():String {
|
||||||
return Computer.TYPE_NAME;
|
return Computer.TYPE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isOn():Bool {
|
public function isOn():Bool {
|
||||||
return Peripheral.call(addr, "isOn");
|
return Peripheral.call(addr, "isOn");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLabel():Null<String> {
|
public function getLabel():Null<String> {
|
||||||
return Peripheral.call(addr, "getLabel");
|
return Peripheral.call(addr, "getLabel");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return -1 if no ID set yet
|
Return -1 if no ID set yet
|
||||||
**/
|
**/
|
||||||
public function getID():NetworkID{
|
public function getID():NetworkID {
|
||||||
return Peripheral.call(addr, "getID");
|
return Peripheral.call(addr, "getID");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reboot() {
|
public function reboot() {
|
||||||
Peripheral.call(addr, "reboot");
|
Peripheral.call(addr, "reboot");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shutdown() {
|
public function shutdown() {
|
||||||
Peripheral.call(addr, "shutdown");
|
Peripheral.call(addr, "shutdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function turnOn() {
|
public function turnOn() {
|
||||||
Peripheral.call(addr, "turnOn");
|
Peripheral.call(addr, "turnOn");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
import cc.Peripheral;
|
import cc.Peripheral;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Drive implements IPeripheral {
|
class Drive implements IPeripheral {
|
||||||
@@ -15,21 +16,21 @@ class Drive implements IPeripheral {
|
|||||||
private final onDiskEjectTrigger:SignalTrigger<Noise> = Signal.trigger();
|
private final onDiskEjectTrigger:SignalTrigger<Noise> = Signal.trigger();
|
||||||
|
|
||||||
@:allow(kernel.peripherals)
|
@:allow(kernel.peripherals)
|
||||||
private function new(addr: String) {
|
private function new(addr:String) {
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
this.native = Peripheral.wrap(addr);
|
this.native = Peripheral.wrap(addr);
|
||||||
|
|
||||||
this.onDiskInsert = this.onDiskInsertTrigger.asSignal();
|
this.onDiskInsert = this.onDiskInsertTrigger.asSignal();
|
||||||
this.onDiskEject = this.onDiskEjectTrigger.asSignal();
|
this.onDiskEject = this.onDiskEjectTrigger.asSignal();
|
||||||
|
|
||||||
KernelEvents.onDisk.handle((addr) ->{
|
KernelEvents.onDisk.handle((addr) -> {
|
||||||
if (addr == this.addr){
|
if (addr == this.addr) {
|
||||||
this.onDiskInsertTrigger.trigger(null);
|
this.onDiskInsertTrigger.trigger(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
KernelEvents.onDiskEject.handle((addr)->{
|
KernelEvents.onDiskEject.handle((addr) -> {
|
||||||
if (addr == this.addr){
|
if (addr == this.addr) {
|
||||||
this.onDiskEjectTrigger.trigger(null);
|
this.onDiskEjectTrigger.trigger(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -43,14 +44,14 @@ class Drive implements IPeripheral {
|
|||||||
return TYPE_NAME;
|
return TYPE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function isDiskPresent(): Bool {
|
public inline function isDiskPresent():Bool {
|
||||||
return this.native.isDiskPresent();
|
return this.native.isDiskPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The label of the disk, or `null` if either no disk is inserted or the disk doesn't have a label.
|
The label of the disk, or `null` if either no disk is inserted or the disk doesn't have a label.
|
||||||
**/
|
**/
|
||||||
public inline function getDiskLabel(): Null<String> {
|
public inline function getDiskLabel():Null<String> {
|
||||||
return this.native.getDiskLabel();
|
return this.native.getDiskLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,11 +59,11 @@ class Drive implements IPeripheral {
|
|||||||
this.native.setDiskLabel();
|
this.native.setDiskLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function setDiskLabel(label: String): Null<Error> {
|
public inline function setDiskLabel(label:String):Null<Error> {
|
||||||
try {
|
try {
|
||||||
this.native.setDiskLabel(label);
|
this.native.setDiskLabel(label);
|
||||||
return null;
|
return null;
|
||||||
} catch (e: Dynamic) {
|
} catch (e:Dynamic) {
|
||||||
return new Error("Invalid label");
|
return new Error("Invalid label");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +80,7 @@ class Drive implements IPeripheral {
|
|||||||
return this.getMountPath();
|
return this.getMountPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getAudioTitle(): Null<String> {
|
public inline function getAudioTitle():Null<String> {
|
||||||
return this.native.getAudioTitle();
|
return this.native.getAudioTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ class Drive implements IPeripheral {
|
|||||||
this.native.ejectDisk();
|
this.native.ejectDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getDiskID(): Int {
|
public inline function getDiskID():Int {
|
||||||
return this.native.getDiskID();
|
return this.native.getDiskID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
491
src/kernel/peripherals/DroneInterface.hx
Normal file
491
src/kernel/peripherals/DroneInterface.hx
Normal file
@@ -0,0 +1,491 @@
|
|||||||
|
package kernel.peripherals;
|
||||||
|
|
||||||
|
import lib.Item;
|
||||||
|
import haxe.exceptions.NotImplementedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
See https://github.com/MineMaarten/PneumaticCraft/blob/master/resources/assets/pneumaticcraft/wiki/en_US/block/droneInterface.txt
|
||||||
|
**/
|
||||||
|
class DroneInterface implements IPeripheral {
|
||||||
|
public static inline final TYPE_NAME:String = "drone_interface";
|
||||||
|
|
||||||
|
private final addr:String;
|
||||||
|
|
||||||
|
@:allow(kernel.peripherals)
|
||||||
|
private function new(addr:String) {
|
||||||
|
this.addr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddr():String {
|
||||||
|
return this.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType():String {
|
||||||
|
return DroneInterface.TYPE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns true if a Drone has connected with this Drone Interface
|
||||||
|
(when the Drone's program has arrived at the ComputerCraft piece and made a connection).
|
||||||
|
**/
|
||||||
|
public function isConnectedToDrone():Bool {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the pressure of the connected Drone.
|
||||||
|
**/
|
||||||
|
public function getDronePressure() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a table of 3 double values containing the x,y and z position respectively of the Drone.
|
||||||
|
**/
|
||||||
|
public function getDronePosition() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Stops the ComputerCraft piece in the Drone, and allows the Drone's program to proceed to the next puzzle piece.
|
||||||
|
**/
|
||||||
|
public function exitPiece() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a table of all the current selectable actions (like 'dig' or 'place').
|
||||||
|
**/
|
||||||
|
public function getAllActions() {
|
||||||
|
/*
|
||||||
|
pneumaticcraft:entity_attack
|
||||||
|
pneumaticcraft:dig
|
||||||
|
pneumaticcraft:harvest
|
||||||
|
pneumaticcraft:place
|
||||||
|
pneumaticcraft:block_right_click
|
||||||
|
pneumaticcraft:entity_right_click
|
||||||
|
pneumaticcraft:pickup_item
|
||||||
|
pneumaticcraft:drop_item
|
||||||
|
pneumaticcraft:void_item
|
||||||
|
pneumaticcraft:void_liquid
|
||||||
|
pneumaticcraft:inventory_export
|
||||||
|
pneumaticcraft:inventory_import
|
||||||
|
pneumaticcraft:liquid_export
|
||||||
|
pneumaticcraft:liquid_import
|
||||||
|
pneumaticcraft:entity_export
|
||||||
|
pneumaticcraft:entity_import
|
||||||
|
pneumaticcraft:rf_import
|
||||||
|
pneumaticcraft:rf_export
|
||||||
|
pneumaticcraft:goto
|
||||||
|
pneumaticcraft:teleport
|
||||||
|
pneumaticcraft:emit_redstone
|
||||||
|
pneumaticcraft:rename
|
||||||
|
pneumaticcraft:suicide
|
||||||
|
pneumaticcraft:crafting
|
||||||
|
pneumaticcraft:standby
|
||||||
|
pneumaticcraft:logistics
|
||||||
|
pneumaticcraft:edit_sign
|
||||||
|
pneumaticcraft:condition_redstone
|
||||||
|
pneumaticcraft:condition_light
|
||||||
|
pneumaticcraft:condition_item_inventory
|
||||||
|
pneumaticcraft:condition_block
|
||||||
|
pneumaticcraft:condition_liquid_inventory
|
||||||
|
pneumaticcraft:condition_pressure
|
||||||
|
pneumaticcraft:drone_condition_item
|
||||||
|
pneumaticcraft:drone_condition_liquid
|
||||||
|
pneumaticcraft:drone_condition_entity
|
||||||
|
pneumaticcraft:drone_condition_pressure
|
||||||
|
pneumaticcraft:drone_condition_upgrades
|
||||||
|
pneumaticcraft:condition_rf
|
||||||
|
pneumaticcraft:drone_condition_rf
|
||||||
|
pneumaticcraft:computer_control
|
||||||
|
*/
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the place/dig order of the Drone.
|
||||||
|
**/
|
||||||
|
public function setBlockOrder(order:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a table of all the possible area types (filled, frame, sphere, ..).
|
||||||
|
**/
|
||||||
|
public function getAreaTypes() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Adds an area to the current stored area of the Drone. When using the latter method, x1, y1, and z1, represent
|
||||||
|
the first point (which would be the first GPS Tool normally), and x2, y2, and z2 represent the second point.
|
||||||
|
**/
|
||||||
|
public function addArea(x:Int, y:Int, z:Int) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Removes an area from the current stored area (like blacklisting).
|
||||||
|
**/
|
||||||
|
public function removeArea(x:Int, y:Int, z:Int) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clears the current stored area.
|
||||||
|
**/
|
||||||
|
public function clearArea() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Will show the current stored area using the area renderer you are used to.
|
||||||
|
**/
|
||||||
|
public function showArea() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Will stop showing the area stored in the Drone.
|
||||||
|
**/
|
||||||
|
public function hideArea() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Acts as you've put a Item Filter piece on the right of a piece (making it whitelisting).
|
||||||
|
The item/block name is in Minecraft format, i.e. "minecraft:stone", or "pneumaticcraft:pressureTube".
|
||||||
|
The 'useXXX' are all booleans that determine what filters will be used (same functionality as the check boxes in the Item Filter puzzle piece).
|
||||||
|
**/
|
||||||
|
public function addWhitelistItemFilter(item:Item, metadata:String, useMetadata:Bool, useNBT:Bool, useOreDictionary:Bool, useModSimilarity:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Like the addWhitelistItemFilter(...), but to blacklist items.
|
||||||
|
**/
|
||||||
|
public function addBlacklistItemFilter(item:Item, metadata:String, useMetadata:Bool, useNBT:Bool, useOreDictionary:Bool, useModSimilarity:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clears all the whitelisted item filters stored.
|
||||||
|
**/
|
||||||
|
public function clearWhitelistItemFilter() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clears all the blacklisted item filters stored.
|
||||||
|
**/
|
||||||
|
public function clearBlacklistItemFilter() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Adds a text to the whitelisted texts. Used to specify a filter for the Entity Attack action for example.
|
||||||
|
**/
|
||||||
|
public function addWhitelistText(text:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Adds a text to the blacklisted texts. Used to specify a filter for the Entity Attack action for example.
|
||||||
|
**/
|
||||||
|
public function addBlacklistText(text:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clears the stored whitelisted texts.
|
||||||
|
**/
|
||||||
|
public function clearWhitelistText() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clears the stored blacklisted texts.
|
||||||
|
**/
|
||||||
|
public function clearBlacklistText() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Acts as you've put a Liquid Filter piece on the right of a piece (making it whitelisting).
|
||||||
|
You can either give it the 'registry name', or the localized name.
|
||||||
|
**/
|
||||||
|
public function addWhitelistLiquidFilter(liquidName:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Like the addWhitelistLiquidFilter(...), but to blacklist liquids.
|
||||||
|
**/
|
||||||
|
public function addBlacklistLiquidFilter(liquidName:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clears all the whitelisted liquid filters stored.
|
||||||
|
**/
|
||||||
|
public function clearWhitelistLiquidFilter() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clears all the blacklisted liquid filters stored.
|
||||||
|
**/
|
||||||
|
public function clearBlacklistLiquidFilter() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the strength the redstone will be emitting when the "emitRedstone" action would be set.
|
||||||
|
**/
|
||||||
|
public function setEmittingRedstone(strength:Int) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the name the Drone will be named to when the "rename" action would be set.
|
||||||
|
**/
|
||||||
|
public function setRenameString(name:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
When the "dropItem" action would be set, this determines whether or not
|
||||||
|
the item will be dropped with a random velocity, or straight down.
|
||||||
|
**/
|
||||||
|
public function setDropStraight(to:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
This says whether or not the Drone has a maximum of imported/exported/dropped pieces.
|
||||||
|
If true, also use setCount().
|
||||||
|
**/
|
||||||
|
public function setUseCount(count:Int) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
This configures the maximum amount of imported/exported/dropped items, and also is the amount that's checked when doing a condition check.
|
||||||
|
**/
|
||||||
|
public function setCount(count:Int) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Used in conditions only. When true, all checked blocks need to satisfy the condition requirements (>=10 etcetera).
|
||||||
|
**/
|
||||||
|
public function setIsAndFunction(to:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Used in conditions only.
|
||||||
|
Says whether or not the condition is checking for an equal amount (=) or equal and higher than amount (>=).
|
||||||
|
The amount can be set using setCount().
|
||||||
|
**/
|
||||||
|
public function setOperator(op:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns true/false. Used in conditions only.
|
||||||
|
Will return true/false depending on whether or not the condition is satisfied.
|
||||||
|
Drone Conditions can be checked right after setting 'setAction()'.
|
||||||
|
Note that you need to wait until 'isActionDone' if you're dealing with a non Drone Condition.
|
||||||
|
**/
|
||||||
|
public function evaluateCondition():Bool {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the specific side to be accessible or not.
|
||||||
|
Used in the Inventory Im- and Export actions to set which side of the inventory the Drone can access.
|
||||||
|
It is also used for the Place action to determine how to place the block.
|
||||||
|
**/
|
||||||
|
public function setSide(side:String, accessible:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Same as setSide(side: String, accessible: Bool), now in one function to set all sides at once (6x boolean).
|
||||||
|
**/
|
||||||
|
public function setSides(down:Bool, up:Bool, north:Bool, south:Bool, east:Bool, west:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
This says whether or not the Drone has a maximum actions performed on a block at a time before the command is considered 'done'.
|
||||||
|
Applies to the Place, Dig and Right-Click block program. If true, also use setMaxActions().
|
||||||
|
**/
|
||||||
|
public function setUseMaxActions(to:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
This configures the maximum amount of actions performed on blocks before the command is considered 'done'.
|
||||||
|
This applies to the Place, Dig an Right-Click block program. Be sure to also call setUseMaxActions(true) to enable usage of this.
|
||||||
|
**/
|
||||||
|
public function setMaxActions(max:Int) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets up the crafting grid so when the Crafting instruction is called, this recipe will be used.
|
||||||
|
You need to specify all 9 items making up the recipe.
|
||||||
|
For empty spaces supply nil. The naming format is the same as for supplying item filters.
|
||||||
|
|
||||||
|
TODO: args: <item/block name>, <item/block name>, ...(9x)
|
||||||
|
**/
|
||||||
|
public function setCraftingGrid() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Only used in the right click command, this will set whether or not the fake player is sneaking while right clicking.
|
||||||
|
**/
|
||||||
|
public function setSneaking(sneaking:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Only used in the Liquid Export command, when set to true the Drone will be allowed to place down fluid blocks.
|
||||||
|
**/
|
||||||
|
public function setPlaceFluidBlocks(to:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the[link{pneumaticcraft:progwidget/coordinateOperator}] variable[link{}] of this Drone.
|
||||||
|
When passing 'true', the coordinate will be set to (1,0,0).
|
||||||
|
Alternatively, false will be setting it to (0,0,0).
|
||||||
|
It is possible to set global variables (#) as well.
|
||||||
|
|
||||||
|
TODO: args
|
||||||
|
setVariable(<variable name>, <true/false>)
|
||||||
|
setVariable(<variable name>, <x>)
|
||||||
|
setVariable(<variable name>, <x>, <y>, <z>)
|
||||||
|
**/
|
||||||
|
public function setVariable(name:String, to:Dynamic) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the value of the variable from this Drone (x, y and z).
|
||||||
|
It is possible to get global (#) and special variables ($) as well.
|
||||||
|
**/
|
||||||
|
public function getVariable(name:String):Dynamic {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the text that's going to be set to Signs using the Edit Sign command.
|
||||||
|
|
||||||
|
TODO: args <line1>, <line2>, ..., <lineN>
|
||||||
|
**/
|
||||||
|
public function setSignText(lines:Array<String>) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
String that represents the action. This should be one of the actions returned by getAllActions().
|
||||||
|
**/
|
||||||
|
public function setAction(action:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a string that represents the last action set by 'setAction'.
|
||||||
|
Will return nil when no action is set.
|
||||||
|
Can be used to make sure to only call 'isActionDone()' when this method does not return nil.
|
||||||
|
**/
|
||||||
|
public function getAction():String {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Stops the current running action.
|
||||||
|
**/
|
||||||
|
public function abortAction() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns true if the current action is done (goto has arrived at the target location,
|
||||||
|
inventory import can't import anymore, dig has dug every possible block, ..).
|
||||||
|
**/
|
||||||
|
public function isActionDone():Bool {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
When the Drone was targeting an Entity (in the Entity Attack program), this will stop attacking that target.
|
||||||
|
**/
|
||||||
|
public function forgetTarget() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Will get the amount of inserted upgrades of the given type.
|
||||||
|
This type is the index of the upgrade (in creative, or NEI), starting with 0.
|
||||||
|
Or the metadata value when you use NEI.
|
||||||
|
A Speed upgrade for example has an index of 5.
|
||||||
|
**/
|
||||||
|
public function getUpgrades(upgrade:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Unkown. Showed up in the inspect.
|
||||||
|
**/
|
||||||
|
public function setCanSteal(canSteal:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Unkown. Showed up in the inspect.
|
||||||
|
**/
|
||||||
|
public function setRequiresTool(requiresTool:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Unkown. Showed up in the inspect.
|
||||||
|
**/
|
||||||
|
public function setCheckLineOfSight(check:Bool) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Unkown. Showed up in the inspect.
|
||||||
|
**/
|
||||||
|
public function setRightClickType(to:String) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Unkown. Showed up in the inspect.
|
||||||
|
**/
|
||||||
|
public function getDronePositionVec() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Unkown. Showed up in the inspect.
|
||||||
|
**/
|
||||||
|
public function getOwnerID() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Unkown. Showed up in the inspect.
|
||||||
|
**/
|
||||||
|
public function getOwnerName():String {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,23 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
import lib.exporter.ExportConfig;
|
class EnergyStorage implements IPeripheral {
|
||||||
import lib.exporter.IExportable;
|
public static inline final TYPE_NAME:String = "energyCell";
|
||||||
|
|
||||||
class EnergyStorage implements IPeripheral implements IExportable{
|
private final addr:String;
|
||||||
public static inline final TYPE_NAME:String = "energyCell";
|
private final native:cc.periphs.EnergyStorage;
|
||||||
|
|
||||||
private final addr:String;
|
public function new(addr:String) {
|
||||||
private final native: cc.periphs.EnergyStorage;
|
this.addr = addr;
|
||||||
|
this.native = cc.Peripheral.wrap(addr);
|
||||||
|
}
|
||||||
|
|
||||||
public function new(addr: String) {
|
public function getEnergy():Int {
|
||||||
this.addr = addr;
|
return this.native.getEnergy();
|
||||||
this.native = cc.Peripheral.wrap(addr);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function getEnergy(): Int {
|
public function getEnergyCapacity():Int {
|
||||||
return this.native.getEnergy();
|
return this.native.getEnergyCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEnergyCapacity(): Int {
|
|
||||||
return this.native.getEnergyCapacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAddr():String {
|
public function getAddr():String {
|
||||||
return this.addr;
|
return this.addr;
|
||||||
@@ -29,13 +26,4 @@ class EnergyStorage implements IPeripheral implements IExportable{
|
|||||||
public function getType():String {
|
public function getType():String {
|
||||||
return TYPE_NAME;
|
return TYPE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function export():ExportConfig {
|
|
||||||
return {
|
|
||||||
getDelegates: [
|
|
||||||
"energy" => _ -> Number(this.getEnergy()),
|
|
||||||
"capacity" => _ -> Number(this.getEnergyCapacity()),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
76
src/kernel/peripherals/GeoScanner.hx
Normal file
76
src/kernel/peripherals/GeoScanner.hx
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
package kernel.peripherals;
|
||||||
|
|
||||||
|
import lib.BlockPos;
|
||||||
|
import lib.Tags;
|
||||||
|
import cc.Peripheral;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
using lua.Table;
|
||||||
|
|
||||||
|
@:structInit typedef ScanBlock = {
|
||||||
|
name:String,
|
||||||
|
tags:Tags,
|
||||||
|
pos:BlockPos
|
||||||
|
}
|
||||||
|
|
||||||
|
class GeoScanner implements IPeripheral {
|
||||||
|
public static inline final TYPE_NAME:String = "geoScanner";
|
||||||
|
|
||||||
|
private final addr:String;
|
||||||
|
|
||||||
|
public function new(addr:String) {
|
||||||
|
this.addr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddr():String {
|
||||||
|
return this.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType():String {
|
||||||
|
return TYPE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the current time remaining until then next scan() can be ran.
|
||||||
|
**/
|
||||||
|
public function getScanCooldown():Int {
|
||||||
|
return Peripheral.call(this.addr, "getScanCooldown");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the cost in FE for a scan with the given radius.
|
||||||
|
Returns null of scan of this radius is not posible.
|
||||||
|
**/
|
||||||
|
public function cost(radius:Int):Null<Int> {
|
||||||
|
return Peripheral.call(this.addr, "cost", radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a list of data about all blocks in the radius.
|
||||||
|
X,Y,Z are relative to the geoscanner block.
|
||||||
|
Air blocks are not included.
|
||||||
|
List is unsorted.
|
||||||
|
**/
|
||||||
|
public function scan(radius:Int):Outcome<Array<ScanBlock>, String> {
|
||||||
|
// TODO: Handel fail state
|
||||||
|
var result:lua.Table<Int, {
|
||||||
|
x:Int,
|
||||||
|
y:Int,
|
||||||
|
z:Int,
|
||||||
|
name:String,
|
||||||
|
tags:lua.Table<Int, String>
|
||||||
|
}> = Peripheral.call(this.addr, "scan", radius);
|
||||||
|
|
||||||
|
return Success(result.toArray().map((e) -> {
|
||||||
|
name: e.name,
|
||||||
|
tags: Tags.fromIntTable(e.tags),
|
||||||
|
pos: new BlockPos(e.x, e.y, e.z)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function chunkAnalyze():Outcome<Map<String, Int>, String> {
|
||||||
|
var result:lua.Table<String, Int> = Peripheral.call(this.addr, "chunkAnalyze");
|
||||||
|
|
||||||
|
return Success(result.toMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
interface IPeripheral {
|
interface IPeripheral {
|
||||||
public function getAddr(): String;
|
public function getAddr():String;
|
||||||
public function getType(): String;
|
public function getType():String;
|
||||||
}
|
}
|
||||||
|
|||||||
123
src/kernel/peripherals/Inventory.hx
Normal file
123
src/kernel/peripherals/Inventory.hx
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
package kernel.peripherals;
|
||||||
|
|
||||||
|
import kernel.log.Log;
|
||||||
|
import lib.Debug;
|
||||||
|
import cc.Peripheral;
|
||||||
|
import lib.Tags;
|
||||||
|
import lib.Item;
|
||||||
|
import cc.periphs.ItemStorage.ReducedItemInfo;
|
||||||
|
import lua.Table;
|
||||||
|
|
||||||
|
using Lambda;
|
||||||
|
|
||||||
|
class ItemInfo {
|
||||||
|
public final count:Int;
|
||||||
|
public final name:Item;
|
||||||
|
public final nbt:Null<String>;
|
||||||
|
|
||||||
|
@:allow(kernel.peripherals.Inventory)
|
||||||
|
private function new(from:ReducedItemInfo) {
|
||||||
|
this.count = from.count;
|
||||||
|
this.name = from.name;
|
||||||
|
this.nbt = from.nbt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DetailedItemInfo extends ItemInfo {
|
||||||
|
public final displayName:String;
|
||||||
|
public final maxCount:Int;
|
||||||
|
public final tags:Tags;
|
||||||
|
public final durability:Null<Float>;
|
||||||
|
public final damage:Null<Int>;
|
||||||
|
public final maxDamage:Null<Int>;
|
||||||
|
public final enchantments:Array<{displayName:String, level:Int, name:String}>;
|
||||||
|
|
||||||
|
@:allow(kernel.peripherals.Inventory)
|
||||||
|
private function new(from:cc.periphs.ItemStorage.DetailedItemInfo) {
|
||||||
|
super(from);
|
||||||
|
|
||||||
|
this.tags = Tags.fromBoolTable(from.tags);
|
||||||
|
|
||||||
|
this.displayName = from.displayName;
|
||||||
|
this.maxCount = from.maxCount;
|
||||||
|
this.durability = from.durability;
|
||||||
|
this.damage = from.damage;
|
||||||
|
this.maxDamage = from.maxDamage;
|
||||||
|
|
||||||
|
if (from.enchantments != null) {
|
||||||
|
this.enchantments = from.enchantments;
|
||||||
|
} else {
|
||||||
|
this.enchantments = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Inventory implements IPeripheral {
|
||||||
|
public static inline final TYPE_NAME:String = "inventory";
|
||||||
|
|
||||||
|
private final addr:String;
|
||||||
|
|
||||||
|
public function new(addr:String) {
|
||||||
|
this.addr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddr():String {
|
||||||
|
return this.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType():String {
|
||||||
|
return TYPE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the size of this inventory.
|
||||||
|
**/
|
||||||
|
public function size():Int {
|
||||||
|
return Peripheral.call(this.addr, "size");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
List all items in this inventory.
|
||||||
|
**/
|
||||||
|
public function list():Map<Int, ItemInfo> {
|
||||||
|
var list:Map<Int, ReducedItemInfo> = Table.toMap(Peripheral.call(this.addr, "list"));
|
||||||
|
var rtn:Map<Int, ItemInfo> = new Map();
|
||||||
|
|
||||||
|
for (k => v in list) {
|
||||||
|
rtn.set(k - 1, new ItemInfo(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
return rtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get detailed information about an item.
|
||||||
|
**/
|
||||||
|
public function getItemDetail(slot:Int):DetailedItemInfo {
|
||||||
|
return new DetailedItemInfo(Peripheral.call(this.addr, "getItemDetail", slot + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the maximum number of items which can be stored in this slot.
|
||||||
|
Typically this will be limited to 64 items.
|
||||||
|
However, some inventorwies (such as barrels or caches) can store hundreds or thousands of items in one slot.
|
||||||
|
Keep in mind that this does not depend on that item stored in this slot.
|
||||||
|
**/
|
||||||
|
public function getItemLimit(slot:Int):Int {
|
||||||
|
return Peripheral.call(this.addr, "getItemLimit", slot + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Push items from one inventory to another connected one. Needs to be on the same wired network.
|
||||||
|
**/
|
||||||
|
public function pushItems(to:String, fromSlot:Int, ?limit:Int, ?toSlot:Int):Int {
|
||||||
|
return Peripheral.call(this.addr, "pushItems", to, fromSlot + 1, limit, toSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Pull items from a connected inventory into this one. Needs to be on the same wired network.
|
||||||
|
**/
|
||||||
|
public function pullItems(from:String, fromSlot:Int, ?limit:Int, ?toSlot:Int):Int {
|
||||||
|
return Peripheral.call(this.addr, "pullItems", from, fromSlot + 1, limit, toSlot);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,9 +11,9 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
public static inline final TYPE_NAME:String = "modem";
|
public static inline final TYPE_NAME:String = "modem";
|
||||||
|
|
||||||
public final addr:String;
|
public final addr:String;
|
||||||
public var onMessage(default, null):Signal<{pack:GenericPackage,dist:Null<Float>}>;
|
public var onMessage(default, null):Signal<{pack:GenericPackage, dist:Null<Float>}>;
|
||||||
|
|
||||||
private final onMessageTrigger:SignalTrigger<{pack:GenericPackage,dist:Null<Float>}> = Signal.trigger();
|
private final onMessageTrigger:SignalTrigger<{pack:GenericPackage, dist:Null<Float>}> = Signal.trigger();
|
||||||
private final native:cc.periphs.Modem.Modem;
|
private final native:cc.periphs.Modem.Modem;
|
||||||
|
|
||||||
@:allow(kernel.peripherals)
|
@:allow(kernel.peripherals)
|
||||||
@@ -22,9 +22,9 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
this.native = Peripheral.wrap(addr);
|
this.native = Peripheral.wrap(addr);
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
|
|
||||||
KernelEvents.onModemMessage.handle(params ->{
|
KernelEvents.onModemMessage.handle(params -> {
|
||||||
try{
|
try {
|
||||||
if (params.addr == this.addr){
|
if (params.addr == this.addr) {
|
||||||
var pack:GenericPackage = {
|
var pack:GenericPackage = {
|
||||||
fromID: params.message.fromID,
|
fromID: params.message.fromID,
|
||||||
toID: params.message.toID,
|
toID: params.message.toID,
|
||||||
@@ -36,7 +36,7 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
|
|
||||||
this.onMessageTrigger.trigger({pack: pack, dist: params.distance});
|
this.onMessageTrigger.trigger({pack: pack, dist: params.distance});
|
||||||
}
|
}
|
||||||
}catch(e:Dynamic){
|
} catch (e:Dynamic) {
|
||||||
Log.error("Error while parsing modem message");
|
Log.error("Error while parsing modem message");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -79,9 +79,9 @@ class Modem implements INetworkInterface implements IPeripheral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getBaseRoutingCost():Int {
|
public function getBaseRoutingCost():Int {
|
||||||
if (this.native.isWireless()){
|
if (this.native.isWireless()) {
|
||||||
return 2; // Prefere messages over cable
|
return 2; // Prefere messages over cable
|
||||||
}else{
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ using tink.CoreApi;
|
|||||||
Class responseable for retrieving peripherals.
|
Class responseable for retrieving peripherals.
|
||||||
**/
|
**/
|
||||||
class Peripheral {
|
class Peripheral {
|
||||||
public static function getAllAddresses(): Array<String> {
|
public static function getAllAddresses():Array<String> {
|
||||||
return cc.Peripheral.getNames().toArray();
|
return cc.Peripheral.getNames().toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isPresent(addr: String): Bool {
|
public static function isPresent(addr:String):Bool {
|
||||||
return cc.Peripheral.isPresent(addr);
|
return cc.Peripheral.isPresent(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTypes(addr: String): Array<String> {
|
public static function getTypes(addr:String):Array<String> {
|
||||||
if (!cc.Peripheral.isPresent(addr)) {
|
if (!cc.Peripheral.isPresent(addr)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -27,11 +27,11 @@ class Peripheral {
|
|||||||
return cc.Peripheral.getType(addr).toArray();
|
return cc.Peripheral.getType(addr).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function findAddrByType(type: String): Array<String> {
|
public static function findAddrByType(type:String):Array<String> {
|
||||||
return getAllAddresses().filter(addr -> getTypes(addr).contains(type));
|
return getAllAddresses().filter(addr -> getTypes(addr).contains(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function safeGetAddr(addr: String, type: String): Null<String> {
|
private static function safeGetAddr(addr:String, type:String):Null<String> {
|
||||||
if (!isPresent(addr)) {
|
if (!isPresent(addr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -44,18 +44,13 @@ class Peripheral {
|
|||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function inspect(addr: String): Null<{ types: Array<String>, methods: Array<String>}> {
|
public static function inspect(addr:String):Null<{types:Array<String>, methods:Array<String>}> {
|
||||||
if (!isPresent(addr)) {
|
if (!isPresent(addr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var types = getTypes(addr);
|
var types = getTypes(addr);
|
||||||
var methodsMap = cc.Peripheral.getMethods(addr).toArray();
|
var methods = cc.Peripheral.getMethods(addr).toArray();
|
||||||
var methods: Array<String> = [];
|
|
||||||
|
|
||||||
for (method in methodsMap) {
|
|
||||||
methods.push(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
types: types,
|
types: types,
|
||||||
@@ -67,8 +62,8 @@ class Peripheral {
|
|||||||
Cast peripheral to a specific type.
|
Cast peripheral to a specific type.
|
||||||
This is a temporary solution, maybe forever.
|
This is a temporary solution, maybe forever.
|
||||||
**/
|
**/
|
||||||
public static function getFromType(addr: String, type: String): Null<IPeripheral> {
|
public static function getFromType(addr:String, type:String):Null<IPeripheral> {
|
||||||
switch (type){
|
switch (type) {
|
||||||
case Computer.TYPE_NAME:
|
case Computer.TYPE_NAME:
|
||||||
return getComputer(addr);
|
return getComputer(addr);
|
||||||
case Screen.TYPE_NAME:
|
case Screen.TYPE_NAME:
|
||||||
@@ -81,76 +76,120 @@ class Peripheral {
|
|||||||
return getModem(addr);
|
return getModem(addr);
|
||||||
case Printer.TYPE_NAME:
|
case Printer.TYPE_NAME:
|
||||||
return getPrinter(addr);
|
return getPrinter(addr);
|
||||||
case "redstone":
|
case Speaker.TYPE_NAME:
|
||||||
|
return getSpeaker(addr);
|
||||||
|
case Redstone.TYPE_NAME:
|
||||||
return getRedstone(addr);
|
return getRedstone(addr);
|
||||||
|
case Inventory.TYPE_NAME:
|
||||||
|
return getInventory(addr);
|
||||||
|
case GeoScanner.TYPE_NAME:
|
||||||
|
return getGeoScanner(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getScreen(addr: String): Null<Screen> {
|
public static function getScreen(addr:String):Null<Screen> {
|
||||||
var addr = safeGetAddr(addr, Screen.TYPE_NAME);
|
var addr = safeGetAddr(addr, Screen.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Screen(addr);
|
return new Screen(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAllScreens():Array<Screen> {
|
||||||
public static function getAllScreens(): Array<Screen> {
|
return [for (addr in findAddrByType(Screen.TYPE_NAME)) new Screen(addr)];
|
||||||
return [ for (addr in findAddrByType(Screen.TYPE_NAME)) new Screen(addr)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getModem(addr: String): Null<Modem> {
|
public static function getModem(addr:String):Null<Modem> {
|
||||||
var addr = safeGetAddr(addr, Modem.TYPE_NAME);
|
var addr = safeGetAddr(addr, Modem.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Modem(addr);
|
return new Modem(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllModems(): Array<Modem> {
|
public static function getAllModems():Array<Modem> {
|
||||||
return [ for (addr in findAddrByType(Modem.TYPE_NAME)) new Modem(addr)];
|
return [for (addr in findAddrByType(Modem.TYPE_NAME)) new Modem(addr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDrive(addr: String): Null<Drive> {
|
public static function getDrive(addr:String):Null<Drive> {
|
||||||
var addr = safeGetAddr(addr, Drive.TYPE_NAME);
|
var addr = safeGetAddr(addr, Drive.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Drive(addr);
|
return new Drive(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllDrives(): Array<Drive> {
|
public static function getAllDrives():Array<Drive> {
|
||||||
return [ for (addr in findAddrByType(Drive.TYPE_NAME)) new Drive(addr)];
|
return [for (addr in findAddrByType(Drive.TYPE_NAME)) new Drive(addr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRedstone(side: String): Redstone {
|
public static function getRedstone(side:String):Redstone {
|
||||||
// TODO: maybe handle restone differently to not duplicate event listeners
|
// TODO: maybe handle restone differently to not duplicate event listeners
|
||||||
return new Redstone(side);
|
return new Redstone(side);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPrinter(addr: String):Null<Printer> {
|
public static function getPrinter(addr:String):Null<Printer> {
|
||||||
var addr = safeGetAddr(addr, Printer.TYPE_NAME);
|
var addr = safeGetAddr(addr, Printer.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Printer(addr);
|
return new Printer(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllPrinters(): Array<Printer> {
|
public static function getAllPrinters():Array<Printer> {
|
||||||
return [ for (addr in findAddrByType(Printer.TYPE_NAME)) new Printer(addr)];
|
return [for (addr in findAddrByType(Printer.TYPE_NAME)) new Printer(addr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getEnergyStorage(addr: String): Null<EnergyStorage> {
|
public static function getEnergyStorage(addr:String):Null<EnergyStorage> {
|
||||||
var addr = safeGetAddr(addr, EnergyStorage.TYPE_NAME);
|
var addr = safeGetAddr(addr, EnergyStorage.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new EnergyStorage(addr);
|
return new EnergyStorage(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllEnergyStorages(): Array<EnergyStorage> {
|
public static function getAllEnergyStorages():Array<EnergyStorage> {
|
||||||
return [ for (addr in findAddrByType(EnergyStorage.TYPE_NAME)) new EnergyStorage(addr)];
|
return [for (addr in findAddrByType(EnergyStorage.TYPE_NAME)) new EnergyStorage(addr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getComputer(addr: String): Null<Computer> {
|
public static function getComputer(addr:String):Null<Computer> {
|
||||||
var addr = safeGetAddr(addr, Computer.TYPE_NAME);
|
var addr = safeGetAddr(addr, Computer.TYPE_NAME);
|
||||||
if (addr == null) return null;
|
if (addr == null)
|
||||||
|
return null;
|
||||||
return new Computer(addr);
|
return new Computer(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllComputers(): Array<Computer> {
|
public static function getAllComputers():Array<Computer> {
|
||||||
return [ for (addr in findAddrByType(Computer.TYPE_NAME)) new Computer(addr)];
|
return [for (addr in findAddrByType(Computer.TYPE_NAME)) new Computer(addr)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSpeaker(addr:String):Null<Speaker> {
|
||||||
|
var addr = safeGetAddr(addr, Speaker.TYPE_NAME);
|
||||||
|
if (addr == null)
|
||||||
|
return null;
|
||||||
|
return new Speaker(addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAllSpeakers():Array<Speaker> {
|
||||||
|
return [for (addr in findAddrByType(Speaker.TYPE_NAME)) new Speaker(addr)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInventory(addr:String):Null<Inventory> {
|
||||||
|
var addr = safeGetAddr(addr, Inventory.TYPE_NAME);
|
||||||
|
if (addr == null)
|
||||||
|
return null;
|
||||||
|
return new Inventory(addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAllInventorys():Array<Inventory> {
|
||||||
|
return [for (addr in findAddrByType(Inventory.TYPE_NAME)) new Inventory(addr)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getGeoScanner(addr:String):Null<GeoScanner> {
|
||||||
|
var addr = safeGetAddr(addr, GeoScanner.TYPE_NAME);
|
||||||
|
if (addr == null)
|
||||||
|
return null;
|
||||||
|
return new GeoScanner(addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAllGeoScanners():Array<GeoScanner> {
|
||||||
|
return [for (addr in findAddrByType(GeoScanner.TYPE_NAME)) new GeoScanner(addr)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package kernel.peripherals;
|
|||||||
|
|
||||||
import cc.Peripheral;
|
import cc.Peripheral;
|
||||||
import lib.Rect;
|
import lib.Rect;
|
||||||
import lib.Pos;
|
import lib.ScreenPos;
|
||||||
|
|
||||||
class Printer implements IPeripheral {
|
class Printer implements IPeripheral {
|
||||||
public static inline final TYPE_NAME:String = "printer";
|
public static inline final TYPE_NAME:String = "printer";
|
||||||
@@ -10,7 +10,7 @@ class Printer implements IPeripheral {
|
|||||||
private final native:cc.periphs.Printer.Printer;
|
private final native:cc.periphs.Printer.Printer;
|
||||||
private final addr:String;
|
private final addr:String;
|
||||||
|
|
||||||
public function new(addr: String) {
|
public function new(addr:String) {
|
||||||
this.native = Peripheral.wrap(addr);
|
this.native = Peripheral.wrap(addr);
|
||||||
this.addr = addr;
|
this.addr = addr;
|
||||||
}
|
}
|
||||||
@@ -23,36 +23,34 @@ class Printer implements IPeripheral {
|
|||||||
return TYPE_NAME;
|
return TYPE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(text: String){
|
public function write(text:String) {}
|
||||||
|
|
||||||
|
public function getCurserPos():ScreenPos {
|
||||||
|
return new ScreenPos({x: 0, y: 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCurserPos(): Pos {
|
public function setCurserPos(pos:ScreenPos) {
|
||||||
return new Pos({x: 0, y: 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCurserPos(pos: Pos){
|
|
||||||
this.native.setCursorPos(pos.x, pos.y);
|
this.native.setCursorPos(pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPageSize(): Rect {
|
public function getPageSize():Rect {
|
||||||
var pos = this.native.getPageSize();
|
var pos = this.native.getPageSize();
|
||||||
return new Rect({x: 0, y: 0}, {x: pos.x, y: pos.y});
|
return new Rect({x: 0, y: 0}, {x: pos.x, y: pos.y});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newPage(): Bool{
|
public function newPage():Bool {
|
||||||
return this.native.newPage();
|
return this.native.newPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function endPage(): Bool{
|
public function endPage():Bool {
|
||||||
return this.native.endPage();
|
return this.native.endPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPageTitle(title: String){
|
public function setPageTitle(title:String) {
|
||||||
this.native.setPageTitle(title);
|
this.native.setPageTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInkLevel(): Float{
|
public function getInkLevel():Float {
|
||||||
return this.native.getInkLevel();
|
return this.native.getInkLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,38 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
import lib.exporter.ExportConfig;
|
import kernel.peripherals.interfaces.IRedstone;
|
||||||
import lib.exporter.IExportable;
|
|
||||||
import haxe.ds.ReadOnlyArray;
|
import haxe.ds.ReadOnlyArray;
|
||||||
import lib.Color;
|
import lib.Color;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
abstract BundleMask(Int) from cc.Colors.Color to cc.Colors.Color {
|
abstract BundleMask(Int) from cc.Colors.Color to cc.Colors.Color {
|
||||||
public inline function new(i:Int) {
|
public inline function new(i:Int) {
|
||||||
this = i;
|
this = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:from
|
@:from
|
||||||
public static function fromColor(c: Color) {
|
public static function fromColor(c:Color) {
|
||||||
return new BundleMask(c);
|
return new BundleMask(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:op(A + B)
|
@:op(A + B)
|
||||||
@:op(A | B)
|
@:op(A | B)
|
||||||
public inline function combine(rhs: BundleMask):BundleMask {
|
public inline function combine(rhs:BundleMask):BundleMask {
|
||||||
return this | rhs;
|
return this | rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:op(A + B)
|
@:op(A + B)
|
||||||
@:op(A | B)
|
@:op(A | B)
|
||||||
public inline function combineWithColor(rhs: Color):BundleMask {
|
public inline function combineWithColor(rhs:Color):BundleMask {
|
||||||
return this | rhs;
|
return this | rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getComponents(): ReadOnlyArray<Color> {
|
public function getComponents():ReadOnlyArray<Color> {
|
||||||
var components: Array<Color> = [];
|
var components:Array<Color> = [];
|
||||||
var mask = 1;
|
var mask = 1;
|
||||||
for (i in 0...16){
|
for (i in 0...16) {
|
||||||
if ((this & mask) > 0 ){
|
if ((this & mask) > 0) {
|
||||||
components.push(mask);
|
components.push(mask);
|
||||||
}
|
}
|
||||||
mask = mask << 1;
|
mask = mask << 1;
|
||||||
@@ -43,8 +42,7 @@ abstract BundleMask(Int) from cc.Colors.Color to cc.Colors.Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@:build(macros.Exporter.buildExport())
|
class Redstone implements IPeripheral implements IRedstone {
|
||||||
class Redstone implements IPeripheral implements IExportable {
|
|
||||||
public static inline final TYPE_NAME:String = "redstone"; // TODO: there is technically not a type for redstone.
|
public static inline final TYPE_NAME:String = "redstone"; // TODO: there is technically not a type for redstone.
|
||||||
|
|
||||||
public final onChange:Signal<Noise>;
|
public final onChange:Signal<Noise>;
|
||||||
@@ -57,19 +55,18 @@ class Redstone implements IPeripheral implements IExportable {
|
|||||||
private var bundleInputState:BundleMask;
|
private var bundleInputState:BundleMask;
|
||||||
|
|
||||||
@:allow(kernel.peripherals)
|
@:allow(kernel.peripherals)
|
||||||
private function new(side: Side) {
|
private function new(side:Side) {
|
||||||
this.addr = side;
|
this.addr = side;
|
||||||
this.onChange = this.onChangeTrigger.asSignal();
|
this.onChange = this.onChangeTrigger.asSignal();
|
||||||
|
|
||||||
updateState();
|
updateState();
|
||||||
|
|
||||||
KernelEvents.onRedstone.handle(()->{
|
KernelEvents.onRedstone.handle(() -> {
|
||||||
if ((this.getAnalogInput() != this.analogInputState) || (this.bundleInputState != this.getBundledInput())){
|
if ((this.getAnalogInput() != this.analogInputState) || (this.bundleInputState != this.getBundledInput())) {
|
||||||
updateState();
|
updateState();
|
||||||
this.onChangeTrigger.trigger(null);
|
this.onChangeTrigger.trigger(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAddr():String {
|
public function getAddr():String {
|
||||||
@@ -87,35 +84,33 @@ class Redstone implements IPeripheral implements IExportable {
|
|||||||
|
|
||||||
public inline function setOutput(on:Bool):Void {
|
public inline function setOutput(on:Bool):Void {
|
||||||
this.analogInputState = 15;
|
this.analogInputState = 15;
|
||||||
cc.Redstone.setOutput(this.addr,on);
|
cc.Redstone.setOutput(this.addr, on);
|
||||||
}
|
}
|
||||||
|
|
||||||
@export("output")
|
public inline function getOutput():Bool {
|
||||||
public inline function getOutput(): Bool {
|
|
||||||
return cc.Redstone.getOutput(this.addr);
|
return cc.Redstone.getOutput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@export("input")
|
public inline function getInput():Bool {
|
||||||
public inline function getInput(): Bool {
|
|
||||||
return cc.Redstone.getInput(this.addr);
|
return cc.Redstone.getInput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function setAnalogOutput(strength:Int): Void {
|
public inline function setAnalogOutput(strength:Int):Void {
|
||||||
this.analogInputState = strength;
|
this.analogInputState = strength;
|
||||||
cc.Redstone.setAnalogOutput(this.addr,strength);
|
cc.Redstone.setAnalogOutput(this.addr, strength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getAnalogOutput(): Int {
|
public inline function getAnalogOutput():Int {
|
||||||
return cc.Redstone.getAnalogOutput(this.addr);
|
return cc.Redstone.getAnalogOutput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getAnalogInput(): Int {
|
public inline function getAnalogInput():Int {
|
||||||
return cc.Redstone.getAnalogInput(this.addr);
|
return cc.Redstone.getAnalogInput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function setBundledOutput(output: BundleMask) {
|
public inline function setBundledOutput(output:BundleMask) {
|
||||||
this.bundleInputState = output;
|
this.bundleInputState = output;
|
||||||
cc.Redstone.setBundledOutput(this.addr,output);
|
cc.Redstone.setBundledOutput(this.addr, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function getBundledOutput():BundleMask {
|
public inline function getBundledOutput():BundleMask {
|
||||||
@@ -126,7 +121,7 @@ class Redstone implements IPeripheral implements IExportable {
|
|||||||
return cc.Redstone.getBundledInput(this.addr);
|
return cc.Redstone.getBundledInput(this.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline function testBundledInput(mask: Color): Bool {
|
public inline function testBundledInput(mask:Color):Bool {
|
||||||
return cc.Redstone.testBundledInput(this.addr,mask);
|
return cc.Redstone.testBundledInput(this.addr, mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
package kernel.peripherals;
|
package kernel.peripherals;
|
||||||
|
|
||||||
import cc.Peripheral;
|
import cc.Peripheral;
|
||||||
import lib.Pos;
|
import lib.ScreenPos;
|
||||||
import cc.Term.TerminalSize;
|
import cc.Term.TerminalSize;
|
||||||
import kernel.ui.TermWriteable;
|
import kernel.ui.ITermWriteable;
|
||||||
import lib.Vec.Vec2;
|
import lib.Vec.Vec2;
|
||||||
import lib.Color;
|
import lib.Color;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Screen implements TermWriteable implements IPeripheral {
|
class Screen implements ITermWriteable implements IPeripheral {
|
||||||
public static inline final TYPE_NAME:String = "monitor";
|
public static inline final TYPE_NAME:String = "monitor";
|
||||||
|
|
||||||
private final nativ:cc.periphs.Monitor.Monitor;
|
private final nativ:cc.periphs.Monitor.Monitor;
|
||||||
private final addr:String;
|
private final addr:String;
|
||||||
|
|
||||||
private final onResizeTrigger:SignalTrigger<Vec2<Int>> = Signal.trigger();
|
private final onResizeTrigger:SignalTrigger<Vec2<Int>> = Signal.trigger();
|
||||||
|
|
||||||
public final onResize:Signal<Vec2<Int>>;
|
public final onResize:Signal<Vec2<Int>>;
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ class Screen implements TermWriteable implements IPeripheral {
|
|||||||
nativ.scroll(y);
|
nativ.scroll(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCursorPos():Pos {
|
public function getCursorPos():ScreenPos {
|
||||||
var rtn = nativ.getCursorPos();
|
var rtn = nativ.getCursorPos();
|
||||||
return {
|
return {
|
||||||
x: rtn.x - 1,
|
x: rtn.x - 1,
|
||||||
@@ -119,6 +119,6 @@ class Screen implements TermWriteable implements IPeripheral {
|
|||||||
this.setBackgroundColor(Black);
|
this.setBackgroundColor(Black);
|
||||||
this.setTextColor(White);
|
this.setTextColor(White);
|
||||||
this.clear();
|
this.clear();
|
||||||
this.setCursorPos(0,0);
|
this.setCursorPos(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ enum abstract Side(String) to String {
|
|||||||
var Back = "back";
|
var Back = "back";
|
||||||
|
|
||||||
@:from
|
@:from
|
||||||
static public function fromString(s: String) {
|
static public function fromString(s:String) {
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case "top":
|
case "top":
|
||||||
return Top;
|
return Top;
|
||||||
|
|||||||
61
src/kernel/peripherals/Speaker.hx
Normal file
61
src/kernel/peripherals/Speaker.hx
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package kernel.peripherals;
|
||||||
|
|
||||||
|
import cc.Peripheral;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
class Speaker implements IPeripheral {
|
||||||
|
public static inline final TYPE_NAME:String = "speaker";
|
||||||
|
|
||||||
|
private final addr:String;
|
||||||
|
|
||||||
|
public function new(addr:String) {
|
||||||
|
this.addr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType():String {
|
||||||
|
return Speaker.TYPE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddr():String {
|
||||||
|
return this.addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Plays a note block note through the speaker.
|
||||||
|
The pitch argument uses semitones as the unit. This directly maps to the number of clicks on a note block.
|
||||||
|
For reference, 0, 12, and 24 map to F#, and 6 and 18 map to C.
|
||||||
|
A maximum of 8 notes can be played in a single tick. If this limit is hit, this function will return an error.
|
||||||
|
**/
|
||||||
|
public function playNote(instrument:String, ?volume:Float = 1.0, ?pitch:Int = 12):Outcome<Noise, String> {
|
||||||
|
if (Peripheral.call(addr, "playNote", instrument, volume, pitch)) {
|
||||||
|
return Success(null);
|
||||||
|
} else {
|
||||||
|
return Failure("maximum reached");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function playSound(sound:String, ?volume:Float = 1.0, ?pitch:Float = 1.0):Outcome<Noise, String> {
|
||||||
|
try {
|
||||||
|
if (Peripheral.call(addr, "playSound", sound, volume, pitch)) {
|
||||||
|
return Success(null);
|
||||||
|
} else {
|
||||||
|
return Failure("Sound still playing");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return Failure("Sound does not exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function playAudio(buffer:Array<Int>, ?volume:Float = 1.0):Outcome<Noise, String> {
|
||||||
|
try {
|
||||||
|
if (Peripheral.call(addr, "playAudio", buffer, volume)) {
|
||||||
|
return Success(null);
|
||||||
|
} else {
|
||||||
|
return Failure("Buffer full");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return Failure("Buffer malformed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/kernel/peripherals/exports/RedstoneExport.hx
Normal file
7
src/kernel/peripherals/exports/RedstoneExport.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package kernel.peripherals.exports;
|
||||||
|
|
||||||
|
import macros.rpc.RPCBase;
|
||||||
|
import kernel.peripherals.interfaces.IRedstone;
|
||||||
|
|
||||||
|
@:build(macros.rpc.RPC.buildRPC(IRedstone))
|
||||||
|
class RedstoneExport extends RPCBase {}
|
||||||
17
src/kernel/peripherals/interfaces/IRedstone.hx
Normal file
17
src/kernel/peripherals/interfaces/IRedstone.hx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package kernel.peripherals.interfaces;
|
||||||
|
|
||||||
|
import cc.Colors.Color;
|
||||||
|
import kernel.peripherals.Redstone.BundleMask;
|
||||||
|
|
||||||
|
interface IRedstone {
|
||||||
|
function setOutput(on:Bool):Void;
|
||||||
|
function getOutput():Bool;
|
||||||
|
function getInput():Bool;
|
||||||
|
function setAnalogOutput(strength:Int):Void;
|
||||||
|
function getAnalogOutput():Int;
|
||||||
|
function getAnalogInput():Int;
|
||||||
|
function setBundledOutput(output:BundleMask):Void;
|
||||||
|
function getBundledOutput():BundleMask;
|
||||||
|
function getBundledInput():BundleMask;
|
||||||
|
function testBundledInput(mask:Color):Bool;
|
||||||
|
}
|
||||||
34
src/kernel/pocket/Pocket.hx
Normal file
34
src/kernel/pocket/Pocket.hx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package kernel.pocket;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
class Pocket {
|
||||||
|
public static function isPocket():Bool {
|
||||||
|
return cc.Pocket != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Search the player's inventory for another upgrade, replacing the existing one with that item if found.
|
||||||
|
This inventory search starts from the player's currently selected slot, allowing you to prioritise upgrades.
|
||||||
|
**/
|
||||||
|
public static function equipBack():Outcome<Noise, String> {
|
||||||
|
var r = cc.Pocket.equipBack();
|
||||||
|
if (r.successful) {
|
||||||
|
return Success(Noise);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Failure(r.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Remove the pocket computer's current upgrade.
|
||||||
|
**/
|
||||||
|
public static function unequipBack():Outcome<Noise, String> {
|
||||||
|
var r = cc.Pocket.unequipBack();
|
||||||
|
if (r.successful) {
|
||||||
|
return Success(Noise);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Failure(r.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/kernel/ps/IProcess.hx
Normal file
8
src/kernel/ps/IProcess.hx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package kernel.ps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Defines an independent process that can be run by the kernel.
|
||||||
|
**/
|
||||||
|
interface IProcess {
|
||||||
|
public function run(handle:ProcessHandle):Void;
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package kernel.ps;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Defines an independent process that can be run by the kernel.
|
|
||||||
**/
|
|
||||||
@:autoBuild(macros.DCEHack.DCEHack.dceInclude())
|
|
||||||
interface Process {
|
|
||||||
public function run(handle: ProcessHandle): Void;
|
|
||||||
}
|
|
||||||
@@ -1,35 +1,37 @@
|
|||||||
package kernel.ps;
|
package kernel.ps;
|
||||||
|
|
||||||
|
import kernel.turtle.TurtleMutex;
|
||||||
import kernel.ps.ProcessManager.PID;
|
import kernel.ps.ProcessManager.PID;
|
||||||
import kernel.ui.WindowContext;
|
import kernel.ui.WindowContext;
|
||||||
import kernel.ui.WindowManager;
|
import kernel.ui.WindowManager;
|
||||||
import haxe.ds.ReadOnlyArray;
|
import haxe.ds.ReadOnlyArray;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
typedef HandleConfig = {
|
typedef HandleConfig = {
|
||||||
?args: Array<String>,
|
?args:Array<String>,
|
||||||
?onWrite: Callback<String>,
|
?onWrite:Callback<String>,
|
||||||
?onExit: Callback<Bool>,
|
?onExit:Callback<Bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProcessHandle {
|
class ProcessHandle {
|
||||||
public var args(get,null): ReadOnlyArray<String>;
|
public var args(get, null):ReadOnlyArray<String>;
|
||||||
|
|
||||||
private final pid: PID;
|
private final pid:PID;
|
||||||
private final config:HandleConfig;
|
private final config:HandleConfig;
|
||||||
private final closeFuture: Future<Bool>;
|
private final closeFuture:Future<Bool>;
|
||||||
private var closeFutureResolev: Bool -> Void;
|
private var closeFutureResolev:Bool->Void;
|
||||||
private final windowContexts: Array<WindowContext> = [];
|
private final windowContexts:Array<WindowContext> = [];
|
||||||
private final cbLinks:Array<CallbackLink> = [];
|
private final cbLinks:Array<CallbackLink> = [];
|
||||||
private final deferFuncs:Array<Void -> Void> = [];
|
private final deferFuncs:Array<Void->Void> = [];
|
||||||
private var hasExited: Bool = false;
|
private var hasExited:Bool = false;
|
||||||
|
|
||||||
@:allow(kernel.ps.ProcessManager)
|
@:allow(kernel.ps.ProcessManager)
|
||||||
private function new(config: HandleConfig,pid: PID) {
|
private function new(config:HandleConfig, pid:PID) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.pid = pid;
|
this.pid = pid;
|
||||||
|
|
||||||
this.closeFuture = new Future<Bool>((trigger)->{
|
this.closeFuture = new Future<Bool>((trigger) -> {
|
||||||
this.closeFutureResolev = trigger;
|
this.closeFutureResolev = trigger;
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -39,42 +41,45 @@ class ProcessHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onExit(): Future<Bool> {
|
public function onExit():Future<Bool> {
|
||||||
return this.closeFuture;
|
return this.closeFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(success: Bool = true): Void {
|
public function close(success:Bool = true):Void {
|
||||||
this.hasExited = true;
|
this.hasExited = true;
|
||||||
this.dispose();
|
this.dispose();
|
||||||
|
|
||||||
EndOfLoop.endOfLoop(() ->{this.closeFutureResolev(success);});
|
EndOfLoop.endOfLoop(() -> {
|
||||||
|
this.closeFutureResolev(success);
|
||||||
|
});
|
||||||
ProcessManager.removeProcess(this.pid);
|
ProcessManager.removeProcess(this.pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(message: String): Void {
|
public function write(message:String):Void {
|
||||||
if (this.hasExited) return;
|
if (this.hasExited)
|
||||||
if (this.config.onWrite != null){
|
return;
|
||||||
|
if (this.config.onWrite != null) {
|
||||||
this.config.onWrite.invoke(message);
|
this.config.onWrite.invoke(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function writeLine(message: String): Void {
|
public function writeLine(message:String):Void {
|
||||||
this.write(message + "\n");
|
this.write(message + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createBufferdWindowContext(): WindowContext {
|
public function createBufferdWindowContext():WindowContext {
|
||||||
var ctx = WindowManager.createNewContext();
|
var ctx = WindowManager.createNewContext();
|
||||||
this.windowContexts.push(ctx);
|
this.windowContexts.push(ctx);
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createStatelessWindowContext(): {ctx:WindowContext, setRenderFunc: (() -> Void) -> Void, requestRender:() -> Void} {
|
public function createStatelessWindowContext():{ctx:WindowContext, setRenderFunc:(() -> Void)->Void, requestRender:() -> Void} {
|
||||||
var ctx = WindowManager.createNewStatelessContext();
|
var ctx = WindowManager.createNewStatelessContext();
|
||||||
this.windowContexts.push(ctx.ctx);
|
this.windowContexts.push(ctx.ctx);
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWindowContexts(): ReadOnlyArray<WindowContext> {
|
public function getWindowContexts():ReadOnlyArray<WindowContext> {
|
||||||
return this.windowContexts;
|
return this.windowContexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,19 +93,31 @@ class ProcessHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPid(): PID {
|
public function getPid():PID {
|
||||||
return this.pid;
|
return this.pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addCallbackLink(link: CallbackLink) {
|
public function addCallbackLink(link:CallbackLink) {
|
||||||
this.cbLinks.push(link);
|
this.cbLinks.push(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addDeferFunc(func: Void -> Void) {
|
public function addDeferFunc(func:Void->Void) {
|
||||||
this.deferFuncs.push(func);
|
this.deferFuncs.push(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_args():ReadOnlyArray<String> {
|
public function get_args():ReadOnlyArray<String> {
|
||||||
return this.config.args;
|
return this.config.args != null ? this.config.args : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function claimTurtleMutex():Bool {
|
||||||
|
if (TurtleMutex.claim(this.pid)) {
|
||||||
|
this.addDeferFunc(() -> {
|
||||||
|
TurtleMutex.release(this.pid);
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,26 +8,26 @@ using tink.CoreApi;
|
|||||||
typedef PID = Int;
|
typedef PID = Int;
|
||||||
|
|
||||||
class ProcessManager {
|
class ProcessManager {
|
||||||
private static final processList = new Map<PID,ProcessHandle>();
|
private static final processList = new Map<PID, ProcessHandle>();
|
||||||
|
|
||||||
public static function run(process:Process, config: HandleConfig):PID {
|
public static function run(process:IProcess, config:HandleConfig):PID {
|
||||||
var pid = createPID();
|
var pid = createPID();
|
||||||
var handle = new ProcessHandle(config, pid);
|
var handle = new ProcessHandle(config, pid);
|
||||||
|
|
||||||
processList.set(pid, handle);
|
processList.set(pid, handle);
|
||||||
|
|
||||||
try{
|
try {
|
||||||
process.run(handle);
|
process.run(handle);
|
||||||
}catch(e:Dynamic){
|
} catch (e:Dynamic) {
|
||||||
Log.error("Error while running process: " + e);
|
Log.error("Error while running process: " + e);
|
||||||
handle.close(false);
|
handle.close(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function kill(pid: PID) {
|
public static function kill(pid:PID) {
|
||||||
if (!processList.exists(pid)){
|
if (!processList.exists(pid)) {
|
||||||
Log.warn("Trying to kill non-existing process: " + pid);
|
Log.warn("Trying to kill non-existing process: " + pid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ class ProcessManager {
|
|||||||
handle.close();
|
handle.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createPID(): PID {
|
private static function createPID():PID {
|
||||||
// TODO: better PID generation
|
// TODO: better PID generation
|
||||||
|
|
||||||
// generate a random PID
|
// generate a random PID
|
||||||
@@ -45,7 +45,7 @@ class ProcessManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@:allow(kernel.ui.WindowManager)
|
@:allow(kernel.ui.WindowManager)
|
||||||
private static function getProcess(pid:PID):Null<ProcessHandle>{
|
private static function getProcess(pid:PID):Null<ProcessHandle> {
|
||||||
return processList.get(pid);
|
return processList.get(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,38 @@
|
|||||||
package kernel.service;
|
package kernel.service;
|
||||||
|
|
||||||
import kernel.ps.Process;
|
import kernel.ps.IProcess;
|
||||||
import kernel.ps.ProcessManager;
|
import kernel.ps.ProcessManager;
|
||||||
import kernel.binstore.BinStore;
|
import kernel.binstore.BinStore;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Service {
|
class Service {
|
||||||
public final binName:String;
|
public final binName:String;
|
||||||
public final name:String;
|
public final name:String;
|
||||||
public final args:Array<String>;
|
public final args:Array<String>;
|
||||||
public var pid:PID;
|
public var pid:PID;
|
||||||
public var ps: Process;
|
public var ps:IProcess;
|
||||||
|
|
||||||
@:allow(kernel.service.ServiceManager)
|
@:allow(kernel.service.ServiceManager)
|
||||||
private function new(binName: String,name: String,?args: Array<String> ) {
|
private function new(binName:String, name:String, ?args:Array<String>) {
|
||||||
this.binName = binName;
|
this.binName = binName;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.args = args ?? [];
|
this.args = args ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start() {
|
public function start() {
|
||||||
var bin = BinStore.getBinByAlias(this.binName);
|
var ps = BinStore.instantiate(this.binName);
|
||||||
|
|
||||||
if (bin == null){
|
if (ps == null) {
|
||||||
throw new Error('Bin ${this.binName} not found');
|
throw new Error('Bin ${this.binName} not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ps = Type.createInstance(bin.c,this.args);
|
|
||||||
|
|
||||||
this.pid = ProcessManager.run(this.ps,{});
|
this.ps = ps;
|
||||||
}
|
|
||||||
|
|
||||||
public function stop() {
|
this.pid = ProcessManager.run(this.ps, {});
|
||||||
ProcessManager.kill(this.pid);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
public function stop() {
|
||||||
|
ProcessManager.kill(this.pid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,135 +7,143 @@ import lib.KVStore;
|
|||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class ServiceManager {
|
class ServiceManager {
|
||||||
private static final services:Map<String,Service> = new Map();
|
private static final services:Map<String, Service> = new Map();
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
@:allow(kernel.Init)
|
||||||
private static function init() {
|
private static function init() {
|
||||||
startAllEnabled();
|
startAllEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Add a service to be automatically started.
|
|
||||||
**/
|
|
||||||
public static function enable(name: String) {
|
|
||||||
if (!services.exists(name)){
|
|
||||||
return; // Service must be started
|
|
||||||
}
|
|
||||||
|
|
||||||
var store = KVStore.getStoreForClass();
|
/**
|
||||||
|
Add a service to be automatically started.
|
||||||
|
**/
|
||||||
|
public static function enable(name:String):Outcome<Noise, String> {
|
||||||
|
if (!services.exists(name)) {
|
||||||
|
return Failure("Service must be started before enable");
|
||||||
|
}
|
||||||
|
|
||||||
var enabled = store.get("enabled",[]);
|
var store = KVStore.getStoreForClass();
|
||||||
enabled.push(name);
|
store.load();
|
||||||
store.set("enabled",enabled);
|
|
||||||
|
|
||||||
store.save();
|
var enabled = store.get("enabled", []);
|
||||||
}
|
enabled.push(name);
|
||||||
|
store.set("enabled", enabled);
|
||||||
|
|
||||||
/**
|
store.save();
|
||||||
Remove a service from being automatically started.
|
|
||||||
**/
|
|
||||||
private static function disable(name: String) {
|
|
||||||
var store = KVStore.getStoreForClass();
|
|
||||||
var enabled: Array<String> = store.get("enabled");
|
|
||||||
var index = enabled.indexOf(name);
|
|
||||||
if (index == -1){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
enabled.splice(index,1);
|
return Success(Noise);
|
||||||
store.save();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static function startAllEnabled() {
|
/**
|
||||||
var store = KVStore.getStoreForClass();
|
Remove a service from being automatically started.
|
||||||
var enabled: Array<String> = store.get("enabled",[]);
|
**/
|
||||||
for (name in enabled){
|
private static function disable(name:String):Outcome<Noise, String> {
|
||||||
start(name);
|
var store = KVStore.getStoreForClass();
|
||||||
}
|
store.load();
|
||||||
}
|
|
||||||
|
|
||||||
private static function load(name: String): Null<Service> {
|
var enabled:Array<String> = store.get("enabled");
|
||||||
var store = new KVStore('service/${name}');
|
var index = enabled.indexOf(name);
|
||||||
store.load();
|
if (index == -1) {
|
||||||
if (!store.exists("service")){
|
return Failure("Service not found");
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return store.get("service");
|
enabled.splice(index, 1);
|
||||||
}
|
store.save();
|
||||||
|
|
||||||
public static function register(name: String, binName: String,args: Array<String>): Outcome<Noise,String> {
|
return Success(Noise);
|
||||||
if (BinStore.getBinByAlias(binName) == null){
|
}
|
||||||
return Failure("bin not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (load(name) != null){
|
private static function startAllEnabled() {
|
||||||
return Failure("service already exists");
|
var store = KVStore.getStoreForClass();
|
||||||
}
|
store.load();
|
||||||
|
|
||||||
var service = new Service(binName,name,args);
|
var enabled:Array<String> = store.get("enabled", []);
|
||||||
|
for (name in enabled) {
|
||||||
|
start(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var store = new KVStore('service/${name}');
|
private static function load(name:String):Null<Service> {
|
||||||
store.set("service",service);
|
var store = new KVStore('service/${name}');
|
||||||
store.save();
|
store.load();
|
||||||
|
if (!store.exists("service")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Log.info('Service ${name} registered');
|
return store.get("service");
|
||||||
return Success(Noise);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static function unregister(name: String): Outcome<Noise,String> {
|
public static function register(name:String, binName:String, args:Array<String>):Outcome<Noise, String> {
|
||||||
if (services.exists(name)){
|
if (BinStore.getNameByAlias(binName) == null) {
|
||||||
return Failure("service is running");
|
return Failure("bin not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
KVStore.removeNamespace('service/${name}');
|
if (load(name) != null) {
|
||||||
Log.info('Service ${name} unregistered');
|
return Failure("service already exists");
|
||||||
return Success(Noise);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static function start(name: String): Outcome<Noise,String> {
|
|
||||||
var service = load(name);
|
|
||||||
if (service == null){
|
|
||||||
return Failure("service not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
service.start();
|
var service = new Service(binName, name, args);
|
||||||
services.set(name,service);
|
|
||||||
|
|
||||||
Log.info('Service ${name} started');
|
var store = new KVStore('service/${name}');
|
||||||
return Success(Noise);
|
store.set("service", service);
|
||||||
}
|
store.save();
|
||||||
|
|
||||||
public static function stop(name: String): Outcome<Noise,String> {
|
Log.info('Service ${name} registered');
|
||||||
if (!services.exists(name)){
|
return Success(Noise);
|
||||||
return Failure("service not found");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var service = services.get(name);
|
public static function unregister(name:String):Outcome<Noise, String> {
|
||||||
service.stop();
|
if (services.exists(name)) {
|
||||||
services.remove(name);
|
return Failure("service is running");
|
||||||
|
}
|
||||||
|
|
||||||
Log.info('Service ${name} stopped');
|
KVStore.removeNamespace('service/${name}');
|
||||||
return Success(Noise);
|
Log.info('Service ${name} unregistered');
|
||||||
}
|
return Success(Noise);
|
||||||
|
}
|
||||||
|
|
||||||
public static function listRunning(): Array<String> {
|
public static function start(name:String):Outcome<Noise, String> {
|
||||||
var running = [];
|
var service = load(name);
|
||||||
for (name in services.keys()){
|
if (service == null) {
|
||||||
running.push(name);
|
return Failure("service not found");
|
||||||
}
|
}
|
||||||
return running;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function get(name: String): Null<Dynamic> {
|
service.start();
|
||||||
if (!services.exists(name)){
|
services.set(name, service);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Maybe there is a way to check types here?
|
Log.info('Service ${name} started');
|
||||||
|
return Success(Noise);
|
||||||
var srv = services.get(name);
|
}
|
||||||
return srv.ps;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static function stop(name:String):Outcome<Noise, String> {
|
||||||
|
if (!services.exists(name)) {
|
||||||
|
return Failure("service not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
var service = services.get(name);
|
||||||
|
service.stop();
|
||||||
|
services.remove(name);
|
||||||
|
|
||||||
|
Log.info('Service ${name} stopped');
|
||||||
|
return Success(Noise);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function listRunning():Array<String> {
|
||||||
|
var running = [];
|
||||||
|
for (name in services.keys()) {
|
||||||
|
running.push(name);
|
||||||
|
}
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get(name:String):Null<Dynamic> {
|
||||||
|
if (!services.exists(name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Maybe there is a way to check types here?
|
||||||
|
|
||||||
|
var srv = services.get(name);
|
||||||
|
return srv.ps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,18 @@
|
|||||||
package kernel.turtle;
|
package kernel.turtle;
|
||||||
|
|
||||||
import kernel.log.Log;
|
|
||||||
import kernel.turtle.Types;
|
import kernel.turtle.Types;
|
||||||
import kernel.gps.INS;
|
import kernel.gps.INS;
|
||||||
|
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
class Turtle {
|
class Turtle {
|
||||||
public static var instance:Turtle;
|
|
||||||
public static final MAX_SLOTS:Int = 16;
|
public static final MAX_SLOTS:Int = 16;
|
||||||
|
|
||||||
@:allow(kernel.Init)
|
|
||||||
private function new() {
|
|
||||||
if (!Turtle.isTurtle()) {
|
|
||||||
Log.warn("Tried to initialize Turtle, but it is not available.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function isTurtle():Bool {
|
public static function isTurtle():Bool {
|
||||||
return true; // TODO: Implement
|
return cc.Turtle != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function conterToOutcome(r:cc.Turtle.TurtleActionResult):Outcome<Noise, String> {
|
private static function conterToOutcome(r:cc.Turtle.TurtleActionResult):Outcome<Noise, String> {
|
||||||
if (r.successful) {
|
if (r.successful) {
|
||||||
return Outcome.Success(null);
|
return Outcome.Success(null);
|
||||||
} else {
|
} else {
|
||||||
@@ -33,49 +24,60 @@ class Turtle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function forward():Outcome<Noise, String> {
|
public static function forward():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.forward();
|
var r = cc.Turtle.forward();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.moveForward();
|
if (r2.isSuccess())
|
||||||
|
INS.moveForward();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function back():Outcome<Noise, String> {
|
public static function back():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.back();
|
var r = cc.Turtle.back();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.moveBackward();
|
if (r2.isSuccess())
|
||||||
|
INS.moveBackward();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function up():Outcome<Noise, String> {
|
public static function up():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.up();
|
var r = cc.Turtle.up();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.moveUp();
|
if (r2.isSuccess())
|
||||||
|
INS.moveUp();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down():Outcome<Noise, String> {
|
public static function down():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.down();
|
var r = cc.Turtle.down();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.moveDown();
|
if (r2.isSuccess())
|
||||||
|
INS.moveDown();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function turnLeft():Outcome<Noise, String> {
|
public static function turnLeft():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.turnLeft();
|
var r = cc.Turtle.turnLeft();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.turnRight();
|
if (r2.isSuccess())
|
||||||
|
INS.turnRight();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function turnRight():Outcome<Noise, String> {
|
public static function turnRight():Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.turnRight();
|
var r = cc.Turtle.turnRight();
|
||||||
var r2 = conterToOutcome(r);
|
var r2 = conterToOutcome(r);
|
||||||
if (r2.isSuccess()) INS.turnRight();
|
if (r2.isSuccess())
|
||||||
|
INS.turnRight();
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dig(dir:InteractDirections, ?toolSide:ToolSide):Outcome<Noise, String> {
|
/**
|
||||||
|
Dig in the provided direction.
|
||||||
|
Keep in mind that digging on a empty space is considerd a failure.
|
||||||
|
Also see `digEmpty`.
|
||||||
|
**/
|
||||||
|
public static function dig(dir:InteractDirections, ?toolSide:ToolSide):Outcome<Noise, String> {
|
||||||
var r:cc.Turtle.TurtleActionResult;
|
var r:cc.Turtle.TurtleActionResult;
|
||||||
|
|
||||||
// FIXME: upstream needs to be fixed to accept ToolSide
|
// FIXME: upstream needs to be fixed to accept ToolSide
|
||||||
@@ -90,7 +92,37 @@ class Turtle {
|
|||||||
return conterToOutcome(r);
|
return conterToOutcome(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(dir:InteractDirections):Outcome<Noise, String> {
|
/**
|
||||||
|
Dig in the provided direction.
|
||||||
|
Does not fail if there is nothing to dig.
|
||||||
|
Also see `dig`.
|
||||||
|
**/
|
||||||
|
public static function digEmpty(dir:InteractDirections, ?toolSide:ToolSide):Outcome<Noise, String> {
|
||||||
|
var r:cc.Turtle.TurtleActionResult;
|
||||||
|
|
||||||
|
// FIXME: upstream needs to be fixed to accept ToolSide
|
||||||
|
switch dir {
|
||||||
|
case Front:
|
||||||
|
r = cc.Turtle.dig();
|
||||||
|
case Up:
|
||||||
|
r = cc.Turtle.digUp();
|
||||||
|
case Down:
|
||||||
|
r = cc.Turtle.digDown();
|
||||||
|
}
|
||||||
|
var result = conterToOutcome(r);
|
||||||
|
|
||||||
|
switch (result) {
|
||||||
|
case Success(_):
|
||||||
|
return result;
|
||||||
|
case Failure(failure):
|
||||||
|
if (failure == "Nothing to dig here") {
|
||||||
|
return Success(null);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function place(dir:InteractDirections):Outcome<Noise, String> {
|
||||||
var r:cc.Turtle.TurtleActionResult;
|
var r:cc.Turtle.TurtleActionResult;
|
||||||
switch dir {
|
switch dir {
|
||||||
case Front:
|
case Front:
|
||||||
@@ -103,7 +135,7 @@ class Turtle {
|
|||||||
return conterToOutcome(r);
|
return conterToOutcome(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function placeSign(dir:InteractDirections, text:String):Outcome<Noise, String> {
|
public static function placeSign(dir:InteractDirections, text:String):Outcome<Noise, String> {
|
||||||
var r:cc.Turtle.TurtleActionResult;
|
var r:cc.Turtle.TurtleActionResult;
|
||||||
switch dir {
|
switch dir {
|
||||||
case Front:
|
case Front:
|
||||||
@@ -116,32 +148,26 @@ class Turtle {
|
|||||||
return conterToOutcome(r);
|
return conterToOutcome(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function drop(dir:InteractDirections, ?count:Int):Outcome<Noise, String> {
|
public static function drop(dir:InteractDirections, ?count:Int):Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.drop(count);
|
var r = cc.Turtle.drop(count);
|
||||||
return conterToOutcome(r);
|
return conterToOutcome(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function selectSlot(slot:TurtleSlot):Outcome<Noise, Noise> {
|
public static function selectSlot(slot:TurtleSlot):Outcome<Noise, Noise> {
|
||||||
// TODO: slot in bounds?
|
var r = cc.Turtle.select(slot.toCCSlot());
|
||||||
|
|
||||||
var r = cc.Turtle.select(slot + 1);
|
|
||||||
|
|
||||||
return (r) ? Outcome.Success(null) : Outcome.Failure("Slot out of bounds");
|
return (r) ? Outcome.Success(null) : Outcome.Failure("Slot out of bounds");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getItemCount(?slot:TurtleSlot):Int {
|
public static function getItemCount(?slot:TurtleSlot):Int {
|
||||||
// TODO: slot in bounds?
|
return cc.Turtle.getItemCount(slot.toCCSlot());
|
||||||
|
|
||||||
return cc.Turtle.getItemCount(slot + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getItemSpace(?slot:TurtleSlot):Int {
|
public static function getItemSpace(?slot:TurtleSlot):Int {
|
||||||
// TODO: slot in bounds?
|
return cc.Turtle.getItemSpace(slot.toCCSlot());
|
||||||
|
|
||||||
return cc.Turtle.getItemSpace(slot + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detect(dir:InteractDirections):Bool {
|
public static function detect(dir:InteractDirections):Bool {
|
||||||
switch dir {
|
switch dir {
|
||||||
case Front:
|
case Front:
|
||||||
return cc.Turtle.detect();
|
return cc.Turtle.detect();
|
||||||
@@ -152,7 +178,7 @@ class Turtle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compareToSlot(dir:InteractDirections):Bool {
|
public static function compareToSlot(dir:InteractDirections):Bool {
|
||||||
switch dir {
|
switch dir {
|
||||||
case Front:
|
case Front:
|
||||||
return cc.Turtle.compare();
|
return cc.Turtle.compare();
|
||||||
@@ -163,7 +189,7 @@ class Turtle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attack(dir:InteractDirections, ?toolSide:ToolSide):Outcome<Noise, String> {
|
public static function attack(dir:InteractDirections, ?toolSide:ToolSide):Outcome<Noise, String> {
|
||||||
var r:cc.Turtle.TurtleActionResult;
|
var r:cc.Turtle.TurtleActionResult;
|
||||||
|
|
||||||
// FIXEM: upstream needs to be fixed to accept ToolSide
|
// FIXEM: upstream needs to be fixed to accept ToolSide
|
||||||
@@ -179,7 +205,7 @@ class Turtle {
|
|||||||
return conterToOutcome(r);
|
return conterToOutcome(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function suckItem(dir:InteractDirections, ?ammount:Int):Outcome<Noise, String> {
|
public static function suckItem(dir:InteractDirections, ?ammount:Int):Outcome<Noise, String> {
|
||||||
// TODO: ammount in bounds?
|
// TODO: ammount in bounds?
|
||||||
|
|
||||||
var r:cc.Turtle.TurtleActionResult;
|
var r:cc.Turtle.TurtleActionResult;
|
||||||
@@ -195,40 +221,40 @@ class Turtle {
|
|||||||
return conterToOutcome(r);
|
return conterToOutcome(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFuelLevel():Int {
|
public static function getFuelLevel():Int {
|
||||||
var r = cc.Turtle.getFuelLevel(); // FIXME: can be a string. Has to be fixed upstream
|
var r = cc.Turtle.getFuelLevel(); // FIXME: can be a string. Has to be fixed upstream
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function refuel(?ammount:Int):Outcome<Noise, String> {
|
public static function refuel(?ammount:Int):Outcome<Noise, String> {
|
||||||
var r = cc.Turtle.refuel(ammount);
|
var r = cc.Turtle.refuel(ammount);
|
||||||
return conterToOutcome(r);
|
return conterToOutcome(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canRefultWithSlot():Bool {
|
public static function canRefultWithSlot():Bool {
|
||||||
var r = cc.Turtle.refuel(0);
|
var r = cc.Turtle.refuel(0);
|
||||||
return r.successful;
|
return r.successful;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compareSlot(otherSlot:TurtleSlot):Bool {
|
public static function compareSlot(otherSlot:TurtleSlot):Bool {
|
||||||
return cc.Turtle.compareTo(otherSlot + 1);
|
return cc.Turtle.compareTo(otherSlot.toCCSlot());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transfer(from:TurtleSlot, to:TurtleSlot, ?count:Int):Outcome<Noise, Noise> {
|
public static function transfer(from:TurtleSlot, to:TurtleSlot, ?count:Int):Outcome<Noise, Noise> {
|
||||||
this.selectSlot(from);
|
selectSlot(from);
|
||||||
var r = cc.Turtle.transferTo(to + 1, count);
|
var r = cc.Turtle.transferTo(to.toCCSlot(), count);
|
||||||
return r ? Outcome.Success(null) : Outcome.Failure(null);
|
return r ? Outcome.Success(null) : Outcome.Failure(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSelectedSlot():TurtleSlot {
|
public static function getSelectedSlot():TurtleSlot {
|
||||||
return cc.Turtle.getSelectedSlot() - 1;
|
return cc.Turtle.getSelectedSlot() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFuelLimit():Int {
|
public static function getFuelLimit():Int {
|
||||||
return cc.Turtle.getFuelLimit(); // FIXME: can be a string. Has to be fixed upstream
|
return cc.Turtle.getFuelLimit(); // FIXME: can be a string. Has to be fixed upstream
|
||||||
}
|
}
|
||||||
|
|
||||||
public function equip(side:ToolSide):Outcome<Noise, String> {
|
public static function equip(side:ToolSide):Outcome<Noise, String> {
|
||||||
switch side {
|
switch side {
|
||||||
case Left:
|
case Left:
|
||||||
return conterToOutcome(cc.Turtle.equipLeft());
|
return conterToOutcome(cc.Turtle.equipLeft());
|
||||||
@@ -237,7 +263,7 @@ class Turtle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function inspect(dir:InteractDirections):Outcome<BlockInspect, String> {
|
public static function inspect(dir:InteractDirections):Outcome<BlockInspect, String> {
|
||||||
var r:cc.Turtle.TurtleInspectResult;
|
var r:cc.Turtle.TurtleInspectResult;
|
||||||
switch dir {
|
switch dir {
|
||||||
case Front:
|
case Front:
|
||||||
@@ -260,8 +286,8 @@ class Turtle {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getItemDetail(?detailed:Bool = false, ?slot:TurtleSlot):Option<ItemInspect> {
|
public static function getItemDetail(slot:TurtleSlot, ?detailed:Bool = false):Option<ItemInspect> {
|
||||||
var r = cc.Turtle.getItemDetail(slot + 1); // FIXME: can take detailed as flag. Has to be fixed upstream
|
var r = cc.Turtle.getItemDetail(slot.toCCSlot()); // FIXME: can take detailed as flag. Has to be fixed upstream
|
||||||
|
|
||||||
if (r == null) {
|
if (r == null) {
|
||||||
return None;
|
return None;
|
||||||
@@ -275,7 +301,7 @@ class Turtle {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function craft(?limit:Int = 64):Outcome<Noise, String> {
|
public static function craft(?limit:Int = 64):Outcome<Noise, String> {
|
||||||
if (limit < 1 || limit > 64) {
|
if (limit < 1 || limit > 64) {
|
||||||
return Outcome.Failure("Crafting limit out of bounds");
|
return Outcome.Failure("Crafting limit out of bounds");
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/kernel/turtle/TurtleMutex.hx
Normal file
52
src/kernel/turtle/TurtleMutex.hx
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package kernel.turtle;
|
||||||
|
|
||||||
|
import kernel.log.Log;
|
||||||
|
import cc.OS;
|
||||||
|
import kernel.ps.ProcessManager.PID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Make sure only one process can access the turtle at a time.
|
||||||
|
**/
|
||||||
|
class TurtleMutex {
|
||||||
|
private static var claimedPid:PID = -1;
|
||||||
|
public static var threadFunc:() -> Void;
|
||||||
|
|
||||||
|
@:allow(kernel.ps.ProcessHandle)
|
||||||
|
private static function claim(pid:PID):Bool {
|
||||||
|
if (claimedPid == -1) {
|
||||||
|
claimedPid = pid;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:allow(kernel.ps.ProcessHandle)
|
||||||
|
private static function release(pid:PID) {
|
||||||
|
if (claimedPid == pid) {
|
||||||
|
claimedPid = -1;
|
||||||
|
stopTurtleThread();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:allow(kernel.KernelEvents)
|
||||||
|
private static function runThreadFunc() {
|
||||||
|
if (threadFunc != null) {
|
||||||
|
try {
|
||||||
|
threadFunc();
|
||||||
|
} catch (e) {
|
||||||
|
Log.error("Error in tthread: " + e);
|
||||||
|
}
|
||||||
|
threadFunc = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function runInTThread(func:() -> Void) {
|
||||||
|
threadFunc = func;
|
||||||
|
OS.queueEvent("tthread");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function stopTurtleThread() {
|
||||||
|
threadFunc = null;
|
||||||
|
KernelEvents.startTurtleCoroutine();
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/kernel/turtle/TurtleSlot.hx
Normal file
26
src/kernel/turtle/TurtleSlot.hx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package kernel.turtle;
|
||||||
|
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The slot nummber for turtle inventory. 0 based. Assured to be in range.
|
||||||
|
**/
|
||||||
|
abstract TurtleSlot(Int) to Int {
|
||||||
|
public function new(i:Int) {
|
||||||
|
if (i >= 0 && i < Turtle.MAX_SLOTS) {
|
||||||
|
this = i;
|
||||||
|
} else {
|
||||||
|
throw new Error("Slot not in range: " + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:from
|
||||||
|
public static function fromInt(i:Int) {
|
||||||
|
return new TurtleSlot(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@:allow(kernel.turtle)
|
||||||
|
private inline function toCCSlot():Int {
|
||||||
|
return this + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,5 +22,3 @@ typedef ItemInspect = {
|
|||||||
public var damage:Int;
|
public var damage:Int;
|
||||||
public var count:Int;
|
public var count:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TurtleSlot = Int;
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user