Skip to content

Commit 3077429

Browse files
committed
Aplikacja electron
1 parent 55966dc commit 3077429

26 files changed

+287
-367
lines changed

build/client/index.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ init = ()->
113113
terrain.setVoxel block...
114114
return
115115
socket.on "mapChunk", (chunk)->
116-
console.log chunk
116+
# console.log chunk
117117
players=new Players {socket,scene,al}
118118
socket.on "playerUpdate",(data)->
119119
players.update data

build/client/module/FirstPersonControls.coffee

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,18 @@ class FirstPersonControls
5050
if THREE.MathUtils.radToDeg( @camera.rotation.x ) > 90
5151
@camera.rotation.x = THREE.MathUtils.degToRad 90
5252
return
53-
lockChangeAlert: ->
54-
_this=@
55-
@handler=
56-
if document.pointerLockElement is @canvas or document.mozPointerLockElement is @canvas
57-
$(".gameMenu").css "display", "none"
58-
@gameState="game"
59-
else
60-
$(".gameMenu").css "display", "block"
61-
@gameState="menu"
62-
return
6353
listen: ->
6454
_this=@
6555
$(window).keydown (z) ->
6656
_this.keys[z.keyCode] = true
57+
#If click escape
58+
if z.keyCode is 27
59+
console.log _this.gameState
60+
if _this.gameState is "menu"
61+
_this.canvas.requestPointerLock()
62+
else
63+
document.exitPointerLock = document.exitPointerLock or document.mozExitPointerLock;
64+
document.exitPointerLock();
6765
return
6866
$(document).keyup (z) ->
6967
delete _this.keys[z.keyCode]
@@ -72,15 +70,21 @@ class FirstPersonControls
7270
console.log "clicked!"
7371
_this.canvas.requestPointerLock()
7472
return
75-
document.addEventListener 'pointerlockchange', ()->
76-
_this.lockChangeAlert()
77-
, false
78-
document.addEventListener 'mozpointerlockchange', ()->
79-
_this.lockChangeAlert()
80-
, false
73+
lockChangeAlert=()->
74+
if document.pointerLockElement is _this.canvas or document.mozPointerLockElement is _this.canvas
75+
_this.gameState="game"
76+
$(".gameMenu").css "display", "none"
77+
console.log("GAME")
78+
else
79+
_this.gameState="menu"
80+
$(".gameMenu").css "display", "block"
81+
console.log("MENU")
82+
return
83+
document.addEventListener 'pointerlockchange', lockChangeAlert, false
84+
document.addEventListener 'mozpointerlockchange', lockChangeAlert, false
8185
document.addEventListener "mousemove", (e)->
8286
_this.updatePosition(e)
8387
, false
8488
return @
8589

86-
export {FirstPersonControls}
90+
export {FirstPersonControls}

build/client/module/Terrain.coffee

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class Terrain
77
@cellTerrain=new CellTerrain {
88
cellSize:@cellSize
99
}
10-
# @cellTerrain.getBuffer(0,0,0)
1110
@cellsData={}
1211
@blocks=options.blocks
1312
@blocksMapping=options.blocksMapping
@@ -69,10 +68,10 @@ class Terrain
6968
Object.keys(@cellsData).forEach (id)->
7069
if _this.cellsData[id].needsUpdate
7170
_this.worker.genCellGeo id.split(":")...
72-
return
71+
return
7372
return
7473
updateCell: (data)->
75-
# console.warn "SENDING cell: #{data.info}"
74+
# console.warn "SENDING cell: #{data.info}"
7675
cellId=@vec3 data.info...
7776
cell=data.cell
7877
if @cellsData[cellId]!=undefined
@@ -178,4 +177,4 @@ class Terrain
178177
else
179178
return false
180179

181-
export {Terrain}
180+
export {Terrain}

build/index.coffee

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
el=require "electron"
3+
fs=require "fs"
4+
5+
config=JSON.parse fs.readFileSync(__dirname+"/config.json")
6+
require("./server")(config)
7+
8+
el.app.on 'ready', ()->
9+
size=el.screen.getPrimaryDisplay().size
10+
win = new el.BrowserWindow({ width:size.width, height:size.height,icon:__dirname+"/client/assets/images/icon.png"})
11+
win.setMenuBarVisibility(false)
12+
win.setAutoHideMenuBar(true)
13+
win.loadURL("http://#{config.host}:#{config['express-port']}")

build/server.coffee

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
module.exports=(config)->
2+
fs=require "fs"
3+
http=require "http"
4+
server=http.createServer()
5+
io=require("socket.io")(server)
6+
express=require 'express'
7+
app=express();
8+
mineflayer = require 'mineflayer'
9+
Chunk = require("prismarine-chunk")("1.16.1")
10+
vec3=require "vec3"
11+
12+
sf={}
13+
port=config["express-port"]
14+
world={}
15+
#Zapisywanie i odczytywanie świata
16+
saveWorld=->
17+
fs.writeFileSync __dirname+"/savedWorld.json",JSON.stringify(world)
18+
restoreWorld=->
19+
world=JSON.parse fs.readFileSync(__dirname+'/savedWorld.json')
20+
21+
restoreWorld()
22+
23+
players={}
24+
socketInfo={}
25+
26+
27+
app.use express.static(__dirname + "/client/")
28+
app.use (req, res, next) ->
29+
res.set 'Cache-Control', 'no-store'
30+
next()
31+
app.get "/websocket/",(req,res)->
32+
res.send String(config["websocket-port"])
33+
app.get "/host/",(req,res)->
34+
res.send String(config["host"])
35+
app.listen port
36+
37+
server.listen config["websocket-port"]
38+
39+
#On connect
40+
io.sockets.on "connection", (socket)->
41+
42+
#Trying to run special functions
43+
socket.on "initClient",(data)->
44+
console.log "NEW: "+socket.id
45+
#init socketInfo
46+
socketInfo[socket.id]=data
47+
48+
#socketInfo add Bot
49+
socketInfo[socket.id].bot=mineflayer.createBot {
50+
host: config.realServer.ip
51+
port: config.realServer.port
52+
username: socketInfo[socket.id].nick
53+
}
54+
#On recieve real Map Chunk
55+
socketInfo[socket.id].bot._client.on "map_chunk",(packet)->
56+
57+
# cell=new Chunk()
58+
# cell.load packet.chunkData,packet.bitMap,false,true
59+
# console.log cell.fromJson
60+
io.to(socket.id).emit "mapChunk", packet
61+
62+
# console.log packet
63+
return
64+
65+
socketInfo[socket.id].bot.on 'chat',(username, message)->
66+
if username is socketInfo[socket.id].bot.username
67+
return
68+
socketInfo[socket.id].bot.chat message
69+
return
70+
#first world load
71+
io.to(socket.id).emit "firstLoad",world
72+
return
73+
socket.on "playerUpdate",(data)->
74+
players[socket.id]=data
75+
io.sockets.emit "playerUpdate", data
76+
socket.on "blockUpdate",(block)->
77+
world["#{block[0]}:#{block[1]}:#{block[2]}"]=block[3]
78+
if block[3] is 0
79+
delete world["#{block[0]}:#{block[1]}:#{block[2]}"]
80+
io.sockets.emit "blockUpdate",block
81+
saveWorld()
82+
socket.on "disconnect", ->
83+
console.log "DIS: "+socket.id
84+
85+
#end bot session
86+
socketInfo[socket.id].bot.end()
87+
#delete socketinfo
88+
delete players[socket.id]
89+
delete socketInfo[socket.id]
90+
return

build/server/start.coffee

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

build/server/webmc.coffee

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

docs/README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Join the chat at https://gitter.im/web-minecraft/community](https://badges.gitter.im/web-minecraft/community.svg)](https://gitter.im/web-minecraft/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44

5-
<i>Minecraft w przeglądarce!</i>
5+
<i>Minecraft w javascripcie!</i>
66

77
<i>
88
</i>
@@ -17,17 +17,9 @@ npm i
1717
npm start
1818

1919
```
20-
<h4>Defaultowa konfiguracja:</h4>
21-
<img src="https://i.ibb.co/M5ZMK49/config.png"
22-
alt="config"
23-
style="margin-right: 10px;" />
2420
<br>
2521
<h4>Screenshoty:</h4>
2622

2723
[<img src="https://i.ibb.co/kmhv1tF/screen1.png" alt="screen1" width="260">](https://i.ibb.co/kmhv1tF/screen1.png)
2824
[<img src="https://i.ibb.co/Q9WCSXR/screen2.png" alt="screen2" width="260">](https://i.ibb.co/Q9WCSXR/screen2.png)
2925
[<img src="https://i.ibb.co/HKwR1kK/screen3.png" alt="screen3" width="260">](https://i.ibb.co/HKwR1kK/screen3.png)
30-
31-
32-
33-

index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)