forked from aatukaj/tetpeli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskulpt.js
68 lines (62 loc) · 1.83 KB
/
skulpt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function outf(text) {
addCmd(text.replace("\n", ""))
console.log(text)
}
function builtinRead(x) {
if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
throw "File not found: '" + x + "'";
return Sk.builtinFiles["files"][x];
}
function runit() {
/*let lines = editor.getValue().split("\n").length
if (lines > 10) {
alert("Koodi on liian pitkä!")
return
}*/
var prog = `
class _Entity:
def __init__(self, x, y, sprite):
self.x=x
self.y=y
self.id=str(id(self))
print(f"addEntity:{self.id},{x},{y},{sprite}")
def move(self, dir):
print(f"move:{self.id},{dir}")
def say(self, text):
print(f"say:{self.id},{text}")
def liiku(self, dir):
if dir == "ylös": dir = "up"
if dir == "alas": dir = "down"
if dir == "vasen": dir = "left"
if dir == "oikea": dir = "right"
print(f"move:{self.id},{dir}")
class Bunny(_Entity):
def __init__(self, x, y):
super().__init__(x, y, "bunny")
class Cat(_Entity):
def __init__(self, x, y):
super().__init__(x, y, "cat")
class Pupu(_Entity):
def __init__(self):
super().__init__(0, 0, "bunny")
pallero = Pupu()\n` + editor.getValue();
Sk.configure({
output: outf,
read: builtinRead,
execLimit: 5000,
});
var myPromise = Sk.misceval.asyncToPromise(function () {
return Sk.importMainWithBody("<stdin>", false, prog, true);
});
myPromise.then(function (mod) {
console.log('success');
},
function (err) {
let offset = 29
let parts = err.toString().split(" ")
let count = parts.length
parts[count-1] -= offset
alert(parts.join(" "));
console.log(err.toString());
});
}