11# Bundle.js
2+ scene = null ;materials = null ;parameters = null ;canvas = null ;renderer = null ;camera = null ;terrain = null ;cursor = null ;FPC = null ;socket = null ;stats = null ;worker = null ;playerObject = null ;inv_bar = null
23import * as THREE from ' ./module/build/three.module.js'
34import {SkeletonUtils} from ' ./module/jsm/utils/SkeletonUtils.js'
45import Stats from ' ./module/jsm/libs/stats.module.js'
@@ -9,28 +10,14 @@ import {AssetLoader} from './module/AssetLoader.js'
910import {InventoryBar} from ' ./module/InventoryBar.js'
1011import {AnimatedTextureAtlas} from ' ./module/AnimatedTextureAtlas.js'
1112import {Players} from ' ./module/Players.js'
13+ import {RandomNick} from ' ./module/RandomNick.js'
1214
13- scene = null ;materials = null ;parameters = null ;canvas = null ;renderer = null ;camera = null ;terrain = null ;cursor = null ;FPC = null ;socket = null ;stats = null ;worker = null ;playerObject = null ;inv_bar = null
1415
15- getNick = ->
16- 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']
17- finalName = " "
18- nick = document .location .hash .substring (1 ,document .location .hash .length )
19- if nick is " "
20- # nick="WebmcPlayer#{Math.floor(10000+Math.random()*10000)}"
21- finalName = nameList[Math .floor ( Math .random () * nameList .length )]
22- finalName += nameList[Math .floor ( Math .random () * nameList .length )]
23- if Math .random () > 0.5
24- finalName += nameList[Math .floor ( Math .random () * nameList .length )]
25- nick = finalName
26- document .location .href = " \# #{ nick} "
27- return nick
2816class TerrainWorker
2917 constructor : (options )->
30- @worker = new Worker " workers/terrain .js" , {type : ' module' }
18+ @worker = new Worker " module/TerrainWorker .js" , {type : ' module' }
3119 @worker .onmessage = (message )->
3220 terrain .updateCell message .data
33- # console.warn "RECIEVED CELL:",message.data.info
3421 @worker .postMessage {
3522 type : ' init'
3623 data : {
@@ -62,7 +49,7 @@ class TerrainWorker
6249init = ()->
6350 # Terrain worker
6451 worker = new TerrainWorker
65-
52+
6653 # canvas,renderer,camera,lights
6754 canvas = document .querySelector ' #c'
6855 renderer = new THREE.WebGLRenderer {
@@ -80,7 +67,7 @@ init = ()->
8067 scene .add ambientLight
8168 directionalLight = new THREE.DirectionalLight 0x333333 , 2
8269 directionalLight .position .set (1 , 1 , 0.5 ).normalize ()
83- scene .add directionalLight
70+ scene .add directionalLight
8471 console .warn gpuInfo ()
8572
8673 # Clouds
@@ -107,14 +94,16 @@ init = ()->
10794 camera
10895 worker
10996 })
110-
97+
11198 # Socket.io setup
11299 socket = io .connect " #{ al .get (" host" )} :#{ al .get (" websocket-port" )} "
113-
114100 socket .on " connect" ,()->
115101 console .log " Połączono z serverem!"
116102 $ (' .loadingText' ).text " Wczytywanie terenu..."
117- nick = getNick ()
103+ nick = document .location .hash .substring (1 ,document .location .hash .length )
104+ if nick is " "
105+ nick = RandomNick ()
106+ document .location .href = " \# #{ nick} "
118107 console .log " User nick: #{ nick} "
119108 socket .emit " initClient" , {
120109 nick : nick
@@ -138,7 +127,7 @@ init = ()->
138127 stats .showPanel (0 );
139128 document .body .appendChild stats .dom
140129 return
141-
130+
142131 # Inventory Bar
143132 inv_bar = new InventoryBar ({
144133 boxSize : 60
@@ -155,13 +144,13 @@ init = ()->
155144 " assets/images/bookshelf.png" ,
156145 " assets/images/tnt.png"
157146 ]).setFocusOnly (1 ).listen ()
158-
147+
159148 # First Person Controls
160149 FPC = new FirstPersonControls ({
161150 canvas
162151 camera
163152 micromove : 0.3
164- }).listen ()
153+ }).listen ()
165154
166155 # Raycast cursor
167156 cursor = new THREE.LineSegments (
@@ -174,7 +163,7 @@ init = ()->
174163 }
175164 )
176165 scene .add cursor
177-
166+
178167 # jquery events
179168 $ (document ).mousedown (e)->
180169 if FPC .gameState is " game"
@@ -186,12 +175,12 @@ init = ()->
186175 else
187176 voxelId = inv_bar .activeBox
188177 pos = rayBlock .posPlace
189- pos[0 ]= Math .floor pos[0 ]
190- pos[1 ]= Math .floor pos[1 ]
191- pos[2 ]= Math .floor pos[2 ]
178+ pos[0 ]= Math .floor pos[0 ]
179+ pos[1 ]= Math .floor pos[1 ]
180+ pos[2 ]= Math .floor pos[2 ]
192181 socket .emit " blockUpdate" ,[pos... ,voxelId]
193182 return
194-
183+
195184 animate ()
196185 return
197186render = ->
@@ -204,7 +193,7 @@ render = ->
204193 renderer .setSize width,height,false
205194 camera .aspect = width / height
206195 camera .updateProjectionMatrix ()
207-
196+
208197 # Player movement
209198 if FPC .gameState is " game"
210199 socket .emit " playerUpdate" , {
@@ -215,7 +204,7 @@ render = ->
215204 zyaw : camera .rotation .y + Math .PI
216205 }
217206 FPC .camMicroMove ()
218-
207+
219208 # Update cursor
220209 rayBlock = terrain .getRayBlock ()
221210 if rayBlock
@@ -227,10 +216,10 @@ render = ->
227216 cursor .visible = true
228217 else
229218 cursor .visible = false
230-
219+
220+ # Rendering
231221 renderer .render scene, camera
232222 terrain .updateCells ()
233-
234223 return
235224animate = ->
236225 try
@@ -245,9 +234,9 @@ $.get "assets/assetLoader.json", (assets)->
245234 al .load assets,()->
246235 console .log " AssetLoader: done loading!"
247236 al .get (" anvil" ).children [0 ].geometry .rotateX - Math .PI / 2
248- al .get (" anvil" ).children [0 ].geometry .translate 0 ,0.17 ,0
249- al .get (" anvil" ).children [0 ].geometry .translate 0 ,- 0.25 ,0
237+ al .get (" anvil" ).children [0 ].geometry .translate 0 ,0.17 ,0
238+ al .get (" anvil" ).children [0 ].geometry .translate 0 ,- 0.25 ,0
250239 init ()
251240 return
252241 ,al
253- return
242+ return
0 commit comments