Skip to content

Commit dde4de8

Browse files
committed
Chat GUI
1 parent b6aafea commit dde4de8

File tree

17 files changed

+301
-271
lines changed

17 files changed

+301
-271
lines changed

coffee/client/module/FirstPersonControls.coffee

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ class FirstPersonControls
1717
@socket=options.socket
1818
@gameState="menu"
1919
@listen()
20+
$("#commandx").blur()
21+
$(".command").hide()
2022
updatePosition: (e)->
21-
if @gameState is "game"
23+
#Updatowanie kursora
24+
if @gameState is "gameLock"
2225
@camera.rotation.x -= THREE.MathUtils.degToRad e.movementY / 10
2326
@camera.rotation.y -= THREE.MathUtils.degToRad e.movementX / 10
2427
if THREE.MathUtils.radToDeg( @camera.rotation.x ) < -90
@@ -29,39 +32,93 @@ class FirstPersonControls
2932
return
3033
listen: ->
3134
_this=@
32-
$(window).keydown (z) ->
35+
$(document).keydown (z) ->
36+
#Kliknięcie
3337
_this.keys[z.keyCode] = true
34-
#If click escape
35-
if z.keyCode is 27
36-
if _this.gameState is "menu"
37-
_this.canvas.requestPointerLock()
38+
39+
#Klawisz Enter
40+
if z.keyCode is 13 and _this.gameState is "chat"
41+
_this.socket.emit "command",commandx.value
42+
commandx.value=""
43+
44+
#Klawisz T lub /
45+
if (z.keyCode is 84 or z.keyCode is 191) and _this.gameState is "gameLock"
46+
if z.keyCode is 191
47+
commandx.value="/"
48+
_this._Chat()
49+
z.preventDefault()
50+
51+
#Klawisz `
52+
if z.keyCode is 192
53+
$("#commandx").blur()
54+
$(".command").hide()
55+
z.preventDefault()
56+
if (_this.gameState is "menu") or (_this.gameState is "chat")
57+
_this._Game()
3858
else
39-
document.exitPointerLock = document.exitPointerLock or document.mozExitPointerLock;
40-
document.exitPointerLock();
41-
if _this.kc[z.keyCode] isnt undefined
59+
_this._Menu()
60+
if z.keyCode is 27 and _this.gameState is "chat"
61+
$("#commandx").blur()
62+
$(".command").hide()
63+
_this._Menu()
64+
65+
#Wysyłanie state'u do serwera
66+
if _this.kc[z.keyCode] isnt undefined and _this.gameState is "gameLock"
4267
_this.socket.emit "move",_this.kc[z.keyCode],true
4368
return
4469
$(document).keyup (z) ->
70+
#Odkliknięcie
71+
delete _this.keys[z.keyCode]
72+
73+
#Wysyłanie state'u do serwera
4574
if _this.kc[z.keyCode] isnt undefined
4675
_this.socket.emit "move",_this.kc[z.keyCode],false
47-
delete _this.keys[z.keyCode]
76+
4877
return
4978
$(".gameOn").click ->
50-
_this.canvas.requestPointerLock()
79+
_this._Game()
5180
return
5281
lockChangeAlert=()->
5382
if document.pointerLockElement is _this.canvas or document.mozPointerLockElement is _this.canvas
54-
_this.gameState="game"
55-
$(".gameMenu").css "display", "none"
83+
#Lock
84+
if _this.gameState is "game"
85+
$("#commandx").blur()
86+
$(".command").hide()
87+
_this.state "gameLock"
88+
$(".gameMenu").css "display", "none"
5689
else
57-
_this.gameState="menu"
58-
$(".gameMenu").css "display", "block"
90+
#Unlock
91+
if (_this.gameState is "menu") or (_this.gameState is "gameLock")
92+
$("#commandx").blur()
93+
$(".command").hide()
94+
_this._Menu()
5995
return
6096
document.addEventListener 'pointerlockchange', lockChangeAlert, false
6197
document.addEventListener 'mozpointerlockchange', lockChangeAlert, false
6298
document.addEventListener "mousemove", (e)->
6399
_this.updatePosition(e)
64100
, false
65101
return @
102+
state:(state)->
103+
@gameState=state
104+
console.log "Game state: "+state
105+
_Game:()->
106+
@state "game"
107+
@canvas.requestPointerLock()
108+
_Menu:()->
109+
@state "menu"
110+
$(".gameMenu").css "display", "block"
111+
document.exitPointerLock = document.exitPointerLock or document.mozExitPointerLock
112+
document.exitPointerLock();
113+
_Chat:()->
114+
if @gameState is "gameLock"
115+
@state "chat"
116+
$(".gameMenu").css "display", "none"
117+
document.exitPointerLock = document.exitPointerLock or document.mozExitPointerLock
118+
document.exitPointerLock()
119+
$(".command").show()
120+
$("#commandx").focus()
121+
122+
66123

67124
export {FirstPersonControls}

coffee/client/module/Players.coffee

Lines changed: 0 additions & 53 deletions
This file was deleted.

coffee/client/module/RandomNick.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
RandomNick=->
22
nameList = ['Time','Past','Future','Dev','Fly','Flying','Soar','Soaring','Power','Falling','Fall','Jump','Cliff','Mountain','Rend','Red','Blue','Green','Yellow','Gold','Panda','Cat','Kitty','Kitten','Zero','Memory','Trooper','XX','Bandit','Fear','Light','Glow','Tread','Deep','Deeper','Deepest','Mine','Your','Worst','Enemy','Hostile','Force','Video','Game','Donkey','Mule','Colt','Cult','Cultist','Magnum','Gun','Assault','Recon','Trap','Trapper','Redeem','Code','Script','Writer','Near','Close','Open','Cube','Circle','Geo','Genome','Germ','Spaz','Shot','Echo','Beta','Alpha','Gamma','Omega','Seal','Squid','Money','Cash','Lord','King','Duke','Rest','Fire','Flame','Morrow','Break','Breaker','Numb','Ice','Cold','Rotten','Sick','Sickly','Janitor','Camel','Rooster','Sand','Desert','Dessert','Hurdle','Racer','Eraser','Erase','Big','Small','Short','Tall','Sith','Bounty','Hunter','Cracked','Broken','Sad','Happy','Joy','Joyful','Crimson','Destiny','Deceit','Lies','Lie','Honest','Destined','Bloxxer','Hawk','Eagle','Hawker','Walker','Zombie','Sarge','Capt','Captain','Punch','One','Two','Uno','Slice','Slash','Melt','Melted','Melting','Fell','Wolf','Hound','Legacy','Sharp','Dead','Mew','Chuckle','Bubba','Bubble','Sandwich','Smasher','Extreme','Multi','Universe','Ultimate','Death','Ready','Monkey','Elevator','Wrench','Grease','Head','Theme','Grand','Cool','Kid','Boy','Girl','Vortex','Paradox']
33
finalName = ""
4-
# nick="WebmcPlayer#{Math.floor(10000+Math.random()*10000)}"
54
finalName = nameList[Math.floor( Math.random() * nameList.length )]
65
finalName += nameList[Math.floor( Math.random() * nameList.length )]
76
if Math.random() > 0.5

coffee/client/module/World/World.coffee

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ class World
1717
@ATA=new AnimatedTextureAtlas {al:@al}
1818
@material=@ATA.material
1919
@cellUpdateTime=null
20+
@renderTime=500
2021
@neighbours=[[-1, 0, 0],[1, 0, 0],[0, -1, 0],[0, 1, 0],[0, 0, -1],[0, 0, 1]]
22+
23+
#Utworzenie Workera do obliczania geometrii chunków
2124
@chunkWorker=new Worker "/module/World/ChunkWorker.js", {type:'module'}
2225
@chunkWorker.onmessage=(message)->
2326
_this.updateCell message.data
@@ -29,18 +32,20 @@ class World
2932
@al.get("anvil").children[0].geometry.attributes...
3033
}
3134
}
32-
blocks: @al.get "blocks"
3335
blocksMapping: @al.get "blocksMapping"
3436
toxelSize: @toxelSize
3537
cellSize: @cellSize
3638
}
3739
}
40+
41+
#Utworzenie Workera do przekształcania bufforów otrzymanych z serwera
3842
@sectionsWorker=new Worker "/module/World/SectionsWorker.js", {type:'module'}
3943
@sectionsWorker.onmessage=(data)->
4044
result=data.data.result
4145
for i in result
4246
if i isnt null
4347
_this.setCell i.x,i.y,i.z,i.cell,i.biome
48+
return
4449
setCell: (cellX,cellY,cellZ,buffer,biome)->
4550
@_setCell cellX,cellY,cellZ,buffer,biome
4651
@cellTerrain.setCell cellX,cellY,cellZ,buffer
@@ -62,12 +67,10 @@ class World
6267
neiCellId=@cellTerrain.vec3 @cellTerrain.computeCellForVoxel(voxelX+nei[0],voxelY+nei[1],voxelZ+nei[2])...
6368
@cellNeedsUpdate[neiCellId]=true
6469
return
65-
getBlock: (voxelX,voxelY,voxelZ) ->
66-
return @cellTerrain.getVoxel voxelX,voxelY,voxelZ
6770
updateCellsAroundPlayer: (pos,radius)->
71+
#Updatowanie komórek wokół gracza w danym zasięgu
6872
_this=@
69-
if @cellUpdateTime isnt null and (performance.now()-@cellUpdateTime>500)
70-
console.log "updating"
73+
if @cellUpdateTime isnt null and (performance.now()-@cellUpdateTime>@renderTime)
7174
for k,v of @cellMesh
7275
v.visible=false
7376
cell=@cellTerrain.computeCellForVoxel (Math.floor pos.x),(Math.floor pos.y),(Math.floor pos.z)
@@ -80,11 +83,17 @@ class World
8083
delete _this.cellNeedsUpdate[_this.cellTerrain.vec3(pcell...)]
8184
return
8285
up(0,0,0)
86+
up(1,0,0)
87+
up(-1,0,0)
88+
89+
up(0,0,1)
90+
up(0,0,-1)
8391
for i in [-radius..radius]
8492
for j in [-radius..radius]
8593
for k in [-radius..radius]
8694
up i,j,k
8795
updateCell: (data)->
96+
#Updatowanie komórki z już obliczoną geometrią
8897
cellId=@cellTerrain.vec3 data.info...
8998
cell=data.cell
9099
mesh=@cellMesh[cellId]
@@ -132,7 +141,7 @@ class World
132141
tzMax = if tzDelta < Infinity then tzDelta * zDist else Infinity
133142
steppedIndex = -1
134143
while t <= len
135-
voxel = @getBlock ix, iy, iz
144+
voxel = @cellTerrain.getVoxel ix, iy, iz
136145
if voxel
137146
return {
138147
position: [
@@ -183,17 +192,20 @@ class World
183192
else
184193
return false
185194
_setCell: (cellX,cellY,cellZ,buffer,biome)->
195+
#Wysyłanie do ChunkWorkera informacji nowej komórce
186196
@cellUpdateTime=performance.now()
187197
@chunkWorker.postMessage {
188198
type:"setCell"
189199
data:[cellX,cellY,cellZ,buffer,biome]
190200
}
191201
_setVoxel: (voxelX,voxelY,voxelZ,value)->
202+
#Wysyłanie do ChunkWorkera informacji o nowym Voxelu
192203
@chunkWorker.postMessage {
193204
type:"setVoxel"
194205
data:[voxelX,voxelY,voxelZ,value]
195206
}
196207
_genCellGeo: (cellX,cellY,cellZ)->
208+
#Wysyłanie do ChunkWorkera prośby o wygenerowanie geometrii komórki
197209
cellX=parseInt cellX
198210
cellY=parseInt cellY
199211
cellZ=parseInt cellZ
@@ -202,6 +214,7 @@ class World
202214
data:[cellX,cellY,cellZ]
203215
}
204216
_computeSections: (sections,x,z,biomes)->
217+
#Wysyłanie do SectionsWorkera Buffora, który ma przekształcić w łatwiejszą postać
205218
@sectionsWorker.postMessage {
206219
type:"computeSections"
207220
data:{

coffee/client/module/ghast.coffee

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)