-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreload.js
More file actions
173 lines (156 loc) · 7.54 KB
/
preload.js
File metadata and controls
173 lines (156 loc) · 7.54 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
var projectileSprites = {}
var skinSprites = {}
var accessSprites = {}
var toolSprites = {}
var aiSprites = {}
var iconSprites = {}
async function preload() {
for (const id in HATS) {
const tmpElement = document.createElement("div")
tmpElement.className = "selectHat"
tmpElement.setAttribute("name", id)
tmpElement.style.backgroundImage = `url(https://moomoo.io/img/hats/hat_${id}${HATS[id].topSprite ? "_p" : ""}.png)`
document.getElementById("hatsContainer").appendChild(tmpElement)
tmpElement.setAttribute("onclick", "selectHat(this)")
const tmpElement2 = document.createElement("div")
tmpElement2.className = "selectHat"
tmpElement2.setAttribute("name", id)
tmpElement2.style.backgroundImage = `url(https://moomoo.io/img/hats/hat_${id}${HATS[id].topSprite ? "_p" : ""}.png)`
document.getElementById("playerHatsContainer").appendChild(tmpElement2)
tmpElement2.setAttribute("onclick", "selectHat(this)")
}
for (const id in ACCESSORIES) {
const tmpElement = document.createElement("div")
tmpElement.className = "selectAccess"
tmpElement.setAttribute("name", id)
tmpElement.style.backgroundImage = `url(https://moomoo.io/img/accessories/access_${id}.png)`
document.getElementById("accessContainer").appendChild(tmpElement)
tmpElement.setAttribute("onclick", "selectAccess(this)")
const tmpElement2 = document.createElement("div")
tmpElement2.className = "selectAccess"
tmpElement2.setAttribute("name", id)
tmpElement2.style.backgroundImage = `url(https://moomoo.io/img/accessories/access_${id}.png)`
document.getElementById("playerAccessContainer").appendChild(tmpElement2)
tmpElement2.setAttribute("onclick", "selectAccess(this)")
}
for (const name in ANIMALS) {
const tmpElement = document.createElement("div")
tmpElement.className = "selectAnimal"
tmpElement.setAttribute("name", name)
tmpElement.style.backgroundImage = `url(https://moomoo.io/img/animals/${name}.png)`
document.getElementById("animalsContainer").appendChild(tmpElement)
tmpElement.setAttribute("onclick", "selectAnimal(this)")
}
for (const name in PROJECTILES) {
var url = `https://moomoo.io/img/weapons/${name}.png`
if (name === "turret") {
const tmpCanvas = document.createElement("canvas")
tmpCanvas.width = tmpCanvas.height = 100
scaleFillNative = 1
const tmpContext = tmpCanvas.getContext("2d")
tmpContext.translate(tmpCanvas.width / 2, tmpCanvas.height / 2)
tmpContext.strokeStyle = outlineColor
tmpContext.lineWidth = outlineWidth
tmpContext.fillStyle = "#939393"
renderCircle(0, 0, PROJECTILES[name].scale, tmpContext)
url = tmpCanvas.toDataURL()
}
const tmpElement = document.createElement("div")
tmpElement.className = "selectProjectile"
tmpElement.setAttribute("name", name)
tmpElement.style.backgroundImage = `url(${url})`
document.getElementById("projectilesContainer").appendChild(tmpElement)
tmpElement.setAttribute("onclick", "selectProjectile(this)")
if (name !== "turret" && name !== "bullet_1") {
const tmpElement2 = document.createElement("div")
tmpElement2.className = "selectProjectile"
tmpElement2.setAttribute("name", name)
tmpElement2.style.backgroundImage = `url(${url})`
document.getElementById("playerProjectilesContainer").appendChild(tmpElement2)
tmpElement2.setAttribute("onclick", "selectProjectile(this)")
}
}
const variants = ["", "_g", "_d", "_r"]
for (const name in WEAPONS) {
for (let i = 0; i < 4; i++) {
const variant = variants[i]
const tmpElement = document.createElement("div")
tmpElement.className = "selectWeapon"
tmpElement.setAttribute("name", name)
tmpElement.setAttribute("variant", variant)
tmpElement.style.backgroundImage = `url(${WEAPONS[name].src === "bow_1" && variant === "_d" ? "" : "https://moomoo.io/"}img/weapons/${
WEAPONS[name].src + variant
}.png)`
document.getElementById("weaponsContainer").appendChild(tmpElement)
tmpElement.setAttribute("onclick", "selectWeapon(this)")
const tmpElement2 = document.createElement("div")
tmpElement2.className = "selectWeapon"
tmpElement2.setAttribute("name", name)
tmpElement2.setAttribute("variant", variant)
tmpElement2.style.backgroundImage = `url(${WEAPONS[name].src === "bow_1" && variant === "_d" ? "" : "https://moomoo.io/"}img/weapons/${
WEAPONS[name].src + variant
}.png)`
document.getElementById("playerWeaponsContainer").appendChild(tmpElement2)
tmpElement2.setAttribute("onclick", "selectWeapon(this)")
}
}
for (const name in ITEMS) {
const tmpCanvas = document.createElement("canvas")
tmpCanvas.width = tmpCanvas.height = 100
const tmpContext = tmpCanvas.getContext("2d")
tmpContext.translate(tmpCanvas.width / 2, tmpCanvas.height / 2)
tmpContext.imageSmoothingEnabled = false
tmpContext.webkitImageSmoothingEnabled = false
tmpContext.mozImageSmoothingEnabled = false
const tmpSprite = getItemSprite(name, false, true)
const tmpScale = Math.min(tmpCanvas.width - 15, tmpSprite.width)
tmpContext.globalAlpha = name == "invisiblepittrap" ? 0.6 : 1
tmpContext.drawImage(tmpSprite, -tmpScale / 2, -tmpScale / 2, tmpScale, tmpScale)
tmpContext.fillStyle = "rgba(0, 0, 70, 0.1)"
tmpContext.globalCompositeOperation = "source-atop"
tmpContext.fillRect(-tmpScale / 2, -tmpScale / 2, tmpScale, tmpScale)
const tmpElement = document.createElement("div")
tmpElement.className = "selectBuilding"
tmpElement.setAttribute("name", name)
tmpElement.style.backgroundImage = `url(${tmpCanvas.toDataURL()})`
document.getElementById("buildingsContainer").appendChild(tmpElement)
tmpElement.setAttribute("onclick", "selectBuidling(this)")
if (name !== "invisiblepittrap" && name !== "blockerwithcircle") {
const tmpElement2 = document.createElement("div")
tmpElement2.className = "selectWeapon"
tmpElement2.setAttribute("build", name)
tmpElement2.style.backgroundImage = `url(${tmpCanvas.toDataURL()})`
document.getElementById("playerWeaponsContainer").appendChild(tmpElement2)
tmpElement2.setAttribute("onclick", "selectWeapon(this)")
}
}
for (const name in RESOURCES) {
const res = RESOURCES[name]
res.forEach((biome) => {
const tmpCanvas = document.createElement("canvas")
tmpCanvas.width = tmpCanvas.height = 100
const tmpContext = tmpCanvas.getContext("2d")
tmpContext.translate(tmpCanvas.width / 2, tmpCanvas.height / 2)
tmpContext.imageSmoothingEnabled = false
tmpContext.webkitImageSmoothingEnabled = false
tmpContext.mozImageSmoothingEnabled = false
const tmpSprite = getResSprite(name, name == "rock" || name == "gold" || name == "bush" ? 80 : name == "volcano" ? 170 : 150, biome, true)
const tmpScale = Math.min(tmpCanvas.width - 15, tmpSprite.width)
tmpContext.globalAlpha = 1
tmpContext.drawImage(tmpSprite, -tmpScale / 2, -tmpScale / 2, tmpScale, tmpScale)
tmpContext.fillStyle = "rgba(0, 0, 70, 0.1)"
tmpContext.globalCompositeOperation = "source-atop"
tmpContext.fillRect(-tmpScale / 2, -tmpScale / 2, tmpScale, tmpScale)
const tmpElement = document.createElement("div")
tmpElement.className = "selectResource"
tmpElement.setAttribute("name", name)
tmpElement.setAttribute("biome", biome)
tmpElement.style.backgroundImage = `url(${tmpCanvas.toDataURL()})`
document.getElementById("resourcesContainer").appendChild(tmpElement)
tmpElement.setAttribute("onclick", "selectResource(this)")
})
}
document.getElementById("loading").style.display = "none"
document.getElementById("menu").style.display = "flex"
}
preload()