Skip to content

Commit

Permalink
[Refactor] Rename packages' name
Browse files Browse the repository at this point in the history
  • Loading branch information
CornWorld committed Feb 6, 2024
1 parent fc185fa commit 8abae74
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/server/api/internal/command/pauser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func PauseCommandStr(userId uint16, str string) (_type.Instruction, error) {
x, _ := strconv.Atoi(c.X)
y, _ := strconv.Atoi(c.Y)
ret = _type.Move{
Position: _type.BlockPosition{X: uint8(x), Y: uint8(y)},
Position: _type.Position{X: uint8(x), Y: uint8(y)},
Towards: _type.MoveTowardsType(c.Towards),
Number: uint16(n),
}
Expand Down
4 changes: 2 additions & 2 deletions packages/server/game_logic/block/base_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type BaseBlock struct {
number uint16
}

func (*BaseBlock) Meta() _type.Meta {
func (*BaseBlock) Meta() _type.BlockMeta {
logrus.Panic("no block meta can be provided")
return _type.Meta{}
return _type.BlockMeta{}
}

func (block *BaseBlock) Number() uint16 {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/game_logic/block/block_blank.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Blank struct {
BaseBlock
}

var BlankMeta = _type.Meta{
var BlankMeta = _type.BlockMeta{
BlockId: 0,
Name: "blank",
Description: "",
Expand All @@ -22,7 +22,7 @@ func init() {
block_manager.Register(BlankMeta, toBlockBlank)
}

func (*Blank) Meta() _type.Meta {
func (*Blank) Meta() _type.BlockMeta {
return BlankMeta
}

Expand Down
4 changes: 2 additions & 2 deletions packages/server/game_logic/block/block_castle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Castle struct {
BaseBuilding
}

var CastleMeta = _type.Meta{
var CastleMeta = _type.BlockMeta{
BlockId: 3,
Name: "castle",
Description: "",
Expand All @@ -34,6 +34,6 @@ func toBlockCastle(b _type.Block) _type.Block {
return _type.Block(&ret)
}

func (*Castle) Meta() _type.Meta {
func (*Castle) Meta() _type.BlockMeta {
return CastleMeta
}
4 changes: 2 additions & 2 deletions packages/server/game_logic/block/block_king.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type King struct {
originalOwnerId uint16
}

var KingMeta = _type.Meta{
var KingMeta = _type.BlockMeta{
BlockId: 2,
Name: "king",
Description: "",
Expand All @@ -35,7 +35,7 @@ func (block *King) IsDied() bool {
return block.originalOwnerId != block.ownerId
}

func (*King) Meta() _type.Meta {
func (*King) Meta() _type.BlockMeta {
return KingMeta
}

Expand Down
4 changes: 2 additions & 2 deletions packages/server/game_logic/block/block_mountain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Mountain struct {
BaseBlock
}

var MountainMeta = _type.Meta{
var MountainMeta = _type.BlockMeta{
BlockId: 4,
Name: "mountain",
Description: "",
Expand All @@ -24,7 +24,7 @@ func toBlockMountain(_type.Block) _type.Block {
return _type.Block(&Mountain{})
}

func (*Mountain) Meta() _type.Meta {
func (*Mountain) Meta() _type.BlockMeta {
return MountainMeta
}

Expand Down
4 changes: 2 additions & 2 deletions packages/server/game_logic/block/block_soldier.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Soldier struct {
BaseBlock
}

var SoldierMeta = _type.Meta{
var SoldierMeta = _type.BlockMeta{
BlockId: 1,
Name: "soldier",
Description: "",
Expand All @@ -29,7 +29,7 @@ func toBlockSoldier(b _type.Block) _type.Block {
return _type.Block(&ret)
}

func (*Soldier) Meta() _type.Meta {
func (*Soldier) Meta() _type.BlockMeta {
return SoldierMeta
}

Expand Down
4 changes: 2 additions & 2 deletions packages/server/game_logic/block_manager/base_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type BaseBlock struct {
number uint16
}

func (*BaseBlock) Meta() _type.Meta {
func (*BaseBlock) Meta() _type.BlockMeta {
logrus.Panic("no block meta can be provided")
return _type.Meta{}
return _type.BlockMeta{}
}

func (block *BaseBlock) Number() uint16 {
Expand Down
6 changes: 3 additions & 3 deletions packages/server/game_logic/block_manager/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ type tranFunc func(_type.Block) _type.Block

var transBlockTypeFunc map[uint8]tranFunc
var GetBlockIdByName map[string]uint8
var GetMetaById map[uint8]_type.Meta
var GetMetaById map[uint8]_type.BlockMeta

func Register(meta _type.Meta, transFunc tranFunc) {
func Register(meta _type.BlockMeta, transFunc tranFunc) {
if transBlockTypeFunc == nil {
transBlockTypeFunc = make(map[uint8]tranFunc)
}
if GetBlockIdByName == nil {
GetBlockIdByName = make(map[string]uint8)
}
if GetMetaById == nil {
GetMetaById = make(map[uint8]_type.Meta)
GetMetaById = make(map[uint8]_type.BlockMeta)
}

GetBlockIdByName[meta.Name] = meta.BlockId
Expand Down
4 changes: 2 additions & 2 deletions packages/server/game_logic/game_def/block.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package _type

type Meta struct {
type BlockMeta struct {
Name string
Description string
BlockId uint8
Expand All @@ -27,7 +27,7 @@ type Block interface {
// MoveTo Ret: a new block to replace this place
MoveTo(BlockVal) Block

Meta() Meta
Meta() BlockMeta
}

type Position struct{ X, Y uint8 }
Expand Down
6 changes: 1 addition & 5 deletions packages/server/game_logic/game_def/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ const (
MoveTowardsDown MoveTowardsType = "down"
)

type BlockPosition struct {
X, Y uint8
}

type Move struct {
Position BlockPosition
Position Position
Towards MoveTowardsType
Number uint16
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/utils/pkg/data_source/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestLocal_Game(t *testing.T) {
t.Run("update instruction", func(t *testing.T) {
u := l.GamePool[id].UserList[0]
ins := _type.Move{
Position: _type.BlockPosition{1, 1},
Position: _type.Position{1, 1},
Towards: "down",
Number: 1,
}
Expand Down

0 comments on commit 8abae74

Please sign in to comment.