/
item.js
57 lines (56 loc) · 1.63 KB
/
item.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
(function (app) {
let sep=/\|\|/
let item=Include("include/item.js")
app.Info.Items=[]
app.Info.BuiltinItems=[]
app.RegisterCallback("info.items.loaditems", function () {
app.Info.BuiltinItems= world.ReadLines("info/data/items.txt")
app.Info.BuiltinItems.forEach(function(line){
let i= new item()
var data=line.split(sep)
i.ID=data[0]
i.Name=data[1]
i.Label=data[2]
i.Type=data[3]
i.Location=data[4]
i.Command=data[5]
i.Interval=data[6]?data[6]-0:0
i.Comment=data[7]
app.Info.Items.push(i)
})
})
app.RegisterAPI("GetItem", function (id) {
for (var key in app.Info.Items){
if (app.Info.Items[key].ID==id){
return app.Info.Items[key]
}
}
return null
})
app.RegisterAPI("GetItemsByName", function (name,ignorecase) {
let result=[]
if (ignorecase){
name=name.toLowerCase()
}
app.Info.Items.forEach(function(data){
let itemname=data.Name
if (ignorecase){
itemname=itemname.toLowerCase()
}
if (itemname===name){
result.push(data)
}
})
return result
})
app.RegisterAPI("GetItemsByLabel", function (label) {
let result=[]
app.Info.Items.forEach(function(data){
if (data.Label===label){
result.push(data)
}
})
return result
})
app.Bind("Ready", "info.items.loaditems")
})(App)