From bb072bcf62ce8bc15330b12e51de817691e54142 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Wed, 23 Jan 2019 08:02:59 +0100 Subject: [PATCH] working metadata parsing --- coords/convert_test.go | 4 ++++ mapblockparser/metadata.go | 5 +++++ mapblockparser/parse_test.go | 18 ++++++++++++++++++ mapblockparser/testdata/mb-with-metadata.bin | Bin 0 -> 1040 bytes testutils/database.go | 6 ++++++ 5 files changed, 33 insertions(+) create mode 100644 mapblockparser/testdata/mb-with-metadata.bin diff --git a/coords/convert_test.go b/coords/convert_test.go index 15c3e7a..7d546da 100644 --- a/coords/convert_test.go +++ b/coords/convert_test.go @@ -34,3 +34,7 @@ func testCoordConvert(t *testing.T, mb MapBlockCoords) { } } + +func TestZeorCoord(t *testing.T) { + testCoordConvert(t, NewMapBlockCoords(0,0,0)) +} diff --git a/mapblockparser/metadata.go b/mapblockparser/metadata.go index ace9403..fb29ee7 100644 --- a/mapblockparser/metadata.go +++ b/mapblockparser/metadata.go @@ -103,6 +103,9 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) { txt := scanner.Text() offset += len(txt) + 1 + log.WithFields(logrus.Fields{"txt":txt, "position":position}).Info("Parsing inventory") + + if strings.HasPrefix(txt, INVENTORY_START) { pairs := strings.Split(txt, " ") currentInventoryName = &pairs[1] @@ -138,6 +141,8 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) { item.Count = int(val) } + currentInventory.Items = append(currentInventory.Items, item) + } } else if txt == INVENTORY_TERMINATOR { diff --git a/mapblockparser/parse_test.go b/mapblockparser/parse_test.go index ba3ff51..65ad76b 100644 --- a/mapblockparser/parse_test.go +++ b/mapblockparser/parse_test.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "mapserver/coords" + "encoding/json" "strconv" "testing" ) @@ -94,3 +95,20 @@ func TestParse3(t *testing.T) { t.Error(err) } } + +func TestParseMetadata(t *testing.T) { + + data, err := ioutil.ReadFile("testdata/mb-with-metadata.bin") + if err != nil { + t.Error(err) + } + + mb, err := Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0)) + + if err != nil { + t.Error(err) + } + + str, err := json.MarshalIndent(mb, "", " ") + fmt.Println(string(str)) +} diff --git a/mapblockparser/testdata/mb-with-metadata.bin b/mapblockparser/testdata/mb-with-metadata.bin new file mode 100644 index 0000000000000000000000000000000000000000..987b0fd6f9dfbf36bebcafd2b5308dc306d9fd41 GIT binary patch literal 1040 zcmb1P{{NqesbbFCnRj`c90XeY|5Ptw@mj!QHGyvni`4}ojYgrIi_tyL?yx^vaU!>D zU#Hpw?)yE4f=(Q(PuBda6jT=RIW{xy`)r-uV|#?(y|=z|zkJ93_XYL$FRosj{Om@( z@xJ`W+2Y^2qmBFjWY?>m|8O0q;Nic0hriag|NhN){rlX?>(4*mztbErO);eOvRP@U zU8njbXUmU868=+uGX3h#t@h$JxX1oV|5t2K!&ke2`iuKjSR>vue-;00r+J`Ce#QP5 z{GN>0emnei{crW<`MU}U{mWJIcjPabzhCY6ckS=2fcn?_q^{iGwVv$?P^j^5@9(UH z+Q<8(0{;J#FSw}vPxrw0`2tQI#m8nJV=a3$Mn9%O@9Q#anDdFFIwNFj3oId-G-H z=As>*h6_aRJ2XtqFxJ1mB)`~s{<-a2@_zJbJ@_|GZ^@#}L(>y3oln|%DLqbMkLlG- zTe2=%^zI3j^GKebZLm?)Mnui9qQ%5dxR71=TApFH)CWtJ$$d97BbPnB_a@p>`czJU zT6Jns%#3rX-ww~nS~u-Rg@RD-w4&7$Zof0#w5Z7OtCz}_IotCxcZ-T_yAFR4$6Zbqqa@I`S?~4{pk3W((qq^^gm4<}R^Oe^s zeoo-D-58y_`L$8bg4d@c7R}UOT6Di&!#4M_qvP`5-6wx73!Nf;+C`*WVNp}`-T50Q znK@U+rR=Y&ye9i_@f3fV&EY=`FYC1|ymLUOw>y5%yuCelddC%kAbBwx-Y*Tu3mL8y%DEWNcqq>zvDo0+?f-8h z56)sXcr}Op#QVVBXN8R)86xbI0;{Gy@KW6TZU4N_>kWVL1(vfeVgQ3B3=A9$>