Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.

Commit b71dc9d

Browse files
committed
commit
1 parent 41a095d commit b71dc9d

23 files changed

+131
-206
lines changed

math/assert.js

Lines changed: 5 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,14 @@
11
'use strict';
22

3-
const assert = require('assert');
43
const O = require('../omikron');
54
const util = require('./util');
65
const su = require('./str-util');
76

8-
class Base{
9-
static *deser(ser){ O.virtual('deser', 1); }
7+
const assert = b => {
8+
if(b) return;
109

11-
*ser(ser){ O.virtual('ser'); }
12-
}
13-
14-
const serMixed = function*(ser, val){
15-
if(typeof val === 'number'){
16-
ser.write(0, 3);
17-
ser.writeInt(val);
18-
19-
switch(a){
20-
case 1:
21-
22-
}
23-
24-
// [a-z]+\\([^\\n]*?\\)$
25-
26-
return;
27-
}
28-
29-
if(typeof val === 'string'){
30-
ser.write(1, 3);
31-
ser.writeStr(val);
32-
return;
33-
}
34-
35-
if(O.isArr(val)){
36-
ser.write(2, 3);
37-
ser.writeInt(val.length);
38-
39-
for(const elem of val)
40-
yield [serMixed, ser, elem];
41-
42-
return;
43-
}
44-
45-
assert(typeof val === 'object');
46-
ser.write(3, 3);
47-
48-
if(val === null){
49-
ser.write(0);
50-
return;
51-
}
52-
53-
ser.write(1);
54-
55-
if(O.proto(val) === null){
56-
ser.write(0);
57-
58-
const keys = O.keys(val);
59-
60-
ser.writeInt(keys.length);
61-
62-
for(const key of keys){
63-
// assert(typeof key === 'string');
64-
ser.writeStr(key);
65-
yield [serMixed, ser, val[key]];
66-
}
67-
68-
return;
69-
}
70-
71-
ser.write(1);
72-
73-
// assert(val instanceof Base);
74-
return O.tco([val, 'ser'], ser);
75-
};
76-
77-
const deserMixed = function*(ser, ctor){
78-
const type = Number(ser.read(3));
79-
80-
if(type === 0)
81-
return Number(ser.readInt());
82-
83-
if(type === 1)
84-
return ser.readStr();
85-
86-
if(type === 2){
87-
const len = Number(ser.readInt());
88-
const arr = [];
89-
90-
for(let i = 0; i !== len; i++)
91-
arr.push(yield [deserMixed, ser, ctor]);
92-
93-
return arr;
94-
}
95-
96-
if(!ser.read())
97-
return null;
98-
99-
if(!ser.read()){
100-
const size = Number(ser.readInt());
101-
const obj = O.obj();
102-
103-
for(let i = 0; i !== size; i++){
104-
const key = ser.readStr();
105-
obj[key] = yield [deserMixed, ser, ctor];
106-
}
107-
108-
return obj;
109-
}
110-
111-
return O.tco([ctor, 'deser'], ser);
10+
debugger;
11+
throw new Error('Assertion failed');
11212
};
11313

114-
module.exports = Object.assign(Base, {
115-
serMixed,
116-
deserMixed,
117-
});
14+
module.exports = Object.assign(assert, {});

math/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const assert = require('assert');
3+
const assert = require('./assert');
44
const O = require('../omikron');
55
const util = require('./util');
66
const su = require('./str-util');

math/config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const fs = require('fs');
44
const path = require('path');
5-
const assert = require('assert');
5+
const assert = require('./assert');
66
const O = require('../omikron');
77
const util = require('./util');
88
const su = require('./str-util');
@@ -13,6 +13,11 @@ const thExt = ext;
1313
const indexFileName = 'index'
1414
const rootDirName = 'logic';
1515
const thPrefix = 'th-';
16+
const ws = 12;
17+
const hs = 25;
18+
const ofs = 15;
19+
const tabW = ws * 20;
20+
const tabH = hs;
1621

1722
const cwd = __dirname;
1823
const rootDir = path.join(cwd, 'logic');
@@ -25,6 +30,11 @@ const config = {
2530
indexFile,
2631
rootDir,
2732
thPrefix,
33+
ws,
34+
hs,
35+
ofs,
36+
tabW,
37+
tabH,
2838
};
2939

3040
module.exports = config;

math/context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const assert = require('assert');
3+
const assert = require('./assert');
44
const O = require('../omikron');
55
const Base = require('./base');
66
const util = require('./util');

math/display.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22

33
const fs = require('fs');
44
const path = require('path');
5-
const assert = require('assert');
5+
const assert = require('./assert');
66
const O = require('../omikron');
77
const System = require('./system');
88
const Tab = require('./tab');
99
const EventTarget = require('./event-target');
10+
const config = require('./config');
1011
const util = require('./util');
1112
const su = require('./str-util');
1213

1314
const {TheoryTab} = Tab;
15+
const {ws, hs, ofs, tabW, tabH} = config;
1416

1517
class Display extends EventTarget{
1618
tabs = [];
1719
curTabIndex = null;
1820

19-
ws = null;
20-
hs = null;
21-
ofs = null;
22-
2321
constructor(system){
2422
super();
2523
this.system = system;
@@ -33,10 +31,7 @@ class Display extends EventTarget{
3331
}
3432

3533
render(g, iw, ih, w, h){
36-
const {tabs, tabsNum, ws, hs, ofs} = this;
37-
38-
const tabW = ws * 20;
39-
const tabH = hs;
34+
const {tabs, tabsNum} = this;
4035

4136
const iwh = iw / 2;
4237
const ihh = ih / 2;
@@ -53,7 +48,7 @@ class Display extends EventTarget{
5348
const x = tabW * i;
5449
const y = 0;
5550

56-
tabs[i].render(g, ofs, x, y, iw, ih, tabW, tabH, ws, hs);
51+
tabs[i].render(g, ofs, x, y, iw, ih, tabW, tabH);
5752
}
5853
}
5954

math/editor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const assert = require('assert');
3+
const assert = require('./assert');
44
const O = require('../omikron');
55
const EventTarget = require('./event-target');
66
const specialChars = require('./special-chars');
@@ -105,7 +105,7 @@ class Editor extends EventTarget{
105105
return;
106106
}
107107

108-
if(flags === 4 || flags === 1){
108+
if(flags === 4 || flags === 5){
109109
if(code === 'ArrowUp'){
110110
this.scrollUp(altKey);
111111
return;

math/equation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const assert = require('assert');
3+
const assert = require('./assert');
44
const O = require('../omikron');
55
const util = require('./util');
66

math/event-target.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const assert = require('assert');
3+
const assert = require('./assert');
44
const O = require('../omikron');
55
const Base = require('./base');
66
const util = require('./util');

math/expr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const assert = require('assert');
3+
const assert = require('./assert');
44
const O = require('../omikron');
55
const Base = require('./base');
66
const util = require('./util');

math/line-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const assert = require('assert');
3+
const assert = require('./assert');
44
const O = require('../omikron');
55
const util = require('./util');
66
const su = require('./str-util');

0 commit comments

Comments
 (0)