From fb43cb1fb7097c0383c10ac7194893fc3cfeb1b0 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Sun, 16 Aug 2020 18:53:39 -0400 Subject: [PATCH] Generate basic world & recieve data on client --- ...t.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.md5 | 3 + ....png-2d96e51b4345f83ec0fb0c1ed8bf2b89.stex | Bin 0 -> 154 bytes ...s.png-d6f949232ad65f7c5ac8611d6943aaf7.md5 | 3 + ....png-d6f949232ad65f7c5ac8611d6943aaf7.stex | Bin 0 -> 3461 bytes client/art/tiles/dirt.png | Bin 0 -> 108 bytes client/art/tiles/dirt.png.import | 34 ++++++++++++ client/art/tiles/grass.png | Bin 0 -> 5029 bytes client/art/tiles/grass.png.import | 34 ++++++++++++ client/nodes/tileset.tres | 43 +++++++++++++++ client/scenes/World.tscn | 11 ++++ client/scripts/menus/login_form.gd | 2 +- client/scripts/singletons/ServerConnection.gd | 13 +++++ client/scripts/singletons/WorldManager.gd | 15 +++++ server/plugin/control/control.go | 33 ++++++++--- server/plugin/gamemap/gamemap.go | 52 ++++++++++++++++++ server/plugin/go.sum | 2 + 16 files changed, 237 insertions(+), 8 deletions(-) create mode 100644 client/.import/dirt.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.md5 create mode 100644 client/.import/dirt.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.stex create mode 100644 client/.import/grass.png-d6f949232ad65f7c5ac8611d6943aaf7.md5 create mode 100644 client/.import/grass.png-d6f949232ad65f7c5ac8611d6943aaf7.stex create mode 100644 client/art/tiles/dirt.png create mode 100644 client/art/tiles/dirt.png.import create mode 100644 client/art/tiles/grass.png create mode 100644 client/art/tiles/grass.png.import create mode 100644 client/nodes/tileset.tres create mode 100644 client/scenes/World.tscn create mode 100644 client/scripts/singletons/WorldManager.gd create mode 100644 server/plugin/gamemap/gamemap.go diff --git a/client/.import/dirt.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.md5 b/client/.import/dirt.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.md5 new file mode 100644 index 0000000..d3c727a --- /dev/null +++ b/client/.import/dirt.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.md5 @@ -0,0 +1,3 @@ +source_md5="ea3da320528c7d54640506628b12b80c" +dest_md5="f8c65d4e4cd80d79c48ff0c014cf0377" + diff --git a/client/.import/dirt.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.stex b/client/.import/dirt.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.stex new file mode 100644 index 0000000000000000000000000000000000000000..e688d241c774845eabe5806d2f29bf5575239913 GIT binary patch literal 154 zcmZ>F2@X+UU|;}Y79eI|5MXBnl662F;ODN;2_$&Aq_}`wUQZ8~ARw&(!W?Wsvbd`1 z3y@+g4sv&5Sa(k5C6Hs{>Eaj?(fanBAtQqU$B_femt`#z`mkS2Qb(M5=d1F1G3(jI dKxIgvK}FI)lF9CkUH?gtsHdx+%Q~loCIEh%A&CG0 literal 0 HcmV?d00001 diff --git a/client/.import/grass.png-d6f949232ad65f7c5ac8611d6943aaf7.md5 b/client/.import/grass.png-d6f949232ad65f7c5ac8611d6943aaf7.md5 new file mode 100644 index 0000000..675b906 --- /dev/null +++ b/client/.import/grass.png-d6f949232ad65f7c5ac8611d6943aaf7.md5 @@ -0,0 +1,3 @@ +source_md5="b38dac28f777cd24a94ae764cf60780a" +dest_md5="8568362e706ffbdddbdcb895eaad16c8" + diff --git a/client/.import/grass.png-d6f949232ad65f7c5ac8611d6943aaf7.stex b/client/.import/grass.png-d6f949232ad65f7c5ac8611d6943aaf7.stex new file mode 100644 index 0000000000000000000000000000000000000000..3f1b88d1b6e68a707aea54bae0df8c51566bc034 GIT binary patch literal 3461 zcmY+He>~Is9>=%q$CPTiog?`*=^iEIN5B0VMJknxm<;ptpb1CBv9&qn#0jnL(WEjZ z9cs-YGsmxqj>%*WW+CJ^TMRR7_TzrH&VAf__s3`Zd>`M>&-e5FdcEi2=6f*|3<5m? z{pX_t0lJ{rtsu}pF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IY|+V>*uJAml)Kn)`NokAlQPHONb$=|B}~ zdDOHmW6Uh!`V0HfK%Bg8^#KGxR42o-Q;u5HoaN( zh>fL0GegbX?F)}2N%;@{r&`pTZ5OX}zU_CJ&9Du{CXNC%A~0HWruWT2)oJ@ow?UO^jyH`orYCL0ZqEZy**&!G|A_Ih3d8>r%-CE}Y1o|%%Frys^fj${XGQkH0xbp_8 W@3GG*B=ElpbjJOHTg8dc8~+A0I!dJg literal 0 HcmV?d00001 diff --git a/client/art/tiles/dirt.png b/client/art/tiles/dirt.png new file mode 100644 index 0000000000000000000000000000000000000000..b85005831dcfece5ff9dd5a8e8b9618f32e79aba GIT binary patch literal 108 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzV^0^ykO=p;7aRo{7+4q_gEW3N#c%!=G=A3oC$1gE3GO=(7C^$4g86R{Ddg|;SiY_}_1k}#p>FVdQ&MBb@0CkHU AnE(I) literal 0 HcmV?d00001 diff --git a/client/art/tiles/dirt.png.import b/client/art/tiles/dirt.png.import new file mode 100644 index 0000000..16e9e0a --- /dev/null +++ b/client/art/tiles/dirt.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/dirt.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://art/tiles/dirt.png" +dest_files=[ "res://.import/dirt.png-2d96e51b4345f83ec0fb0c1ed8bf2b89.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/client/art/tiles/grass.png b/client/art/tiles/grass.png new file mode 100644 index 0000000000000000000000000000000000000000..7bae1a10ae3c6f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kXX zHiTb>t$m*bJ%-lY!>qDu2uga>u# NakamaException: var result : NakamaException = null @@ -36,6 +42,7 @@ func connect_to_server_async() -> NakamaException: _socket = Nakama.create_socket_from(_client) var result : NakamaAsyncResult = yield(_socket.connect_async(_session), "completed") if not result.is_exception(): + _socket.connect("received_match_state", self, "_on_socket_received_match_state") _socket.connect("closed", self, "_on_socket_closed") return null return result.exception @@ -60,3 +67,9 @@ func join_world_async() -> Dictionary: func _on_socket_closed(): _socket = null + +func _on_socket_received_match_state(match_state: NakamaRTAPI.MatchData): + match match_state.op_code: + OPCODE.tile_update: + emit_signal("tile_update", JSON.parse(match_state.data).result) + diff --git a/client/scripts/singletons/WorldManager.gd b/client/scripts/singletons/WorldManager.gd new file mode 100644 index 0000000..322f467 --- /dev/null +++ b/client/scripts/singletons/WorldManager.gd @@ -0,0 +1,15 @@ +extends Node + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready(): + ServerConnection.connect("tile_update", self, "on_tile_update") + yield(ServerConnection.join_world_async(), "completed") + +func on_tile_update(tile_data): + print(tile_data) diff --git a/server/plugin/control/control.go b/server/plugin/control/control.go index cd6dc87..73702e9 100644 --- a/server/plugin/control/control.go +++ b/server/plugin/control/control.go @@ -3,8 +3,14 @@ package control import ( "context" "database/sql" - "github.com/heroiclabs/nakama-common/runtime" + "github.com/josephbmanley/family/server/plugin/gamemap" +) + +type OpCode int64 + +const ( + OpCodeTileUpdate = 1 ) type Match struct{} @@ -12,20 +18,19 @@ type Match struct{} type MatchState struct { presences map[string]runtime.Presence inputs map[string]string - positions map[string]string - jumps map[string]string - colors map[string]string + positions map[string]map[string]int names map[string]string + worldMap *gamemap.WorldMap } func (m *Match) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, params map[string]interface{}) (interface{}, int, string) { + state := &MatchState{ presences: map[string]runtime.Presence{}, inputs: map[string]string{}, - positions: map[string]string{}, - jumps: map[string]string{}, - colors: map[string]string{}, + positions: map[string]map[string]int{}, names: map[string]string{}, + worldMap: gamemap.IntializeMap(), } tickRate := 10 label := "{\"name\": \"Game World\"}" @@ -47,6 +52,20 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB mState, _ := state.(*MatchState) for _, precense := range presences { mState.presences[precense.GetUserId()] = precense + + mState.positions[precense.GetUserId()] = map[string]int{"x": 16, "y": 16} + + mState.names[precense.GetUserId()] = "User" + + if regionData, err := mState.worldMap.GetJsonRegion(16-8, 16+8, 16-8, 16+8); err != nil { + logger.Error(err.Error()) + return mState + } else { + if sendErr := dispatcher.BroadcastMessage(OpCodeTileUpdate, regionData, []runtime.Presence{precense}, precense, true); sendErr != nil { + logger.Error(sendErr.Error()) + return mState + } + } } return mState } diff --git a/server/plugin/gamemap/gamemap.go b/server/plugin/gamemap/gamemap.go new file mode 100644 index 0000000..d76ca71 --- /dev/null +++ b/server/plugin/gamemap/gamemap.go @@ -0,0 +1,52 @@ +package gamemap + +import ( + "encoding/json" + "fmt" +) + +type WorldMap struct { + data [][]int + max_x int + max_y int +} + +func (m WorldMap) GetTile(x int, y int) (int, error) { + if x > m.max_x || y > m.max_y { + return -1, fmt.Errorf("Map out of bounds error: %d, %d", x, y) + } + return m.data[x][y], nil +} + +func (m WorldMap) GetJsonRegion(start_x, end_x, start_y, end_y int) ([]byte, error) { + regionMap := make(map[int]map[int]int) + for x := start_x; x < end_x; x++ { + + for y := start_y; y < end_y; y++ { + if result, err := m.GetTile(x, y); err != nil { + return nil, err + } else { + regionMap[x][y] = result + } + } + } + + jsonString, err := json.Marshal(regionMap) + return jsonString, err +} + +func IntializeMap() *WorldMap { + worldMap := new(WorldMap) + worldMap.max_x = 64 + worldMap.max_y = 64 + for x := 0; x < worldMap.max_x; x++ { + for y := 0; y < worldMap.max_y; y++ { + worldMap.data[x][y] = 0 + } + } + + // Add dot at top left for testing + worldMap.data[0][0] = 1 + + return worldMap +} diff --git a/server/plugin/go.sum b/server/plugin/go.sum index 2015c67..85aeb17 100644 --- a/server/plugin/go.sum +++ b/server/plugin/go.sum @@ -15,6 +15,7 @@ github.com/heroiclabs/nakama-common v1.5.1 h1:ViCm9AvYYdQOCSKEa34SuSQ80JyZOHl6OD github.com/heroiclabs/nakama-common v1.5.1/go.mod h1:nZAXHdeo4SyPlCyf7pU9rCVizxEhBF74gt7teDe/EaQ= github.com/heroiclabs/nakama-common v1.7.2 h1:FQedePGCorBl3tXW4Ro8+XLGbEDQfGrT5Tb07j1UaLc= github.com/josephbmanley/family v0.0.0-20200815220504-0d9d05943cef h1:6oijVkew6eKI1fGE+YMaxmiNlp/hkN9wDpStoid9/ZI= +github.com/josephbmanley/family v0.0.0-20200816202226-abfb0f428423 h1:ynsJFMYkfs3JspzvLCfmPGJwdKY/4QeX457U0+y4J1I= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -42,6 +43,7 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=