This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tis
127 lines (115 loc) · 3.16 KB
/
main.tis
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const DEBUGGING = false;
DEBUGGING && view.connectToInspector && view.connectToInspector(rootElement, inspectorIpAddress);
event change $(#size) {
const n = this.value.toInteger();
$(#size-percentage).text = String.$({n}%);
$(#crosshair).style.set {
foreground-size: String.$({n}%)
};
}
event change $(#opacity) {
const n = this.value;
$(#opacity-percentage).text = String.$({n}%);
$(#crosshair).style.set {
opacity: n.toFloat() / 100;
};
}
function loadImages() {
const folders = [];
const filter = "crosshairs/**";
const result = System.scanFiles(filter, function(folder, attributes) {
if (folder == "." || folder == "..") return true;
if((attributes & System.IS_DIR) != 0) {
folders.push(folder);
return true;
}
});
const filenames = [];
for (var folder in folders) {
System.scanFiles(String.$(crosshairs/{folder}/**), function(filename, attributes) {
if (filename == "." || filename == "..") return true;
filenames.push(String.$(crosshairs/{folder}/{filename}));
return true;
});
}
view.files = {};
for (var filename in filenames) {
const folder = filename.slice(0, filename.lastIndexOf("/")).replace("crosshairs/", "");
if (view.files[folder] == undefined) view.files[folder] = [];
view.files[folder].push(filename);
}
}
loadImages();
view.savedHtml = false;
$(a) << event click {
const popup = view.dialog({
caption: "Choose A Crosshair",
url: self.url("crosshairs.htm"),
parameters: {
files: view.files,
html: view.savedHtml || false;
callbacks: {
changeCrosshair: function(src) {
$(#crosshair).attributes["src"] = src;
},
saveHtml: function(html) {
view.savedHtml = html;
}
}
}
});
}
var sight = "bullet";
var sightColor = color(255, 0, 0);
event click $(button[name=sight]) (evt) {
sight = $$(button[name=sight]).find(button => button.checked).attributes["value"];
$(#crosshair).update();
}
$(#crosshair).paintForeground = function(gfx) {
if (sight == "off") return;
if (sight == "bullet") {
const r = $(#size).value.toFloat() / 50.0;
for (let i = 0; i < 2; i++) {
gfx
.fillColor(sightColor)
.ellipse(50.0, 50.0, r);
}
} else if (sight == "plus") {
const l = $(#size).value.toFloat() / 10.0;
for (let i = 0; i < 2; i++) {
gfx
.strokeColor(sightColor)
.strokeWidth(1.0)
.line(50.0, 50.0 - l, 50.0, 50.0 + l)
.line(50.0 - l, 50.0, 50.0 + l, 50.0);
}
}
}
$(#color-picker) << event click {
const popup = view.window({
type: View.TOOL_WINDOW,
caption: "Pick A Color",
url: self.url("palette.htm"),
parameters: {
callbacks: {
changeColor: function(color) {
sightColor = color;
$(#crosshair).update();
$(#color-picker).style.set {
background-color: sightColor;
}
}
}
}
});
}
function keyCodeName(code) {
for(var (name,val) in Event)
if(val === code)
return name;
return "?";
}
event keyup (evt) {
if( evt.shortcutKey )
debug shortcut: evt.keyCode, keyCodeName(evt.keyCode);
}