test

package
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestBookSystem = server.CreateSystemFromRequestHandler(func(ctx *server.TransactionCtx[*pb_test.C2S_Test]) {
	req := ctx.Req.Data
	w := ctx.W

	playerID := int(req.GetIdentityPayload().GetPlayerId())

	for _, bookInfo := range req.BookInfos {
		switch bookInfo.Op {
		case pb_test.Operation_Add:
			bookTable.Add(w, Book{
				Title:   bookInfo.Title,
				Author:  bookInfo.Author,
				OwnerID: playerID,
			})
		case pb_test.Operation_AddSpecific:
			bookTable.AddSpecific(w, int(bookInfo.Entity), Book{
				Title:   bookInfo.Title,
				Author:  bookInfo.Author,
				OwnerID: playerID,
			})
		case pb_test.Operation_Remove:
			server.QueueTxFromInternal(w, ctx.GameCtx.GameTick.TickNumber+1, server.NewKeystoneTx(testRemoveRequest{
				Title:    bookInfo.Title,
				Author:   bookInfo.Author,
				PlayerID: playerID,
			}, nil), "")
		case pb_test.Operation_Update:
			book := bookTable.Get(w, int(bookInfo.Entity))
			if book.Title == "" {
				ctx.EmitError(fmt.Sprintf("no book to update with entity %v", bookInfo.Entity), []int{playerID})
				return
			}

			book.Title = bookInfo.Title
			book.Author = bookInfo.Author
			bookTable.Set(w, int(bookInfo.Entity), book)
		}
	}
})
View Source
var TestRemoveBookSystem = server.CreateSystemFromRequestHandler(func(ctx *server.TransactionCtx[testRemoveRequest]) {
	req := ctx.Req.Data
	w := ctx.GameCtx.World

	bookFilter := Book{Author: req.Author, Title: req.Title, OwnerID: req.PlayerID}
	fieldNames := []string{"OwnerID"}
	if req.Author == "" && req.Title == "" {
		ctx.EmitError("author or title must be provided to remove a book", []int{req.PlayerID})
		return
	}

	if req.Author != "" {
		fieldNames = append(fieldNames, "Author")
	}
	if req.Title != "" {
		fieldNames = append(fieldNames, "Title")
	}

	bookEntities := bookTable.Filter(w, bookFilter, fieldNames)
	for _, e := range bookEntities {
		bookTable.RemoveEntity(w, e)
	}
})

Functions

This section is empty.

Types

type Book

type Book struct {
	Title   string
	Author  string
	OwnerID int
	Id      int `gorm:"primaryKey;autoIncrement:false"`
}

type Committee added in v0.1.12

type Committee struct {
	CommitteeOwners utils.SerializableArray[Owner] `gorm:"serializer:json"`
}

type Owner added in v0.1.11

type Owner struct {
	Name  string    `json:"name"`
	Age   int       `json:"age"`
	Happy bool      `json:"happy"`
	Pets  []Pet     `json:"pets"`
	Pos   state.Pos `json:"pos" gorm:"embedded"`
}

type Person

type Person struct {
	Name       string
	MainWallet string
	Age        int
	Address    string
	Position   state.Pos `gorm:"embedded"`
	BookId     int
	Id         int `gorm:"primaryKey;autoIncrement:false"`
}

type Pet added in v0.1.11

type Pet struct {
	Kind PetKind `json:"kind"`
	Name string  `json:"name"`
}

type PetCommunity added in v0.1.11

type PetCommunity struct {
	Owners    utils.SerializableArray[Owner] `gorm:"serializer:json"`
	Committee Committee                      `gorm:"embedded"`
	Id        int                            `gorm:"primaryKey;autoIncrement:false"`
}

type PetKind added in v0.1.11

type PetKind int
const (
	Dog PetKind = iota
	Cat
)

type Token added in v0.1.0

type Token struct {
	OriginalOwnerId int
	OwnerId         int
	Id              int `gorm:"primaryKey;autoIncrement:false"`
}

Directories

Path Synopsis
proto

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL