Skip to content

Commit f2d3568

Browse files
committed
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core into gh-pages
2 parents bc843ff + 574d13f commit f2d3568

File tree

73 files changed

+3626
-380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3626
-380
lines changed

demos/leo/dice_roller.js

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
export default class DiceRoller {
2+
3+
onMouseDownOverAmount(evt, currentAmount) {
4+
evt.preventDefault();
5+
evt.stopPropagation();
6+
7+
// reset
8+
var all = currentAmount.parentElement.parentElement.parentElement.querySelectorAll("div[name='value']")
9+
all.forEach(e => e.style.border = "1px lightgray solid")
10+
// mark and save new
11+
currentAmount.style.border = "1px black solid";
12+
this.amount = currentAmount;
13+
}
14+
15+
onMouseOverType(evt, currentType) {
16+
evt.preventDefault();
17+
evt.stopPropagation();
18+
19+
if (this.amount) {
20+
// reset
21+
var all = currentType.parentElement.parentElement.parentElement.querySelectorAll("div[name='value']")
22+
all.forEach(e => e.style.border = "1px lightgray solid")
23+
// mark and save new
24+
currentType.style.border = "1px black solid";
25+
this.type = currentType;
26+
}
27+
}
28+
29+
onMouseOverBonus(evt, currentBonus) {
30+
evt.preventDefault();
31+
evt.stopPropagation();
32+
33+
if (this.amount) {
34+
// reset
35+
var all = currentBonus.parentElement.parentElement.parentElement.querySelectorAll("div[name='value']")
36+
all.forEach(e => e.style.border = "1px lightgray solid")
37+
// mark and save new
38+
currentBonus.style.border = "1px black solid";
39+
this.bonus = currentBonus;
40+
}
41+
}
42+
43+
onMouseUp(evt) {
44+
if (this.amount && this.type) {
45+
var output = this.amount.value + this.type.value
46+
if (this.bonus){
47+
output = output + this.bonus.value
48+
}
49+
this.output.value = output;
50+
}
51+
[this.amount, this.type, this.bonus].forEach(e => {
52+
if (e) e.style.border = "1px lightgray solid";
53+
})
54+
this.amount = undefined;
55+
this.type = undefined;
56+
this.bonus = undefined;
57+
}
58+
59+
create() {
60+
61+
// amount
62+
var table = <table style="width:100%"></table>
63+
var amount = <div style="padding:5px">
64+
<div style="border: 1px solid black; margin:auto">
65+
{table}
66+
</div>
67+
</div>
68+
69+
for (var i = 1; i <= 4; i++) {
70+
var value = <div name="value" style="width:max; text-align:center; background-color: lightgray; border: 1px lightgray solid; cursor: grab">{i}</div>
71+
value.value = i;
72+
var del = <div style="width:max; text-align:right; cursor: pointer">X</div>;
73+
74+
const currentAmount = value
75+
value.addEventListener('mousedown', (evt) => this.onMouseDownOverAmount(evt, currentAmount));
76+
77+
var cell =
78+
<tr>
79+
<td style="width: 33%"></td>
80+
<td style="width: 33%">{value}</td>
81+
<td style="width: 33%">{del}</td>
82+
</tr>
83+
table.appendChild(cell)
84+
}
85+
86+
87+
// type
88+
var typeTable = <table style="width:100%"></table>;
89+
var type = <div style="padding:5px">
90+
<div style="border: 1px solid black; margin:auto">
91+
{typeTable}
92+
</div>
93+
</div>;
94+
95+
["d4", "d6", "d8", "d10", "d12", "d20"].forEach(e => {
96+
var value = <div name="value" style="width:max; text-align:center; background-color: lightgray; border: 1px lightgray solid; cursor: grab">{e}</div>
97+
value.value = e;
98+
var del = <div style="width:max; text-align:right; cursor: pointer">X</div>;
99+
100+
const currentType = value
101+
102+
value.addEventListener('mouseover', (evt) => this.onMouseOverType(evt, currentType));
103+
104+
var cell =
105+
<tr>
106+
<td style="width: 33%"></td>
107+
<td style="width: 33%">{value}</td>
108+
<td style="width: 33%">{del}</td>
109+
</tr>
110+
typeTable.appendChild(cell)
111+
})
112+
113+
114+
// bonus
115+
var bonusTable = <table style="width:100%"></table>;
116+
var bonus = <div style="padding:5px">
117+
<div style="border: 1px solid black; margin:auto">
118+
{bonusTable}
119+
</div>
120+
</div>;
121+
122+
["-1", "0", "+1", "+2", "+3", "+4"].forEach(e => {
123+
var value = <div name="value" style="width:max; text-align:center; background-color: lightgray; border: 1px lightgray solid; cursor: grab">{e}</div>
124+
value.value = e;
125+
var del = <div style="width:max; text-align:right; cursor: pointer">X</div>;
126+
127+
const currentBonus = value
128+
129+
value.addEventListener('mouseover', (evt) => this.onMouseOverBonus(evt, currentBonus));
130+
131+
var cell =
132+
<tr>
133+
<td style="width: 33%"></td>
134+
<td style="width: 33%">{value}</td>
135+
<td style="width: 33%">{del}</td>
136+
</tr>
137+
bonusTable.appendChild(cell)
138+
})
139+
140+
this.output = <input></input>
141+
142+
var roller =
143+
<table style="width:100%, height:100%; border: 1px lightgray solid">
144+
<tr>
145+
<th style="width:33%">Amount</th>
146+
<th style="width:33%">Type</th>
147+
<th style="width:33%">Bonus</th>
148+
</tr>
149+
<tr>
150+
<td>{amount}</td>
151+
<td>{type}</td>
152+
<td>{bonus}</td>
153+
</tr>
154+
<tr>
155+
{this.output}
156+
</tr>
157+
</table>
158+
roller.addEventListener('mouseleave', (evt) => this.onMouseUp(evt));
159+
roller.addEventListener('mouseup', (evt) => this.onMouseUp(evt));
160+
161+
return roller
162+
}
163+
}

demos/leo/dice_roller.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Dice Roller
2+
3+
<script>
4+
import DiceRoller from "./dice_roller.js";
5+
6+
var d = new DiceRoller();
7+
8+
d.create();
9+
</script>

demos/tom/TraceLogParser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ export default class TraceLogParser {
181181

182182
parsePlugin(sections) {
183183
const plugin = new PluginSection(...this.consume().data);
184+
plugin.position = this.peek().position;
185+
184186
sections.push(plugin);
185187
this.defaultParse(plugin, []);
186188
return plugin;

demos/tom/babel-plugin-tracer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Trace from 'demos/tom/trace.js';
22
import wrapAST from 'demos/tom/wrapAST.js';
33

4+
'hello world'
5+
46
let pluginDefinedTrace = false;
57

68
export default function({ types: t }) {

demos/tom/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ Es ist möglich das trace plugin mit sich selbst zu debuggen. Dazu wird einfach
8383
* Diff was ist dazu gekommen; was wurde entfernt während des changes
8484
* AST-compare sollte direkt die Änderung aufgeklappt haben (cool: farblich markieren)
8585
* Im Plugin code markieren und anzeigen welche konkreten Traces darüber gelaufen sind
86+
* "brushing and linking"
87+
- **whence** and **whither** === wohin und woher
88+
- **What if** === Was wäre, wenn
8689

8790
## Known problems
8891
* Wenn zu viele Daten generiert werden (weil entweder das plugin oder der gegebene Code zu viel sind) ist der Worker nicht mehr in der Lage dazu die Daten zu senden, was darin endet, dass das TraceVisualization Tool nicht mehr funktioniert. Dies liegt anscheinend daran, dass während eines Aufrufs von JSON.stringify der Fehler: _rangeerror invalid string length_ geworfen wird

demos/tom/plugin-explorer-worker.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function decorateNodePathTraverse(plugin, trace) {
8484
} else if (typeof visitors[name] === 'object') {
8585
const obj = visitors[name];
8686

87+
// Todo: what is if already decorated
8788
if(obj.enter) {
8889
obj.enter = obj.enter.map(fn => function(path, ...rest) {
8990
trace.startTraversePlugin(name, path.node.traceID);
@@ -133,8 +134,8 @@ async function importPlugin(url) {
133134
return modifiedPlugin;
134135
}
135136

136-
function importPlugins(urls) {
137-
return Promise.all(urls.map(url => importPlugin(url)))
137+
function importPlugins(pluginData) {
138+
return Promise.all(pluginData.map(({url, data}) => importPlugin(url)))
138139
.then(plugins => {
139140
let counter = 0;
140141
for (const plugin of plugins) {
@@ -179,7 +180,7 @@ self.onmessage = function(msg) {
179180
return trace.createTraceID();
180181
}
181182

182-
importPlugins(msg.data.urls)
183+
importPlugins(msg.data.pluginData)
183184
.then(function(modules) {
184185
config.plugins = modules;
185186
config.sourceFileName = 'tmpfile.js';

demos/tom/plugin-load-promise.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function(source, urls) {
1+
export default function(source, pluginData) {
22
return new Promise((resolve, reject) => {
33
const worker = new Worker('demos/tom/plugin-explorer-worker.js')
44
worker.onmessage = function(msg) {
@@ -9,6 +9,6 @@ export default function(source, urls) {
99
reject(msg);
1010
worker.terminate();
1111
}
12-
worker.postMessage({source, urls})
12+
worker.postMessage({source, pluginData})
1313
})
1414
}

demos/tom/trace.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export default class Trace {
6767
return trace;
6868
}
6969

70-
static async on(source, pluginsUrls) {
71-
const data = await loadPlugin(source, pluginsUrls);
70+
static async on(source, pluginData) {
71+
const data = await loadPlugin(source, pluginData);
7272
const obj = {
7373
locations: data.locations,
7474
oldAST: JSON.parse(data.oldAST),
822 KB
Loading

0 commit comments

Comments
 (0)