Skip to content

Commit f9f7377

Browse files
committed
usersLIST
1 parent 53e4648 commit f9f7377

26 files changed

+3853
-1208
lines changed

build/coffee/bundle.coffee

Lines changed: 147 additions & 473 deletions
Large diffs are not rendered by default.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import * as THREE from './../../module/build/three.module.js'
2+
3+
class TextureAtlasCreator
4+
constructor: (options)->
5+
@textureX=options.textureX
6+
@textureMapping=options.textureMapping
7+
@size=36
8+
@willSize=27
9+
gen: (tick)->
10+
multi={}
11+
for i of @textureMapping
12+
if i.includes "@"
13+
xd=@decodeName i
14+
if multi[xd.pref] is undefined
15+
multi[xd.pref]=xd
16+
else
17+
multi[xd.pref].x=Math.max multi[xd.pref].x,xd.x
18+
multi[xd.pref].y=Math.max multi[xd.pref].y,xd.y
19+
canvasx = document.createElement 'canvas'
20+
ctx=canvasx.getContext "2d"
21+
canvasx.width=@willSize*16
22+
canvasx.height=@willSize*16
23+
toxelX=1
24+
toxelY=1
25+
for i of @textureMapping
26+
if i.includes "@"
27+
xd=@decodeName i
28+
if multi[xd.pref].loaded is undefined
29+
multi[xd.pref].loaded=true
30+
lol=@getToxelForTick tick,multi[xd.pref].x+1,multi[xd.pref].y+1
31+
texmap=@textureMapping["#{xd.pref}@#{lol.col}@#{lol.row}"]
32+
ctx.drawImage @textureX,(texmap.x-1)*16,(texmap.y-1)*16,16,16,(toxelX-1)*16,(toxelY-1)*16,16,16
33+
toxelX++
34+
if toxelX>@willSize
35+
toxelX=1
36+
toxelY++
37+
else
38+
ctx.drawImage @textureX,(@textureMapping[i].x-1)*16,(@textureMapping[i].y-1)*16,16,16,(toxelX-1)*16,(toxelY-1)*16,16,16
39+
toxelX++
40+
if toxelX>@willSize
41+
toxelX=1
42+
toxelY++
43+
return canvasx
44+
decodeName: (i)->
45+
m=null
46+
for j in [0..i.length-1]
47+
if i[j] is "@"
48+
m=j
49+
break
50+
pref=i.substr 0,m
51+
sub=i.substr m,i.length
52+
m2=null
53+
for j in [0..sub.length-1]
54+
if sub[j] is "@"
55+
m2=j
56+
x=parseInt sub.substr(1,m2-1)
57+
y=parseInt sub.substr(m2+1,sub.length)
58+
return {pref,x,y}
59+
getToxelForTick: (tick,w,h)->
60+
tick=tick%(w*h)+1
61+
#option1
62+
col=(tick-1)%w
63+
row=Math.ceil(tick/w)-1
64+
#option2
65+
col=Math.ceil(tick/h)-1
66+
row=(tick-1)%h;
67+
return {row,col}
68+
class AnimatedTextureAtlas
69+
constructor:(options)->
70+
_this=@
71+
@al=options.al
72+
@material=new THREE.MeshStandardMaterial({
73+
side: 0
74+
map:null
75+
})
76+
@atlasCreator=new TextureAtlasCreator({
77+
textureX:@al.get "blocksAtlasFull"
78+
textureMapping:@al.get "blocksMappingFull"
79+
})
80+
savedTextures=[]
81+
for i in [0..9]
82+
t=@atlasCreator.gen(i).toDataURL()
83+
tekstura=new THREE.TextureLoader().load t
84+
tekstura.magFilter = THREE.NearestFilter
85+
savedTextures.push tekstura
86+
tickq=0
87+
setInterval(()->
88+
tickq++
89+
tekst=savedTextures[tickq%9]
90+
_this.material.map=tekst
91+
_this.material.map.needsUpdate=true
92+
return
93+
,100)
94+
95+
export {AnimatedTextureAtlas}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as THREE from './../../module/build/three.module.js'
2+
import {FBXLoader} from './../../module/jsm/loaders/FBXLoader.js'
3+
4+
class AssetLoader
5+
constructor: (options)->
6+
@assets={}
7+
load: (assets,callback) ->
8+
_this=@
9+
textureLoader = new THREE.TextureLoader
10+
fbxl = new FBXLoader()
11+
assetsNumber=0
12+
assetsLoaded=0
13+
Object.keys(assets).forEach (p)->
14+
assetsNumber++
15+
Object.keys(assets).forEach (p)->
16+
type=assets[p].type
17+
path=assets[p].path
18+
dynamic=assets[p].dynamic;
19+
if dynamic
20+
path+="?"+THREE.MathUtils.generateUUID()
21+
if type is "texture"
22+
textureLoader.load path,(texture)->
23+
_this.assets[p]=texture
24+
assetsLoaded++;
25+
if assetsLoaded is assetsNumber
26+
callback()
27+
if type is "text"
28+
$.get path,(data)->
29+
_this.assets[p]=data
30+
assetsLoaded++;
31+
if assetsLoaded is assetsNumber
32+
callback()
33+
if type is "image"
34+
img = new Image
35+
img.onload= ->
36+
_this.assets[p]=img
37+
assetsLoaded++;
38+
if assetsLoaded is assetsNumber
39+
callback()
40+
img.src=path
41+
if type is "fbx"
42+
fbxl.load path,(fbx)->
43+
_this.assets[p]=fbx
44+
assetsLoaded++;
45+
if assetsLoaded is assetsNumber
46+
callback()
47+
return this;
48+
get: (assetName)->
49+
return @assets[assetName]
50+
51+
export {AssetLoader}

build/coffee/mod/CellTerrain.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ class CellTerrain
4141
getBuffer:(x,y,z)->
4242
console.log(@cells[@vec3(x,y,z)])
4343
return
44+
4445
export {CellTerrain}

build/coffee/mod/FirstPersonControls.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as THREE from './../../module/build/three.module.js'
2+
23
class FirstPersonControls
34
constructor: (options)->
45
@kc={
@@ -83,4 +84,5 @@ class FirstPersonControls
8384
_this.updatePosition(e)
8485
, false
8586
return @
87+
8688
export {FirstPersonControls}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
class InventoryBar
2+
constructor: (options)->
3+
@boxSize=options.boxSize
4+
@div=options.div
5+
@padding=options.padding
6+
@boxes=9
7+
@activeBox=1
8+
document.querySelector(@div).style="position:fixed;bottom:3px;left:50%;width:#{(@boxSize+2)*@boxes}px;margin-left:-#{@boxSize*@boxes/2}px;height:#{@boxSize}px;"
9+
setBox: (number,imageSrc)->
10+
if imageSrc is null
11+
imageSrc = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
12+
document.querySelector(".inv_box_#{number}").src=imageSrc
13+
return
14+
setFocus: (number,state)->
15+
if state
16+
document.querySelector(".inv_box_#{number}").style.background="rgba(0,0,0,0.7)"
17+
document.querySelector(".inv_box_#{number}").style.border="1px solid black"
18+
else
19+
document.querySelector(".inv_box_#{number}").style.background="rgba(54,54,54,0.5)"
20+
document.querySelector(".inv_box_#{number}").style.border="1px solid #363636"
21+
return
22+
setFocusOnly: (number)->
23+
for i in [1..@boxes]
24+
@setFocus i, i is number
25+
@activeBox=number
26+
return @
27+
moveBoxMinus: ->
28+
if @activeBox + 1 > @boxes
29+
@setFocusOnly 1
30+
else
31+
@setFocusOnly @activeBox + 1
32+
return
33+
moveBoxPlus: ->
34+
if @activeBox - 1 is 0
35+
@setFocusOnly @boxes
36+
else
37+
@setFocusOnly @activeBox - 1
38+
directBoxChange: (event)->
39+
code = event.keyCode
40+
if code >= 49 and code < 49 + @boxes
41+
@setFocusOnly code - 48
42+
setBoxes: (images)->
43+
for i in [0..images.length-1]
44+
@setBox i+1,images[i]
45+
return @
46+
listen: ->
47+
_this=@
48+
$(window).on 'wheel', (event) ->
49+
if event.originalEvent.deltaY < 0
50+
_this.moveBoxPlus()
51+
else
52+
_this.moveBoxMinus()
53+
$(document).keydown (z) ->
54+
_this.directBoxChange(z)
55+
return @
56+
57+
export {InventoryBar}

build/coffee/mod/Players.coffee

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {SkeletonUtils} from './../../module/jsm/utils/SkeletonUtils.js'
2+
import * as THREE from './../../module/build/three.module.js'
3+
4+
class Player
5+
constructor: (options)->
6+
@playerObject=options.playerObject
7+
@scene=options.scene
8+
setup:()->
9+
@object=SkeletonUtils.clone @playerObject
10+
@scene.add @object
11+
setPos:(x,y,z,xyaw,zyaw)->
12+
@object.children[1].position.set x,y-0.5,z
13+
@object.children[1].children[0].children[0].children[0].children[2].rotation.x=xyaw
14+
@object.children[1].children[0].rotation.z=zyaw
15+
remove:()->
16+
@scene.remove @object
17+
class Players
18+
constructor:(options)->
19+
@al=options.al
20+
@scene=options.scene
21+
@playersx={}
22+
@socket=options.socket
23+
@playerObject=@al.get "player"
24+
texturex = @al.get "steve"
25+
texturex.magFilter = THREE.NearestFilter
26+
@playerObject.children[1].scale.set 1,1,1
27+
@playerObject.children[1].position.set 25,25,25
28+
@playerObject.children[0].material.map=texturex
29+
@playerObject.children[0].material.color=new THREE.Color 0xffffff
30+
@playerObject.children[1].scale.set 0.5,0.5,0.5
31+
update:(players)->
32+
_this=@
33+
sockets={}
34+
Object.keys(players).forEach (p)->
35+
sockets[p]=true
36+
if _this.playersx[p] is undefined and p isnt _this.socket.id
37+
_this.playersx[p]=new Player({
38+
scene:_this.scene
39+
playerObject:_this.playerObject
40+
scene:_this.scene
41+
})
42+
_this.playersx[p].setup()
43+
try
44+
_this.playersx[p].setPos(players[p].x,players[p].y,players[p].z,players[p].xyaw,players[p].zyaw)
45+
return
46+
Object.keys(@playersx).forEach (p)->
47+
if sockets[p] is undefined
48+
_this.playersx[p].remove()
49+
delete _this.playersx[p]
50+
return
51+
return
52+
53+
export {Players}

build/coffee/mod/Terrain.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as THREE from './../../module/build/three.module.js'
22
import {CellTerrain} from './CellTerrain.js'
3+
34
class Terrain
45
constructor: (options) ->
56
@cellSize=options.cellSize
@@ -176,4 +177,5 @@ class Terrain
176177
return {posPlace,posBreak}
177178
else
178179
return false
180+
179181
export {Terrain}

build/coffee/mod/ghast.coffee

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#Ghast1
2+
ghast=al.get "ghastF"
3+
texturex1 = al.get "ghast"
4+
texturex1.magFilter = THREE.NearestFilter
5+
ghast.children[1].material.map=texturex1
6+
ghast.children[0].children[0].scale.set 0.01,0.01,0.01
7+
ghast.children[1].material.color=new THREE.Color 0xffffff
8+
mat=ghast.children[1].material.clone()
9+
scene.add ghast
10+
11+
#Ghast2
12+
ghast2=SkeletonUtils.clone ghast
13+
texturex2 = al.get "ghastS"
14+
texturex2.magFilter = THREE.NearestFilter
15+
ghast2.children[1].material=mat
16+
ghast2.children[1].material.map=texturex2
17+
ghast2.position.set 3,0,0
18+
scene.add ghast2

build/coffee/mod/gpuInfo.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ gpuInfo = ->
1313
return {
1414
error: "no WEBGL_debug_renderer_info"
1515
}
16+
1617
export {gpuInfo}

0 commit comments

Comments
 (0)