From 5295b31194c52667110dbfb0322b50fea109454b Mon Sep 17 00:00:00 2001 From: CornWorld Date: Wed, 7 Feb 2024 00:12:47 +0800 Subject: [PATCH] [Clean] Renormalize package references --- .../server/api/internal/command/pauser.go | 14 +++---- .../server/api/internal/receiver/context.go | 2 +- packages/server/api/internal/receiver/file.go | 16 +++---- .../server/game_logic/block/base_block.go | 12 +++--- .../server/game_logic/block/base_building.go | 8 ++-- .../server/game_logic/block/block_blank.go | 16 +++---- .../server/game_logic/block/block_castle.go | 10 ++--- .../server/game_logic/block/block_king.go | 12 +++--- .../server/game_logic/block/block_mountain.go | 12 +++--- .../server/game_logic/block/block_soldier.go | 16 +++---- .../game_logic/block_manager/base_block.go | 12 +++--- .../game_logic/block_manager/register.go | 12 +++--- packages/server/game_logic/game.go | 4 +- packages/server/game_logic/game_def/block.go | 2 +- .../server/game_logic/game_def/game_mode.go | 2 +- .../server/game_logic/game_def/instruction.go | 2 +- packages/server/game_logic/game_def/user.go | 2 +- packages/server/game_logic/map/map.go | 42 +++++++++---------- packages/server/game_logic/map/map_test.go | 10 ++--- .../server/judge_pool/internal/judge/judge.go | 35 ++++++++-------- packages/server/judge_pool/pool.go | 6 +-- packages/server/main.go | 4 +- packages/server/main_test.go | 4 +- .../utils/pkg/data_source/local/local.go | 26 ++++++------ .../utils/pkg/data_source/local/local_test.go | 34 +++++++-------- .../server/utils/pkg/data_source/pg/pg.go | 16 +++---- packages/server/utils/pkg/data_source/temp.go | 12 +++--- 27 files changed, 172 insertions(+), 171 deletions(-) diff --git a/packages/server/api/internal/command/pauser.go b/packages/server/api/internal/command/pauser.go index fb1e72c..3337f66 100644 --- a/packages/server/api/internal/command/pauser.go +++ b/packages/server/api/internal/command/pauser.go @@ -8,9 +8,9 @@ import ( "strings" ) -func PauseCommandStr(userId uint16, str string) (_type.Instruction, error) { +func PauseCommandStr(userId uint16, str string) (game_def.Instruction, error) { var err error = nil - ret := _type.Instruction(nil) + ret := game_def.Instruction(nil) args := strings.Split(str, " ") v := validator.New() switch args[0] { @@ -28,9 +28,9 @@ func PauseCommandStr(userId uint16, str string) (_type.Instruction, error) { n, _ := strconv.Atoi(c.Number) x, _ := strconv.Atoi(c.X) y, _ := strconv.Atoi(c.Y) - ret = _type.Move{ - Position: _type.Position{X: uint8(x), Y: uint8(y)}, - Towards: _type.MoveTowardsType(c.Towards), + ret = game_def.Move{ + Position: game_def.Position{X: uint8(x), Y: uint8(y)}, + Towards: game_def.MoveTowardsType(c.Towards), Number: uint16(n), } } else { @@ -51,7 +51,7 @@ func PauseCommandStr(userId uint16, str string) (_type.Instruction, error) { if c.Status == "true" { s = true } - ret = _type.ForceStart{ + ret = game_def.ForceStart{ UserId: userId, Status: s, } @@ -66,7 +66,7 @@ func PauseCommandStr(userId uint16, str string) (_type.Instruction, error) { case "Surrender": { if len(args)-1 == 0 { - ret = _type.Surrender{UserId: userId} + ret = game_def.Surrender{UserId: userId} } else { err = fmt.Errorf("argument number not right") } diff --git a/packages/server/api/internal/receiver/context.go b/packages/server/api/internal/receiver/context.go index e74b7f7..fedcc5b 100644 --- a/packages/server/api/internal/receiver/context.go +++ b/packages/server/api/internal/receiver/context.go @@ -9,7 +9,7 @@ import ( type Context struct { context.Context Game *game_logic.Game - User _type.User + User game_def.User Command chan string Message chan string } diff --git a/packages/server/api/internal/receiver/file.go b/packages/server/api/internal/receiver/file.go index 2cec69f..cf3d809 100644 --- a/packages/server/api/internal/receiver/file.go +++ b/packages/server/api/internal/receiver/file.go @@ -33,9 +33,9 @@ func NewFileReceiver(pool *judge_pool.Pool) { logrus.Infof("start game by reply file #%d", r.Id) g := &game_logic.Game{ Map: r.Map, - Mode: _type.Mode1v1, + Mode: game_def.Mode1v1, Id: game_logic.Id(index + 1e3), - UserList: []_type.User{}, + UserList: []game_def.User{}, CreateTime: time.Now().UnixMicro(), Status: game_logic.StatusWaiting, RoundNum: 0, @@ -58,7 +58,7 @@ func NewFileReceiver(pool *judge_pool.Pool) { } type command struct { - User _type.User + User game_def.User Ins []string } @@ -112,10 +112,10 @@ func LoadFile() []reply { cmdStr := strings.Split(t[1], "\n") cmd := command{ - User: _type.User{ + User: game_def.User{ Name: name, UserId: uint16(userId), - Status: _type.UserStatusConnected, + Status: game_def.UserStatusConnected, TeamId: uint8(userId) - 1, ForceStartStatus: false, }, @@ -151,7 +151,7 @@ func fakePlayer(ctx *Context, c []string) { playerLogger.Infof("Command(tot: %d) runs out, quit", len(c)) ticker.Stop() player := ctx.User - player.Status = _type.UserStatusDisconnected + player.Status = game_def.UserStatusDisconnected data.SetUserStatus(ctx.Game.Id, player) } if ctx.Game.RoundNum > currentRound { @@ -180,7 +180,7 @@ func fakePlayer(ctx *Context, c []string) { func receiver(ctx *Context) { //ctx.User.Name = strconv.Itoa(int(ctx.User.UserId)) // DEBUG ONLY, avoiding strange username from `gioreply` file - ctx.User.Status = _type.UserStatusConnected + ctx.User.Status = game_def.UserStatusConnected data.SetUserStatus(ctx.Game.Id, ctx.User) receiverLogger := logrus.WithFields(logrus.Fields{ @@ -189,7 +189,7 @@ func receiver(ctx *Context) { receiverLogger.Infof("user join") defer func() { - ctx.User.Status = _type.UserStatusDisconnected + ctx.User.Status = game_def.UserStatusDisconnected data.SetUserStatus(ctx.Game.Id, ctx.User) receiverLogger.Infof("user quit") }() diff --git a/packages/server/game_logic/block/base_block.go b/packages/server/game_logic/block/base_block.go index 1c0bbb1..b189864 100644 --- a/packages/server/game_logic/block/base_block.go +++ b/packages/server/game_logic/block/base_block.go @@ -5,16 +5,16 @@ import ( "server/game_logic/game_def" ) -var _ _type.Block = (*BaseBlock)(nil) +var _ game_def.Block = (*BaseBlock)(nil) type BaseBlock struct { ownerId uint16 number uint16 } -func (*BaseBlock) Meta() _type.BlockMeta { +func (*BaseBlock) Meta() game_def.BlockMeta { logrus.Panic("no block meta can be provided") - return _type.BlockMeta{} + return game_def.BlockMeta{} } func (block *BaseBlock) Number() uint16 { @@ -29,14 +29,14 @@ func (*BaseBlock) RoundStart(_ uint16) {} func (*BaseBlock) RoundEnd(_ uint16) {} -func (*BaseBlock) GetMoveStatus() _type.MoveStatus { - return _type.MoveStatus{} +func (*BaseBlock) GetMoveStatus() game_def.MoveStatus { + return game_def.MoveStatus{} } func (*BaseBlock) MoveFrom(_ uint16) uint16 { return 0 } -func (*BaseBlock) MoveTo(_type.BlockVal) _type.Block { +func (*BaseBlock) MoveTo(game_def.BlockVal) game_def.Block { return nil } diff --git a/packages/server/game_logic/block/base_building.go b/packages/server/game_logic/block/base_building.go index 5a3b328..372533f 100644 --- a/packages/server/game_logic/block/base_building.go +++ b/packages/server/game_logic/block/base_building.go @@ -4,7 +4,7 @@ import ( "server/game_logic/game_def" ) -var _ _type.Block = (*BaseBuilding)(nil) +var _ game_def.Block = (*BaseBuilding)(nil) type BaseBuilding struct { BaseBlock @@ -20,8 +20,8 @@ func (block *BaseBuilding) RoundStart(_ uint16) { } } -func (*BaseBuilding) GetMoveStatus() _type.MoveStatus { - return _type.MoveStatus{AllowMoveFrom: true, AllowMoveTo: true} +func (*BaseBuilding) GetMoveStatus() game_def.MoveStatus { + return game_def.MoveStatus{AllowMoveFrom: true, AllowMoveTo: true} } func (block *BaseBuilding) MoveFrom(number uint16) uint16 { @@ -36,7 +36,7 @@ func (block *BaseBuilding) MoveFrom(number uint16) uint16 { return ret } -func (block *BaseBuilding) MoveTo(info _type.BlockVal) _type.Block { +func (block *BaseBuilding) MoveTo(info game_def.BlockVal) game_def.Block { if block.ownerId != info.OwnerId { if block.number < info.Number { block.ownerId = info.OwnerId diff --git a/packages/server/game_logic/block/block_blank.go b/packages/server/game_logic/block/block_blank.go index e4b8623..2a2160f 100644 --- a/packages/server/game_logic/block/block_blank.go +++ b/packages/server/game_logic/block/block_blank.go @@ -5,13 +5,13 @@ import ( "server/game_logic/game_def" ) -var _ _type.Block = (*Blank)(nil) +var _ game_def.Block = (*Blank)(nil) type Blank struct { BaseBlock } -var BlankMeta = _type.BlockMeta{ +var BlankMeta = game_def.BlockMeta{ BlockId: 0, Name: "blank", Description: "", @@ -22,18 +22,18 @@ func init() { block_manager.Register(BlankMeta, toBlockBlank) } -func (*Blank) Meta() _type.BlockMeta { +func (*Blank) Meta() game_def.BlockMeta { return BlankMeta } -func (*Blank) GetMoveStatus() _type.MoveStatus { - return _type.MoveStatus{false, true} +func (*Blank) GetMoveStatus() game_def.MoveStatus { + return game_def.MoveStatus{false, true} } -func toBlockBlank(_type.Block) _type.Block { - return _type.Block(&Blank{}) +func toBlockBlank(game_def.Block) game_def.Block { + return game_def.Block(&Blank{}) } -func (b *Blank) MoveTo(_type.BlockVal) _type.Block { +func (b *Blank) MoveTo(game_def.BlockVal) game_def.Block { return toBlockSoldier(b) } diff --git a/packages/server/game_logic/block/block_castle.go b/packages/server/game_logic/block/block_castle.go index 01d5e91..2470d41 100644 --- a/packages/server/game_logic/block/block_castle.go +++ b/packages/server/game_logic/block/block_castle.go @@ -6,13 +6,13 @@ import ( "server/game_logic/game_def" ) -var _ _type.Block = (*Castle)(nil) +var _ game_def.Block = (*Castle)(nil) type Castle struct { BaseBuilding } -var CastleMeta = _type.BlockMeta{ +var CastleMeta = game_def.BlockMeta{ BlockId: 3, Name: "castle", Description: "", @@ -23,7 +23,7 @@ func init() { block_manager.Register(CastleMeta, toBlockCastle) } -func toBlockCastle(b _type.Block) _type.Block { +func toBlockCastle(b game_def.Block) game_def.Block { var ret Castle if b.Number() == 0 { ret.number = uint16(30) + uint16(rand.Intn(30)) @@ -31,9 +31,9 @@ func toBlockCastle(b _type.Block) _type.Block { ret.number = b.Number() } ret.ownerId = b.OwnerId() - return _type.Block(&ret) + return game_def.Block(&ret) } -func (*Castle) Meta() _type.BlockMeta { +func (*Castle) Meta() game_def.BlockMeta { return CastleMeta } diff --git a/packages/server/game_logic/block/block_king.go b/packages/server/game_logic/block/block_king.go index 02f93db..72fe10f 100644 --- a/packages/server/game_logic/block/block_king.go +++ b/packages/server/game_logic/block/block_king.go @@ -5,14 +5,14 @@ import ( "server/game_logic/game_def" ) -var _ _type.Block = (*King)(nil) +var _ game_def.Block = (*King)(nil) type King struct { BaseBuilding originalOwnerId uint16 } -var KingMeta = _type.BlockMeta{ +var KingMeta = game_def.BlockMeta{ BlockId: 2, Name: "king", Description: "", @@ -23,23 +23,23 @@ func init() { block_manager.Register(KingMeta, toBlockKing) } -func toBlockKing(b _type.Block) _type.Block { +func toBlockKing(b game_def.Block) game_def.Block { var ret King ret.number = b.Number() ret.ownerId = b.OwnerId() ret.originalOwnerId = b.OwnerId() - return _type.Block(&ret) + return game_def.Block(&ret) } func (block *King) IsDied() bool { return block.originalOwnerId != block.ownerId } -func (*King) Meta() _type.BlockMeta { +func (*King) Meta() game_def.BlockMeta { return KingMeta } -func (block *King) MoveTo(info _type.BlockVal) _type.Block { +func (block *King) MoveTo(info game_def.BlockVal) game_def.Block { if !block.IsDied() { block.BaseBuilding.MoveTo(info) } diff --git a/packages/server/game_logic/block/block_mountain.go b/packages/server/game_logic/block/block_mountain.go index 4abdcf0..d8a8c8a 100644 --- a/packages/server/game_logic/block/block_mountain.go +++ b/packages/server/game_logic/block/block_mountain.go @@ -9,7 +9,7 @@ type Mountain struct { BaseBlock } -var MountainMeta = _type.BlockMeta{ +var MountainMeta = game_def.BlockMeta{ BlockId: 4, Name: "mountain", Description: "", @@ -20,14 +20,14 @@ func init() { block_manager.Register(MountainMeta, toBlockMountain) } -func toBlockMountain(_type.Block) _type.Block { - return _type.Block(&Mountain{}) +func toBlockMountain(game_def.Block) game_def.Block { + return game_def.Block(&Mountain{}) } -func (*Mountain) Meta() _type.BlockMeta { +func (*Mountain) Meta() game_def.BlockMeta { return MountainMeta } -func (*Mountain) GetMoveStatus() _type.MoveStatus { // same as `BaseBlock`'s, in order to remain the function - return _type.MoveStatus{false, false} +func (*Mountain) GetMoveStatus() game_def.MoveStatus { // same as `BaseBlock`'s, in order to remain the function + return game_def.MoveStatus{false, false} } diff --git a/packages/server/game_logic/block/block_soldier.go b/packages/server/game_logic/block/block_soldier.go index 09c79d5..d6ca6f6 100644 --- a/packages/server/game_logic/block/block_soldier.go +++ b/packages/server/game_logic/block/block_soldier.go @@ -5,13 +5,13 @@ import ( "server/game_logic/game_def" ) -var _ _type.Block = (*Soldier)(nil) +var _ game_def.Block = (*Soldier)(nil) type Soldier struct { BaseBlock } -var SoldierMeta = _type.BlockMeta{ +var SoldierMeta = game_def.BlockMeta{ BlockId: 1, Name: "soldier", Description: "", @@ -22,14 +22,14 @@ func init() { block_manager.Register(SoldierMeta, toBlockSoldier) } -func toBlockSoldier(b _type.Block) _type.Block { +func toBlockSoldier(b game_def.Block) game_def.Block { var ret Soldier ret.number = b.Number() ret.ownerId = b.OwnerId() - return _type.Block(&ret) + return game_def.Block(&ret) } -func (*Soldier) Meta() _type.BlockMeta { +func (*Soldier) Meta() game_def.BlockMeta { return SoldierMeta } @@ -43,8 +43,8 @@ func (block *Soldier) RoundStart(roundNum uint16) { } } -func (*Soldier) GetMoveStatus() _type.MoveStatus { - return _type.MoveStatus{true, true} +func (*Soldier) GetMoveStatus() game_def.MoveStatus { + return game_def.MoveStatus{true, true} } func (block *Soldier) MoveFrom(number uint16) uint16 { @@ -59,7 +59,7 @@ func (block *Soldier) MoveFrom(number uint16) uint16 { return ret } -func (block *Soldier) MoveTo(info _type.BlockVal) _type.Block { +func (block *Soldier) MoveTo(info game_def.BlockVal) game_def.Block { if block.ownerId != info.OwnerId { if block.number < info.Number { block.ownerId = info.OwnerId diff --git a/packages/server/game_logic/block_manager/base_block.go b/packages/server/game_logic/block_manager/base_block.go index 1e84438..cba35c9 100644 --- a/packages/server/game_logic/block_manager/base_block.go +++ b/packages/server/game_logic/block_manager/base_block.go @@ -9,16 +9,16 @@ import ( "server/game_logic/game_def" ) -var _ _type.Block = (*BaseBlock)(nil) +var _ game_def.Block = (*BaseBlock)(nil) type BaseBlock struct { ownerId uint16 number uint16 } -func (*BaseBlock) Meta() _type.BlockMeta { +func (*BaseBlock) Meta() game_def.BlockMeta { logrus.Panic("no block meta can be provided") - return _type.BlockMeta{} + return game_def.BlockMeta{} } func (block *BaseBlock) Number() uint16 { @@ -33,14 +33,14 @@ func (*BaseBlock) RoundStart(_ uint16) {} func (*BaseBlock) RoundEnd(_ uint16) {} -func (*BaseBlock) GetMoveStatus() _type.MoveStatus { - return _type.MoveStatus{} +func (*BaseBlock) GetMoveStatus() game_def.MoveStatus { + return game_def.MoveStatus{} } func (*BaseBlock) MoveFrom(_ uint16) uint16 { return 0 } -func (*BaseBlock) MoveTo(_type.BlockVal) _type.Block { +func (*BaseBlock) MoveTo(game_def.BlockVal) game_def.Block { return nil } diff --git a/packages/server/game_logic/block_manager/register.go b/packages/server/game_logic/block_manager/register.go index f5dbade..e019035 100644 --- a/packages/server/game_logic/block_manager/register.go +++ b/packages/server/game_logic/block_manager/register.go @@ -5,13 +5,13 @@ import ( "server/game_logic/game_def" ) -type tranFunc func(_type.Block) _type.Block +type tranFunc func(game_def.Block) game_def.Block var transBlockTypeFunc map[uint8]tranFunc var GetBlockIdByName map[string]uint8 -var GetMetaById map[uint8]_type.BlockMeta +var GetMetaById map[uint8]game_def.BlockMeta -func Register(meta _type.BlockMeta, transFunc tranFunc) { +func Register(meta game_def.BlockMeta, transFunc tranFunc) { if transBlockTypeFunc == nil { transBlockTypeFunc = make(map[uint8]tranFunc) } @@ -19,7 +19,7 @@ func Register(meta _type.BlockMeta, transFunc tranFunc) { GetBlockIdByName = make(map[string]uint8) } if GetMetaById == nil { - GetMetaById = make(map[uint8]_type.BlockMeta) + GetMetaById = make(map[uint8]game_def.BlockMeta) } GetBlockIdByName[meta.Name] = meta.BlockId @@ -28,7 +28,7 @@ func Register(meta _type.BlockMeta, transFunc tranFunc) { logrus.Println("Registered a block game_def", "id:", meta.BlockId, " name:", meta.Name, " description:", meta.Description) } -func ToBlockByTypeId(typeId uint8, block _type.Block) _type.Block { +func ToBlockByTypeId(typeId uint8, block game_def.Block) game_def.Block { transFunc, err := transBlockTypeFunc[typeId] if !err { logrus.Warningln("Get an unknown blockTypeId", typeId) @@ -37,6 +37,6 @@ func ToBlockByTypeId(typeId uint8, block _type.Block) _type.Block { return transFunc(block) } -func NewBlock(typeId uint8, number uint16, ownerId uint16) _type.Block { +func NewBlock(typeId uint8, number uint16, ownerId uint16) game_def.Block { return ToBlockByTypeId(typeId, &BaseBlock{number: number, ownerId: ownerId}) } diff --git a/packages/server/game_logic/game.go b/packages/server/game_logic/game.go index 9a67d39..96449aa 100644 --- a/packages/server/game_logic/game.go +++ b/packages/server/game_logic/game.go @@ -16,9 +16,9 @@ const ( type Game struct { Map *_map.Map - Mode _type.Mode + Mode game_def.Mode Id Id - UserList []_type.User + UserList []game_def.User CreateTime int64 Status Status RoundNum uint16 diff --git a/packages/server/game_logic/game_def/block.go b/packages/server/game_logic/game_def/block.go index 16c10a4..70b6ae6 100644 --- a/packages/server/game_logic/game_def/block.go +++ b/packages/server/game_logic/game_def/block.go @@ -1,4 +1,4 @@ -package _type +package game_def type BlockMeta struct { Name string diff --git a/packages/server/game_logic/game_def/game_mode.go b/packages/server/game_logic/game_def/game_mode.go index 3e38e36..fafa3f0 100644 --- a/packages/server/game_logic/game_def/game_mode.go +++ b/packages/server/game_logic/game_def/game_mode.go @@ -1,4 +1,4 @@ -package _type +package game_def type Mode struct { MaxUserNum uint8 diff --git a/packages/server/game_logic/game_def/instruction.go b/packages/server/game_logic/game_def/instruction.go index 23ce770..6444133 100644 --- a/packages/server/game_logic/game_def/instruction.go +++ b/packages/server/game_logic/game_def/instruction.go @@ -1,4 +1,4 @@ -package _type +package game_def type Instruction interface{} diff --git a/packages/server/game_logic/game_def/user.go b/packages/server/game_logic/game_def/user.go index 13c8595..8fe03fe 100644 --- a/packages/server/game_logic/game_def/user.go +++ b/packages/server/game_logic/game_def/user.go @@ -1,4 +1,4 @@ -package _type +package game_def type UserStatus uint8 diff --git a/packages/server/game_logic/map/map.go b/packages/server/game_logic/map/map.go index d77253b..98e435b 100644 --- a/packages/server/game_logic/map/map.go +++ b/packages/server/game_logic/map/map.go @@ -18,7 +18,7 @@ type mapInfo struct { } type Map struct { - Blocks [][]_type.Block + Blocks [][]game_def.Block mapInfo } @@ -30,11 +30,11 @@ func (p *Map) Id() uint32 { return p.id } -func (p *Map) GetBlock(position _type.Position) _type.Block { +func (p *Map) GetBlock(position game_def.Position) game_def.Block { return p.Blocks[position.Y-1][position.X-1] } -func (p *Map) SetBlock(position _type.Position, block _type.Block) { +func (p *Map) SetBlock(position game_def.Position, block game_def.Block) { p.Blocks[position.Y-1][position.X-1] = block } @@ -72,7 +72,7 @@ func CreateMapWithInfo(mapId uint32, size MapSize) *Map { } } -func DebugOutput(p *Map, f func(_type.Block) uint16) { // Only for debugging +func DebugOutput(p *Map, f func(game_def.Block) uint16) { // Only for debugging tmp := "" ex := func(i uint16) string { ex := "" @@ -97,41 +97,41 @@ func DebugOutput(p *Map, f func(_type.Block) uint16) { // Only for debugging logrus.Tracef("\n%s\n", tmp) } -func isPositionLegal(position _type.Position, size MapSize) bool { +func isPositionLegal(position game_def.Position, size MapSize) bool { return 1 <= position.X && position.X <= size.W && 1 <= position.Y && position.Y <= size.H } -func (p *Map) Move(ins _type.Move) bool { +func (p *Map) Move(ins game_def.Move) bool { var offsetX, offsetY int switch ins.Towards { - case _type.MoveTowardsDown: + case game_def.MoveTowardsDown: { offsetX = 0 offsetY = 1 } - case _type.MoveTowardsUp: + case game_def.MoveTowardsUp: { offsetX = 0 offsetY = -1 } - case _type.MoveTowardsLeft: + case game_def.MoveTowardsLeft: { offsetX = -1 offsetY = 0 } - case _type.MoveTowardsRight: + case game_def.MoveTowardsRight: { offsetX = 1 offsetY = 0 } } - instructionPosition := _type.Position{X: ins.Position.X, Y: ins.Position.Y} + instructionPosition := game_def.Position{X: ins.Position.X, Y: ins.Position.Y} if !isPositionLegal(instructionPosition, p.size) { return false } - newPosition := _type.Position{X: uint8(int(ins.Position.X) + offsetX), Y: uint8(int(ins.Position.Y) + offsetY)} + newPosition := game_def.Position{X: uint8(int(ins.Position.X) + offsetX), Y: uint8(int(ins.Position.Y) + offsetY)} // It won't overflow 'cause the min value is 0 if !isPositionLegal(newPosition, p.size) { return false @@ -159,9 +159,9 @@ func (p *Map) Move(ins _type.Move) bool { return false } - var toBlockNew _type.Block + var toBlockNew game_def.Block hasMovedNum := thisBlock.MoveFrom(ins.Number) - toBlockNew = toBlock.MoveTo(_type.BlockVal{Number: hasMovedNum, OwnerId: thisBlock.OwnerId()}) + toBlockNew = toBlock.MoveTo(game_def.BlockVal{Number: hasMovedNum, OwnerId: thisBlock.OwnerId()}) if toBlockNew != nil { p.SetBlock(newPosition, toBlockNew) } @@ -176,9 +176,9 @@ func Str2GameMap(mapId uint32, originalMapStr string) *Map { return nil } size := MapSize{W: uint8(len(result[0])), H: uint8(len(result))} - ret := make([][]_type.Block, size.H) + ret := make([][]game_def.Block, size.H) for rowNum, row := range result { - ret[rowNum] = make([]_type.Block, size.W) + ret[rowNum] = make([]game_def.Block, size.W) for colNum, typeId := range row { ret[rowNum][colNum] = block_manager.NewBlock(typeId, 0, 0) } @@ -196,9 +196,9 @@ func FullStr2GameMap(mapId uint32, originalMapStr string) *Map { return nil } size := MapSize{W: uint8(len(result[0])), H: uint8(len(result))} - ret := make([][]_type.Block, size.H) + ret := make([][]game_def.Block, size.H) for rowNum, row := range result { - ret[rowNum] = make([]_type.Block, size.W) + ret[rowNum] = make([]game_def.Block, size.W) for colNum, blockInfo := range row { blockId := blockInfo[0] ownerId := blockInfo[1] @@ -259,17 +259,17 @@ func JsonStrToMap(jsonStr string) *Map { res.Mappings.Owner = append([]uint16{0}, res.Mappings.Owner...) } - var blocks [][]_type.Block + var blocks [][]game_def.Block if (res.Number != nil && len(res.Type) != len(res.Number)) || (res.Owner != nil && len(res.Type) != len(res.Owner)) { logrus.Panic("original block game_def, number, owner id must have the same size") } - blocks = make([][]_type.Block, len(res.Type)) + blocks = make([][]game_def.Block, len(res.Type)) for i, v := range res.Type { if (res.Number != nil && len(v) != len(res.Number[i])) || (res.Owner != nil && len(v) != len(res.Owner[i])) { logrus.Panic("original block game_def, number, owner id must have the same size") } - blocks[i] = make([]_type.Block, len(v)) + blocks[i] = make([]game_def.Block, len(v)) for j, typeId := range v { n := uint16(0) diff --git a/packages/server/game_logic/map/map_test.go b/packages/server/game_logic/map/map_test.go index 7c2c85f..871d4f2 100644 --- a/packages/server/game_logic/map/map_test.go +++ b/packages/server/game_logic/map/map_test.go @@ -24,7 +24,7 @@ func TestConvJsonStrMap(t *testing.T) { jsonStr: `{"mappings":{"block":["blank"]},"game_def":[[0,0,0]]}`, }, want: &Map{ - [][]_type.Block{ + [][]game_def.Block{ { &block.Blank{}, &block.Blank{}, @@ -43,7 +43,7 @@ func TestConvJsonStrMap(t *testing.T) { jsonStr: `{"mappings":{"block":["blank"],"owner":[1,2]},"game_def":[[0,0,0]]}`, }, want: &Map{ - [][]_type.Block{ + [][]game_def.Block{ { &block.Blank{}, &block.Blank{}, @@ -62,7 +62,7 @@ func TestConvJsonStrMap(t *testing.T) { jsonStr: `{"mappings":{"block":["blank"]},"game_def":[[0,0,0]],"owner":[[1,1,1]]}`, }, want: &Map{ - [][]_type.Block{ + [][]game_def.Block{ { &block.Blank{}, &block.Blank{}, @@ -81,7 +81,7 @@ func TestConvJsonStrMap(t *testing.T) { jsonStr: `{"mappings":{"block":["soldier"],"owner":[1]},"game_def":[[0,0,0]],"owner":[[1,1,1]]}`, }, want: &Map{ - [][]_type.Block{ + [][]game_def.Block{ { block_manager.NewBlock(1, 0, 1), block_manager.NewBlock(1, 0, 1), @@ -100,7 +100,7 @@ func TestConvJsonStrMap(t *testing.T) { jsonStr: `{"mappings":{"block":["soldier"],"owner":[1]},"game_def":[[0,0,0]],"owner":[[1,1,1]],"number":[[1,2,255]]}`, }, want: &Map{ - [][]_type.Block{ + [][]game_def.Block{ { block_manager.NewBlock(1, 1, 1), block_manager.NewBlock(1, 2, 1), diff --git a/packages/server/judge_pool/internal/judge/judge.go b/packages/server/judge_pool/internal/judge/judge.go index 270ae2b..b67315b 100644 --- a/packages/server/judge_pool/internal/judge/judge.go +++ b/packages/server/judge_pool/internal/judge/judge.go @@ -7,8 +7,8 @@ import ( "server/game_logic/block_manager" "server/game_logic/game_def" "server/game_logic/map" - data_source "server/utils/pkg/data_source" - game_temp_pool "server/utils/pkg/game_temp_pool" + "server/utils/pkg/data_source" + "server/utils/pkg/game_temp_pool" "time" ) @@ -120,7 +120,7 @@ func judgeWorking(j *GameJudge) { g.Map.RoundStart(g.RoundNum) data.SetGameMap(j.gameId, g.Map) - _map.DebugOutput(g.Map, func(block _type.Block) uint16 { + _map.DebugOutput(g.Map, func(block game_def.Block) uint16 { return uint16(block.Meta().BlockId) }) // TODO } @@ -128,13 +128,13 @@ func judgeWorking(j *GameJudge) { } } -func getKingPos(g *game_logic.Game) []_type.Position { - var kingPos []_type.Position +func getKingPos(g *game_logic.Game) []game_def.Position { + var kingPos []game_def.Position for y := uint8(1); y <= g.Map.Size().H; y++ { for x := uint8(1); x <= g.Map.Size().W; x++ { - b := g.Map.GetBlock(_type.Position{X: x, Y: y}) + b := g.Map.GetBlock(game_def.Position{X: x, Y: y}) if b.Meta().BlockId == block.KingMeta.BlockId { - kingPos = append(kingPos, _type.Position{X: x, Y: y}) + kingPos = append(kingPos, game_def.Position{X: x, Y: y}) } } } @@ -142,21 +142,22 @@ func getKingPos(g *game_logic.Game) []_type.Position { } // judgeGame TODO: Add unit test -func judgeGame(g *game_logic.Game, kingPos []_type.Position) game_logic.Status { +func judgeGame(g *game_logic.Game, kingPos []game_def.Position) game_logic.Status { // Check online player number onlinePlayerNum := uint8(0) for _, u := range g.UserList { - if u.Status == _type.UserStatusConnected { + if u.Status == game_def.UserStatusConnected { onlinePlayerNum++ } } + if onlinePlayerNum <= 0 { return game_logic.StatusEnd } if onlinePlayerNum == 1 { // TODO: Announce game-over for _, u := range g.UserList { - if u.Status == _type.UserStatusConnected { + if u.Status == game_def.UserStatusConnected { g.Winner = u.TeamId break } @@ -165,7 +166,7 @@ func judgeGame(g *game_logic.Game, kingPos []_type.Position) game_logic.Status { } // Check king status - if g.Mode == _type.Mode1v1 { + if g.Mode == game_def.Mode1v1 { flag := true for _, k := range kingPos { if g.Map.GetBlock(k).Meta().BlockId != block.KingMeta.BlockId { @@ -195,7 +196,7 @@ func judgeGame(g *game_logic.Game, kingPos []_type.Position) game_logic.Status { return game_logic.StatusRunning } -func allocateKing(g *game_logic.Game, kingPos []_type.Position) { +func allocateKing(g *game_logic.Game, kingPos []game_def.Position) { allocatableKingNum := 0 for _, k := range kingPos { if g.Map.GetBlock(k).OwnerId() == 0 { @@ -215,7 +216,7 @@ func allocateKing(g *game_logic.Game, kingPos []_type.Position) { } func allocateTeam(g *game_logic.Game) { - if g.Mode == _type.Mode1v1 { + if g.Mode == game_def.Mode1v1 { for i := range g.UserList { g.UserList[i].TeamId = uint8(i) + 1 } @@ -224,15 +225,15 @@ func allocateTeam(g *game_logic.Game) { } } -func executeInstruction(id game_logic.Id, userId uint16, ins _type.Instruction) bool { +func executeInstruction(id game_logic.Id, userId uint16, ins game_def.Instruction) bool { var ret bool var m *_map.Map switch ins.(type) { - case _type.Move: + case game_def.Move: { - i := ins.(_type.Move) + i := ins.(game_def.Move) m = data.GetCurrentMap(id) - if m.GetBlock(_type.Position(i.Position)).OwnerId() != userId { + if m.GetBlock(i.Position).OwnerId() != userId { return false } ret = m.Move(i) diff --git a/packages/server/judge_pool/pool.go b/packages/server/judge_pool/pool.go index 55d1413..d61f495 100644 --- a/packages/server/judge_pool/pool.go +++ b/packages/server/judge_pool/pool.go @@ -12,7 +12,7 @@ import ( type Pool struct { judges sync.Map - AllowGameMode []_type.Mode + AllowGameMode []game_def.Mode } var data data_source.TempDataSource @@ -22,7 +22,7 @@ func ApplyDataSource(source interface{}) { judge.ApplyDataSource(source) } -func (p *Pool) NewGame(mode _type.Mode) { +func (p *Pool) NewGame(mode game_def.Mode) { id := data.CreateGame(mode) if id == 0 { logrus.Panic("cannot create game") @@ -40,7 +40,7 @@ func (p *Pool) DebugNewGame(g *game_logic.Game) { p.judges.Store(g.Id, judge.NewGameJudge(g.Id)) } -func CreatePool(allowGameMode []_type.Mode) *Pool { +func CreatePool(allowGameMode []game_def.Mode) *Pool { p := &Pool{AllowGameMode: allowGameMode} go poolWorking(p) return p diff --git a/packages/server/main.go b/packages/server/main.go index 3ac9ad5..00ee56c 100644 --- a/packages/server/main.go +++ b/packages/server/main.go @@ -55,12 +55,12 @@ func main() { data := local.Local{ GamePool: make(map[game_logic.Id]*game_logic.Game), OriginalMapStrPool: make(map[uint32]string), - InstructionLog: make(map[game_logic.Id]map[uint16]map[uint16]_type.Instruction), + InstructionLog: make(map[game_logic.Id]map[uint16]map[uint16]game_def.Instruction), } data.OriginalMapStrPool[0] = "[\n[0,0,0,0,2],\n[0,2,0,0,0],\n[0,0,0,0,0],\n[0,3,3,0,3],\n[0,3,0,2,0]\n]" judge_pool.ApplyDataSource(&data) - p := judge_pool.CreatePool([]_type.Mode{_type.Mode1v1}) + p := judge_pool.CreatePool([]game_def.Mode{game_def.Mode1v1}) time.Sleep(200 * time.Millisecond) diff --git a/packages/server/main_test.go b/packages/server/main_test.go index ca76faf..5179de6 100644 --- a/packages/server/main_test.go +++ b/packages/server/main_test.go @@ -22,12 +22,12 @@ func TestServer_main(t *testing.T) { data := local.Local{ GamePool: make(map[game_logic.Id]*game_logic.Game), OriginalMapStrPool: make(map[uint32]string), - InstructionLog: make(map[game_logic.Id]map[uint16]map[uint16]_type.Instruction), + InstructionLog: make(map[game_logic.Id]map[uint16]map[uint16]game_def.Instruction), } data.OriginalMapStrPool[0] = "[\n[0,0,0,0,2],\n[0,2,0,0,0],\n[0,0,0,0,0],\n[0,3,3,0,3],\n[0,3,0,2,0]\n]" judge_pool.ApplyDataSource(&data) - p := judge_pool.CreatePool([]_type.Mode{_type.Mode1v1}) + p := judge_pool.CreatePool([]game_def.Mode{game_def.Mode1v1}) time.Sleep(200 * time.Millisecond) diff --git a/packages/server/utils/pkg/data_source/local/local.go b/packages/server/utils/pkg/data_source/local/local.go index 1def222..0495dc6 100644 --- a/packages/server/utils/pkg/data_source/local/local.go +++ b/packages/server/utils/pkg/data_source/local/local.go @@ -19,7 +19,7 @@ type Local struct { m sync.Mutex GamePool map[game_logic.Id]*game_logic.Game OriginalMapStrPool map[uint32]string - InstructionLog map[game_logic.Id]map[uint16]map[uint16]_type.Instruction + InstructionLog map[game_logic.Id]map[uint16]map[uint16]game_def.Instruction } func (l *Local) lock() bool { @@ -53,7 +53,7 @@ func (l *Local) SetWinner(id game_logic.Id, teamId uint8) (ok bool) { return false } -func (l *Local) GetGameList(mode _type.Mode) []game_logic.Game { +func (l *Local) GetGameList(mode game_def.Mode) []game_logic.Game { if l.lock() { defer l.unlock() var ret []game_logic.Game @@ -103,7 +103,7 @@ func (l *Local) GetGameInfo(id game_logic.Id) *game_logic.Game { } } -func (l *Local) GetCurrentUserList(id game_logic.Id) []_type.User { +func (l *Local) GetCurrentUserList(id game_logic.Id) []game_def.User { if l.lock() { defer l.unlock() return l.GamePool[id].UserList @@ -112,7 +112,7 @@ func (l *Local) GetCurrentUserList(id game_logic.Id) []_type.User { } } -func (l *Local) GetInstructions(id game_logic.Id, tempId uint16) map[uint16]_type.Instruction { +func (l *Local) GetInstructions(id game_logic.Id, tempId uint16) map[uint16]game_def.Instruction { if l.lock() { defer l.unlock() return l.InstructionLog[id][tempId] @@ -126,7 +126,7 @@ func (l *Local) NewInstructionTemp(id game_logic.Id, _ uint16) (ok bool) { if l.lock() { defer l.unlock() l.GamePool[id].RoundNum++ - l.InstructionLog[id][l.GamePool[id].RoundNum] = make(map[uint16]_type.Instruction) + l.InstructionLog[id][l.GamePool[id].RoundNum] = make(map[uint16]game_def.Instruction) return true } else { return false @@ -153,7 +153,7 @@ func (l *Local) SetGameMap(id game_logic.Id, m *_map.Map) (ok bool) { } } -func (l *Local) SetUserStatus(id game_logic.Id, user _type.User) (ok bool) { +func (l *Local) SetUserStatus(id game_logic.Id, user game_def.User) (ok bool) { if l.lock() { defer l.unlock() @@ -165,7 +165,7 @@ func (l *Local) SetUserStatus(id game_logic.Id, user _type.User) (ok bool) { // Try to find for i, u := range g.UserList { if u.UserId == user.UserId { - if user.Status == _type.UserStatusDisconnected { + if user.Status == game_def.UserStatusDisconnected { // Remove the user from the list if they are disconnected g.UserList = append(g.UserList[:i], g.UserList[i+1:]...) } else { @@ -182,7 +182,7 @@ func (l *Local) SetUserStatus(id game_logic.Id, user _type.User) (ok bool) { logrus.Panic("game mode is illegal") } // If the user is not in the list, try to add him/her if the game is not full - if user.Status == _type.UserStatusConnected && uint8(len(g.UserList)) < g.Mode.MaxUserNum { + if user.Status == game_def.UserStatusConnected && uint8(len(g.UserList)) < g.Mode.MaxUserNum { user.TeamId = 0 g.UserList = append(g.UserList, user) return true @@ -200,7 +200,7 @@ func (l *Local) SetUserStatus(id game_logic.Id, user _type.User) (ok bool) { return false } -func (l *Local) UpdateInstruction(id game_logic.Id, user _type.User, instruction _type.Instruction) (ok bool) { +func (l *Local) UpdateInstruction(id game_logic.Id, user game_def.User, instruction game_def.Instruction) (ok bool) { if l.lock() { defer l.unlock() l.InstructionLog[id][l.GamePool[id].RoundNum][user.UserId] = instruction @@ -237,7 +237,7 @@ func (l *Local) GetCurrentGame(id game_logic.Id) *game_logic.Game { return nil } -func (l *Local) CreateGame(mode _type.Mode) game_logic.Id { +func (l *Local) CreateGame(mode game_def.Mode) game_logic.Id { //m := l.GetOriginalMap(rand.Uint32()) m := l.GetOriginalMap(0) // TODO DEBUG ONLY if l.lock() { @@ -256,11 +256,11 @@ func (l *Local) CreateGame(mode _type.Mode) game_logic.Id { CreateTime: time.Now().UnixMicro(), Status: game_logic.StatusWaiting, RoundNum: 0, - UserList: []_type.User{}, + UserList: []game_def.User{}, } l.GamePool[g.Id] = g - l.InstructionLog[g.Id] = make(map[uint16]map[uint16]_type.Instruction) + l.InstructionLog[g.Id] = make(map[uint16]map[uint16]game_def.Instruction) return g.Id } else { return 0 @@ -295,7 +295,7 @@ func (l *Local) DebugCreateGame(g *game_logic.Game) (ok bool) { RoundNum: 0, } l.GamePool[g.Id] = ng - l.InstructionLog[g.Id] = make(map[uint16]map[uint16]_type.Instruction) + l.InstructionLog[g.Id] = make(map[uint16]map[uint16]game_def.Instruction) return true } else { return false diff --git a/packages/server/utils/pkg/data_source/local/local_test.go b/packages/server/utils/pkg/data_source/local/local_test.go index 2c0285d..90d0db0 100644 --- a/packages/server/utils/pkg/data_source/local/local_test.go +++ b/packages/server/utils/pkg/data_source/local/local_test.go @@ -17,17 +17,17 @@ func create() *Local { return &Local{ GamePool: make(map[game_logic.Id]*game_logic.Game), OriginalMapStrPool: make(map[uint32]string), - InstructionLog: make(map[game_logic.Id]map[uint16]map[uint16]_type.Instruction), + InstructionLog: make(map[game_logic.Id]map[uint16]map[uint16]game_def.Instruction), } } var userCount = uint16(1) -func getUser() _type.User { - return _type.User{ +func getUser() game_def.User { + return game_def.User{ Name: strconv.Itoa(int(userCount)), UserId: userCount, - Status: _type.UserStatusDisconnected, + Status: game_def.UserStatusDisconnected, TeamId: uint8(userCount), ForceStartStatus: false, } @@ -56,9 +56,9 @@ func TestLocal_Game(t *testing.T) { // This function must be correct l.DebugCreateGame(&game_logic.Game{ Map: _map.FullStr2GameMap(1, "[[[0,0,0]]]"), // Wait - Mode: _type.Mode1v1, + Mode: game_def.Mode1v1, Id: id, - UserList: []_type.User{getUser()}, + UserList: []game_def.User{getUser()}, CreateTime: 0, Status: game_logic.StatusWaiting, RoundNum: 0, @@ -78,7 +78,7 @@ func TestLocal_Game(t *testing.T) { } }) t.Run("get game list", func(t *testing.T) { - gl := l.GetGameList(_type.Mode1v1) + gl := l.GetGameList(game_def.Mode1v1) if len(gl) != 1 { t.Fatalf("game count is incorrect") } @@ -95,8 +95,8 @@ 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.Position{1, 1}, + ins := game_def.Move{ + Position: game_def.Position{1, 1}, Towards: "down", Number: 1, } @@ -122,9 +122,9 @@ func TestLocal_User(t *testing.T) { id := game_logic.Id(2) l.DebugCreateGame(&game_logic.Game{ Map: _map.FullStr2GameMap(1, "[[[0,0,0]]]"), - Mode: _type.Mode1v1, + Mode: game_def.Mode1v1, Id: id, - UserList: []_type.User{}, + UserList: []game_def.User{}, CreateTime: 0, Status: game_logic.StatusWaiting, RoundNum: 0, @@ -137,14 +137,14 @@ func TestLocal_User(t *testing.T) { t.Fatalf("user has been added unexpectedly") } - u.Status = _type.UserStatusConnected + u.Status = game_def.UserStatusConnected l.SetUserStatus(id, u) if len(l.GamePool[id].UserList) != 1 || l.GamePool[id].UserList[0].UserId != u.UserId { t.Fatalf("user has not been added") } - u.Status = _type.UserStatusDisconnected + u.Status = game_def.UserStatusDisconnected l.SetUserStatus(id, u) @@ -159,9 +159,9 @@ func TestLocal_Map(t *testing.T) { id := game_logic.Id(3) l.DebugCreateGame(&game_logic.Game{ Map: _map.FullStr2GameMap(1, "[[[0,0,0]]]"), - Mode: _type.Mode1v1, + Mode: game_def.Mode1v1, Id: id, - UserList: []_type.User{}, + UserList: []game_def.User{}, CreateTime: 0, Status: game_logic.StatusWaiting, RoundNum: 0, @@ -185,8 +185,8 @@ func TestLocal_Map(t *testing.T) { if a.Size() == b.Size() && a.Id() == b.Id() { for y := uint8(1); y <= a.Size().H; y++ { for x := uint8(1); x <= a.Size().W; x++ { - blockA := a.GetBlock(_type.Position{x, y}) - blockB := b.GetBlock(_type.Position{x, y}) + blockA := a.GetBlock(game_def.Position{x, y}) + blockB := b.GetBlock(game_def.Position{x, y}) if blockA != blockB { ret = false break diff --git a/packages/server/utils/pkg/data_source/pg/pg.go b/packages/server/utils/pkg/data_source/pg/pg.go index 9a89311..c9ec32e 100644 --- a/packages/server/utils/pkg/data_source/pg/pg.go +++ b/packages/server/utils/pkg/data_source/pg/pg.go @@ -44,7 +44,7 @@ func generatorMapJson(m *_map.Map) string { for y := uint8(1); y <= m.Size().H; y++ { ret.Blocks[y] = make([]b, m.Size().W) for x := uint8(1); x <= m.Size().W; x++ { - ob := m.GetBlock(_type.Position{X: x, Y: y}) + ob := m.GetBlock(game_def.Position{X: x, Y: y}) ret.Blocks[y][x] = b{ TypeId: ob.Meta().BlockId, OwnerId: ob.OwnerId(), @@ -62,7 +62,7 @@ func generatorMapJson(m *_map.Map) string { var sqlQueryGame = "SELECT * FROM game WHERE game_id=$1" -func (p *Pg) CreateGame(mode _type.Mode) game_logic.Id { +func (p *Pg) CreateGame(mode game_def.Mode) game_logic.Id { var gameId game_logic.Id for { gameId = game_logic.Id(rand.Uint32()) @@ -91,7 +91,7 @@ func (p *Pg) DebugCreateGame(g *game_logic.Game) (ok bool) { var sqlQueryGameList = "SELECT game_id FROM game WHERE mode=$1 AND (status=1 OR status=2)" -func (p *Pg) GetGameList(mode _type.Mode) []game_logic.Game { +func (p *Pg) GetGameList(mode game_def.Mode) []game_logic.Game { r := db.SqlQuery(sqlQueryGameList, mode) var list []game_logic.Id for { @@ -114,12 +114,12 @@ func (p *Pg) CancelGame(id game_logic.Id) (ok bool) { panic("implement me") } -func (p *Pg) GetCurrentUserList(id game_logic.Id) []_type.User { +func (p *Pg) GetCurrentUserList(id game_logic.Id) []game_def.User { //TODO implement me panic("implement me") } -func (p *Pg) GetInstructions(id game_logic.Id, tempId uint16) map[uint16]_type.Instruction { +func (p *Pg) GetInstructions(id game_logic.Id, tempId uint16) map[uint16]game_def.Instruction { //TODO implement me panic("implement me") } @@ -141,7 +141,7 @@ func (p *Pg) GetGameInfo(id game_logic.Id) *game_logic.Game { logrus.Warn("cannot get game info") return nil } - if mode, ok := _type.ModeMap[modeStr]; !ok { + if mode, ok := game_def.ModeMap[modeStr]; !ok { logrus.Warn("get unknown mode ", modeStr, " when get game info") } else { g.Mode = mode @@ -164,7 +164,7 @@ func (p *Pg) SetGameMap(id game_logic.Id, m *_map.Map) (ok bool) { panic("implement me") } -func (p *Pg) SetUserStatus(id game_logic.Id, user _type.User) (ok bool) { +func (p *Pg) SetUserStatus(id game_logic.Id, user game_def.User) (ok bool) { //TODO implement me panic("implement me") } @@ -174,7 +174,7 @@ func (p *Pg) SetWinner(id game_logic.Id, teamId uint8) (ok bool) { panic("implement me") } -func (p *Pg) UpdateInstruction(id game_logic.Id, user _type.User, instruction _type.Instruction) (ok bool) { +func (p *Pg) UpdateInstruction(id game_logic.Id, user game_def.User, instruction game_def.Instruction) (ok bool) { //TODO implement me panic("implement me") } diff --git a/packages/server/utils/pkg/data_source/temp.go b/packages/server/utils/pkg/data_source/temp.go index 4a51f34..b0dfe25 100644 --- a/packages/server/utils/pkg/data_source/temp.go +++ b/packages/server/utils/pkg/data_source/temp.go @@ -7,20 +7,20 @@ import ( ) type TempDataSource interface { - CreateGame(mode _type.Mode) game_logic.Id - GetGameList(mode _type.Mode) []game_logic.Game // Returns `Game` structs with only basic info of not end game + CreateGame(mode game_def.Mode) game_logic.Id + GetGameList(mode game_def.Mode) []game_logic.Game // Returns `Game` structs with only basic info of not end game CancelGame(id game_logic.Id) (ok bool) - GetCurrentUserList(id game_logic.Id) []_type.User - GetInstructions(id game_logic.Id, tempId uint16) map[uint16]_type.Instruction + GetCurrentUserList(id game_logic.Id) []game_def.User + GetInstructions(id game_logic.Id, tempId uint16) map[uint16]game_def.Instruction GetGameInfo(id game_logic.Id) *game_logic.Game // Returns a `Game` struct with only basic info NewInstructionTemp(id game_logic.Id, tempId uint16) (ok bool) SetGameStatus(id game_logic.Id, status game_logic.Status) (ok bool) SetGameMap(id game_logic.Id, m *_map.Map) (ok bool) - SetUserStatus(id game_logic.Id, user _type.User) (ok bool) + SetUserStatus(id game_logic.Id, user game_def.User) (ok bool) SetWinner(id game_logic.Id, teamId uint8) (ok bool) - UpdateInstruction(id game_logic.Id, user _type.User, instruction _type.Instruction) (ok bool) + UpdateInstruction(id game_logic.Id, user game_def.User, instruction game_def.Instruction) (ok bool) GetCurrentMap(id game_logic.Id) *_map.Map // Functions only for debug