所以我使用Firebase和JavaScript制作2D游戏,这里是保存文件的一部分。他们使用JSON来存储数据。
{
"player" : {
"github:123123" : {
"email" : "tester@gmail.com",
"inventory" : {
"slot_1" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_10" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_11" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_12" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_13" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_14" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_15" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_16" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_17" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_18" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_19" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_2" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_20" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_3" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_4" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_5" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_6" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_7" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_8" : {
"item_id" : 0,
"item_qty" : 0
},
"slot_9" : {
"item_id" : 0,
"item_qty" : 0
}
},
"lowercase" : "test",
"map" : 1,
"member_level" : 2,
"signed_up" : 1437261263536,
"uid" : "github:616320",
"username" : "Test",
"version" : "1.0.0",
"x" : 50,
"y" : 20
}
}
}
正如您所看到的,问题在于inventory
的结构。有没有更好的结构方式,所以它更好,更整洁?我已阅读Firebase上的Structuring Data文档但我很感激您的意见。
这也可能不仅适用于库存,也适用于银行以及游戏中需要大量商品插槽的地方。
感谢。
答案 0 :(得分:1)
好。您的版本应该有效,但我会建议以下结构:
{
"email" : "tester@gmail.com",
"inventory" : [{
"id": 0,
"amount": 0
},{
"id": 0,
"amount": 0
},{
"id": 0,
"amount": 0
},{
"id": 0,
"amount": 0
}],
"lowercase" : "test",
"map" : 1,
"memberLevel" : 2,
"signedUp" : 1437261263536,
"uid" : "github:616320",
"username" : "Test",
"version" : "1.0.0",
"x" : 50,
"y" : 20
}
推理: