This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathWrite.js
64 lines (52 loc) · 1.8 KB
/
Write.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
let Write = {}
Write.keyValue = function(id, value) {
document.getElementById(id).value = value;
}
Write.string = Write.keyValue;
Write.number = Write.keyValue;
Write.select = Write.keyValue;
Write.pair = function(id, objects) { // objects : [{name, value}]
objects.forEach((object) => {
Write.keyValue(id + '-' + object.name, object.value);
});
}
Write.pairList = function(id, values, attributes) { // values [[{name,value},{name, value}]]
values.forEach((object) => {
var index = Draw.pairInList(id, attributes);
var set = []
attributes.forEach((attribute) => {
let obj = {}
obj.name = attribute.value;
obj.value = object[attribute.value];
set.push(obj);
})
Write.pair(id + '-' + index, set);
})
}
Write.addablePairList = Write.pairList;
Write.attributeSet = function(id, values, attributes) {
attributes.forEach((attribute) => {
if (values[attribute[0]] != null) Write[attribute[2]](id + '-' + attribute[0], values[attribute[0]], attribute[3]);
})
}
Write.object = function(id, object, attributes) {
/*var result = {};
object.forEach((attribute) => {
Draw[attribute[2]](id + '-' + attribute[0], attribute[1], attribute[3], location);
})*/
return Write.attributeSet(id, object, attributes);
}
Write.imageInputGroup = function(id, name, folder) {
let files = folder.file(new RegExp(name));
files.forEach((file) => {
if (!file.dir) {
var type = file.name.split(name)[1].replace('.png', '').replace('-', '');
if (type == '') type = 'icon';
file.async('base64').then((img) => {
var html = document.getElementById(id + '-images-' + type);
if (html) html.setAttribute('src', 'data:image/png;base64,' + img);
else alert('Found unknown image type ' + type + ' when loading ' + name);
});
}
})
}