Skip to content

Commit

Permalink
[Clean] Renormalize package references
Browse files Browse the repository at this point in the history
  • Loading branch information
CornWorld committed Feb 6, 2024
1 parent 8abae74 commit 5295b31
Show file tree
Hide file tree
Showing 27 changed files with 172 additions and 171 deletions.
14 changes: 7 additions & 7 deletions packages/server/api/internal/command/pauser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand All @@ -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 {
Expand All @@ -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,
}
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/api/internal/receiver/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions packages/server/api/internal/receiver/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -58,7 +58,7 @@ func NewFileReceiver(pool *judge_pool.Pool) {
}

type command struct {
User _type.User
User game_def.User
Ins []string
}

Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand All @@ -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")
}()
Expand Down
12 changes: 6 additions & 6 deletions packages/server/game_logic/block/base_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
8 changes: 4 additions & 4 deletions packages/server/game_logic/block/base_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions packages/server/game_logic/block/block_blank.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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)
}
10 changes: 5 additions & 5 deletions packages/server/game_logic/block/block_castle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -23,17 +23,17 @@ 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))
} else {
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
}
12 changes: 6 additions & 6 deletions packages/server/game_logic/block/block_king.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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)
}
Expand Down
12 changes: 6 additions & 6 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.BlockMeta{
var MountainMeta = game_def.BlockMeta{
BlockId: 4,
Name: "mountain",
Description: "",
Expand All @@ -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}
}
16 changes: 8 additions & 8 deletions packages/server/game_logic/block/block_soldier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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
}

Expand All @@ -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 {
Expand All @@ -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
Expand Down
Loading

0 comments on commit 5295b31

Please sign in to comment.