clean up
This commit is contained in:
parent
c8aa5389c1
commit
ced2b28d9b
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/bedrock-tool/bedrocktool/locale"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
@ -52,7 +53,7 @@ func NewSkinsSession(proxy *utils.ProxyContext, serverName, fpath string) *skins
|
|||
}
|
||||
}
|
||||
|
||||
func (s *skinsSession) AddPlayerSkin(playerID uuid.UUID, playerName string, skin *Skin) {
|
||||
func (s *skinsSession) AddPlayerSkin(playerID uuid.UUID, playerName string, skin *Skin) (added bool) {
|
||||
p, ok := s.playerSkinPacks[playerID]
|
||||
if !ok {
|
||||
creating := fmt.Sprintf("Creating Skinpack for %s", playerName)
|
||||
|
@ -63,17 +64,19 @@ func (s *skinsSession) AddPlayerSkin(playerID uuid.UUID, playerName string, skin
|
|||
}
|
||||
if p.AddSkin(skin) {
|
||||
if ok {
|
||||
added := fmt.Sprintf("Added a skin to %s", playerName)
|
||||
s.Proxy.SendPopup(added)
|
||||
logrus.Info(added)
|
||||
addedStr := fmt.Sprintf("Added a skin to %s", playerName)
|
||||
s.Proxy.SendPopup(addedStr)
|
||||
logrus.Info(addedStr)
|
||||
}
|
||||
added = true
|
||||
}
|
||||
if err := p.Save(path.Join(s.fpath, playerName), s.ServerName); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
return added
|
||||
}
|
||||
|
||||
func (s *skinsSession) AddSkin(playerName string, playerID uuid.UUID, playerSkin *protocol.Skin) {
|
||||
func (s *skinsSession) AddSkin(playerName string, playerID uuid.UUID, playerSkin *protocol.Skin) (string, *Skin, bool) {
|
||||
if playerName == "" {
|
||||
playerName = s.playerNames[playerID]
|
||||
if playerName == "" {
|
||||
|
@ -81,31 +84,45 @@ func (s *skinsSession) AddSkin(playerName string, playerID uuid.UUID, playerSkin
|
|||
}
|
||||
}
|
||||
if !strings.HasPrefix(playerName, s.PlayerNameFilter) {
|
||||
return
|
||||
return "", nil, false
|
||||
}
|
||||
s.playerNames[playerID] = playerName
|
||||
|
||||
skin := Skin{playerSkin}
|
||||
skin := &Skin{playerSkin}
|
||||
if s.OnlyIfHasGeometry && !skin.HaveGeometry() {
|
||||
return
|
||||
return "", nil, false
|
||||
}
|
||||
s.AddPlayerSkin(playerID, playerName, &skin)
|
||||
wasAdded := s.AddPlayerSkin(playerID, playerName, skin)
|
||||
|
||||
return playerName, skin, wasAdded
|
||||
}
|
||||
|
||||
func (s *skinsSession) ProcessPacket(pk packet.Packet) {
|
||||
type skinAdd struct {
|
||||
PlayerName string
|
||||
Skin *protocol.Skin
|
||||
}
|
||||
|
||||
func (s *skinsSession) ProcessPacket(pk packet.Packet) (out []skinAdd) {
|
||||
switch pk := pk.(type) {
|
||||
case *packet.PlayerList:
|
||||
if pk.ActionType == 1 { // remove
|
||||
return
|
||||
return nil
|
||||
}
|
||||
for _, player := range pk.Entries {
|
||||
s.AddSkin(utils.CleanupName(player.Username), player.UUID, &player.Skin)
|
||||
playerName, skin, wasAdded := s.AddSkin(utils.CleanupName(player.Username), player.UUID, &player.Skin)
|
||||
if wasAdded {
|
||||
out = append(out, skinAdd{
|
||||
PlayerName: playerName,
|
||||
Skin: skin.Skin,
|
||||
})
|
||||
}
|
||||
}
|
||||
case *packet.AddPlayer:
|
||||
if _, ok := s.playerNames[pk.UUID]; !ok {
|
||||
s.playerNames[pk.UUID] = utils.CleanupName(pk.Username)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
type SkinCMD struct {
|
||||
|
@ -131,10 +148,14 @@ func (c *SkinCMD) Execute(ctx context.Context, ui utils.UI) error {
|
|||
|
||||
proxy, _ := utils.NewProxy()
|
||||
proxy.WithClient = !c.NoProxy
|
||||
proxy.OnClientConnect = func(proxy *utils.ProxyContext, hasClient bool) {
|
||||
ui.Message(messages.SetUIState, messages.UIStateConnecting)
|
||||
}
|
||||
proxy.ConnectCB = func(proxy *utils.ProxyContext, err error) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ui.Message(messages.SetUIState, messages.UIStateMain)
|
||||
logrus.Info(locale.Loc("ctrl_c_to_exit", nil))
|
||||
return true
|
||||
}
|
||||
|
@ -146,11 +167,21 @@ func (c *SkinCMD) Execute(ctx context.Context, ui utils.UI) error {
|
|||
|
||||
proxy.PacketCB = func(pk packet.Packet, _ *utils.ProxyContext, toServer bool, _ time.Time) (packet.Packet, error) {
|
||||
if !toServer {
|
||||
s.ProcessPacket(pk)
|
||||
for _, s := range s.ProcessPacket(pk) {
|
||||
ui.Message(messages.NewSkin, messages.NewSkinPayload{
|
||||
PlayerName: s.PlayerName,
|
||||
Skin: s.Skin,
|
||||
})
|
||||
}
|
||||
}
|
||||
return pk, nil
|
||||
}
|
||||
|
||||
if proxy.WithClient {
|
||||
ui.Message(messages.SetUIState, messages.UIStateConnect)
|
||||
} else {
|
||||
ui.Message(messages.SetUIState, messages.UIStateConnecting)
|
||||
}
|
||||
err = proxy.Run(ctx, address)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -88,17 +88,23 @@ func (w *WorldState) processAddActor(pk *packet.AddActor) {
|
|||
}
|
||||
|
||||
func entityMetadataToNBT(metadata protocol.EntityMetadata, nbt map[string]any) {
|
||||
if variant, ok := metadata[protocol.EntityDataKeyVariant].(int32); ok {
|
||||
if variant, ok := metadata[protocol.EntityDataKeyVariant]; ok {
|
||||
nbt["Variant"] = variant
|
||||
}
|
||||
if markVariant, ok := metadata[protocol.EntityDataKeyMarkVariant].(int32); ok {
|
||||
if markVariant, ok := metadata[protocol.EntityDataKeyMarkVariant]; ok {
|
||||
nbt["MarkVariant"] = markVariant
|
||||
}
|
||||
if color, ok := metadata[protocol.EntityDataKeyColorIndex]; ok {
|
||||
nbt["Color"] = color
|
||||
}
|
||||
if color2, ok := metadata[protocol.EntityDataKeyColorTwoIndex]; ok {
|
||||
nbt["Color2"] = color2
|
||||
}
|
||||
|
||||
if name, ok := metadata[protocol.EntityDataKeyName].(string); ok {
|
||||
if name, ok := metadata[protocol.EntityDataKeyName]; ok {
|
||||
nbt["CustomName"] = name
|
||||
}
|
||||
if ShowNameTag, ok := metadata[protocol.EntityDataKeyAlwaysShowNameTag].(uint8); ok {
|
||||
if ShowNameTag, ok := metadata[protocol.EntityDataKeyAlwaysShowNameTag]; ok {
|
||||
if ShowNameTag != 0 {
|
||||
nbt["CustomNameVisible"] = true
|
||||
} else {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/bedrock-tool/bedrocktool/locale"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
"golang.design/x/lockfree"
|
||||
|
||||
|
@ -230,7 +231,7 @@ func (m *MapUI) Redraw() {
|
|||
ChunkCount := len(m.renderedChunks)
|
||||
if m.showOnGui {
|
||||
min, max := m.GetBounds()
|
||||
m.w.gui.Message(utils.UpdateMapName, utils.UpdateMapPayload{
|
||||
m.w.gui.Message(messages.UpdateMap, messages.UpdateMapPayload{
|
||||
ChunkCount: ChunkCount,
|
||||
Rotation: m.w.PlayerPos.Yaw,
|
||||
UpdatedTiles: updatedChunks,
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/bedrock-tool/bedrocktool/locale"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
"github.com/bedrock-tool/bedrocktool/utils/behaviourpack"
|
||||
|
||||
|
@ -84,7 +85,7 @@ func NewWorldState(ctx context.Context, proxy *utils.ProxyContext, ServerName st
|
|||
}
|
||||
w.mapUI = NewMapUI(w)
|
||||
|
||||
w.gui.Message(utils.InitName, utils.InitPayload{
|
||||
w.gui.Message(messages.Init, messages.InitPayload{
|
||||
Handler: w.uiMessage,
|
||||
})
|
||||
|
||||
|
@ -155,7 +156,7 @@ func (c *WorldCMD) Execute(ctx context.Context, ui utils.UI) error {
|
|||
proxy.AlwaysGetPacks = true
|
||||
proxy.ConnectCB = w.OnConnect
|
||||
proxy.OnClientConnect = func(proxy *utils.ProxyContext, hasClient bool) {
|
||||
w.gui.Message(utils.SetUIStateName, utils.UIStateConnecting)
|
||||
w.gui.Message(messages.SetUIState, messages.UIStateConnecting)
|
||||
}
|
||||
proxy.PacketCB = func(pk packet.Packet, proxy *utils.ProxyContext, toServer bool, _ time.Time) (packet.Packet, error) {
|
||||
forward := true
|
||||
|
@ -177,7 +178,7 @@ func (c *WorldCMD) Execute(ctx context.Context, ui utils.UI) error {
|
|||
return pk, nil
|
||||
}
|
||||
|
||||
w.gui.Message(utils.SetUIStateName, utils.UIStateConnect)
|
||||
w.gui.Message(messages.SetUIState, messages.UIStateConnect)
|
||||
err = w.proxy.Run(ctx, serverAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -186,17 +187,17 @@ func (c *WorldCMD) Execute(ctx context.Context, ui utils.UI) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (w *WorldState) uiMessage(name string, data interface{}) utils.MessageResponse {
|
||||
r := utils.MessageResponse{
|
||||
func (w *WorldState) uiMessage(name string, data interface{}) messages.MessageResponse {
|
||||
r := messages.MessageResponse{
|
||||
Ok: false,
|
||||
Data: nil,
|
||||
}
|
||||
switch name {
|
||||
case utils.SetVoidGenName:
|
||||
set_void_gen := data.(utils.SetVoidGenPayload)
|
||||
case messages.SetVoidGen:
|
||||
set_void_gen := data.(messages.SetVoidGenPayload)
|
||||
r.Ok = w.setVoidGen(set_void_gen.Value, true)
|
||||
case utils.SetWorldNameName:
|
||||
set_world_name := data.(utils.SetWorldNamePayload)
|
||||
case messages.SetWorldName:
|
||||
set_world_name := data.(messages.SetWorldNamePayload)
|
||||
r.Ok = w.setWorldName(set_world_name.WorldName, true)
|
||||
}
|
||||
return r
|
||||
|
@ -227,7 +228,7 @@ func (w *WorldState) setVoidGen(val bool, fromUI bool) bool {
|
|||
w.proxy.SendMessage(s)
|
||||
|
||||
if !fromUI {
|
||||
w.gui.Message(utils.SetVoidGenName, utils.SetVoidGenPayload{
|
||||
w.gui.Message(messages.SetVoidGen, messages.SetVoidGenPayload{
|
||||
Value: w.voidGen,
|
||||
})
|
||||
}
|
||||
|
@ -240,7 +241,7 @@ func (w *WorldState) setWorldName(val string, fromUI bool) bool {
|
|||
w.proxy.SendMessage(locale.Loc("worldname_set", locale.Strmap{"Name": w.WorldName}))
|
||||
|
||||
if !fromUI {
|
||||
w.gui.Message(utils.SetWorldNameName, utils.SetWorldNamePayload{
|
||||
w.gui.Message(messages.SetWorldName, messages.SetWorldNamePayload{
|
||||
WorldName: w.WorldName,
|
||||
})
|
||||
}
|
||||
|
@ -446,7 +447,8 @@ func (w *WorldState) SaveAndReset() {
|
|||
|
||||
// save behaviourpack
|
||||
if w.bp.HasContent() {
|
||||
name := strings.ReplaceAll(w.ServerName, "/", "-") + "_blocks"
|
||||
name := strings.ReplaceAll(w.ServerName, "./", "")
|
||||
name = strings.ReplaceAll(name, "/", "-")
|
||||
packFolder := path.Join(folder, "behavior_packs", name)
|
||||
os.MkdirAll(packFolder, 0o755)
|
||||
|
||||
|
@ -508,7 +510,7 @@ func (w *WorldState) SaveAndReset() {
|
|||
}
|
||||
|
||||
func (w *WorldState) OnConnect(proxy *utils.ProxyContext, err error) bool {
|
||||
w.gui.Message(utils.SetUIStateName, utils.UIStateMain)
|
||||
w.gui.Message(messages.SetUIState, messages.UIStateMain)
|
||||
|
||||
if err != nil {
|
||||
return false
|
||||
|
|
|
@ -15,7 +15,9 @@ import (
|
|||
"gioui.org/x/pref/theme"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui/pages"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui/pages/settings"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui/pages/skins"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui/pages/worlds"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -70,6 +72,7 @@ func (g *GUI) Start(ctx context.Context, cancel context.CancelFunc) (err error)
|
|||
|
||||
g.router.Register("Settings", settings.New(&g.router))
|
||||
g.router.Register("worlds", worlds.New(&g.router))
|
||||
g.router.Register("skins", skins.New(&g.router))
|
||||
|
||||
g.router.SwitchTo("Settings")
|
||||
|
||||
|
@ -111,13 +114,13 @@ func (g *GUI) run(w *app.Window) error {
|
|||
}
|
||||
}
|
||||
|
||||
func (g *GUI) Message(name string, data interface{}) utils.MessageResponse {
|
||||
func (g *GUI) Message(name string, data interface{}) messages.MessageResponse {
|
||||
r := g.router.Handler(name, data)
|
||||
if r.Ok || r.Data != nil {
|
||||
return r
|
||||
}
|
||||
|
||||
r = utils.MessageResponse{
|
||||
r = messages.MessageResponse{
|
||||
Ok: false,
|
||||
Data: nil,
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
package gui
|
|
@ -10,10 +10,10 @@ import (
|
|||
"gioui.org/op/paint"
|
||||
"gioui.org/widget/material"
|
||||
"gioui.org/x/component"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
)
|
||||
|
||||
type HandlerFunc = func(name string, data interface{}) utils.MessageResponse
|
||||
type HandlerFunc = func(name string, data interface{}) messages.MessageResponse
|
||||
|
||||
type Page interface {
|
||||
Actions() []component.AppBarAction
|
||||
|
@ -133,12 +133,12 @@ func (r *Router) Layout(gtx layout.Context, th *material.Theme) layout.Dimension
|
|||
return layout.Dimensions{Size: gtx.Constraints.Max}
|
||||
}
|
||||
|
||||
func (r *Router) Handler(name string, data interface{}) utils.MessageResponse {
|
||||
func (r *Router) Handler(name string, data interface{}) messages.MessageResponse {
|
||||
page, ok := r.pages[r.current]
|
||||
if ok {
|
||||
return page.Handler()(name, data)
|
||||
}
|
||||
return utils.MessageResponse{}
|
||||
return messages.MessageResponse{}
|
||||
}
|
||||
|
||||
var Pages = map[string]func(*Router) Page{}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"gioui.org/x/component"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui/pages"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui/settings"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -51,7 +52,7 @@ func New(router *pages.Router) *Page {
|
|||
OptionList: layout.List{},
|
||||
Options: options,
|
||||
}
|
||||
p.cmdMenu.selected = "worlds"
|
||||
//p.cmdMenu.selected = "worlds"
|
||||
|
||||
for _, su := range settings.Settings {
|
||||
su.Init()
|
||||
|
@ -169,8 +170,8 @@ func (p *Page) Layout(gtx C, th *material.Theme) D {
|
|||
}
|
||||
|
||||
func (p *Page) Handler() pages.HandlerFunc {
|
||||
return func(name string, data interface{}) utils.MessageResponse {
|
||||
return utils.MessageResponse{
|
||||
return func(name string, data interface{}) messages.MessageResponse {
|
||||
return messages.MessageResponse{
|
||||
Ok: false,
|
||||
Data: nil,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package skins
|
||||
|
||||
import (
|
||||
"gioui.org/layout"
|
||||
"gioui.org/unit"
|
||||
"gioui.org/widget/material"
|
||||
"gioui.org/x/component"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui/pages"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
)
|
||||
|
||||
type (
|
||||
C = layout.Context
|
||||
D = layout.Dimensions
|
||||
)
|
||||
|
||||
type Page struct {
|
||||
*pages.Router
|
||||
|
||||
State messages.UIState
|
||||
}
|
||||
|
||||
func New(router *pages.Router) *Page {
|
||||
return &Page{
|
||||
Router: router,
|
||||
}
|
||||
}
|
||||
|
||||
var _ pages.Page = &Page{}
|
||||
|
||||
func (p *Page) Actions() []component.AppBarAction {
|
||||
return []component.AppBarAction{}
|
||||
}
|
||||
|
||||
func (p *Page) Overflow() []component.OverflowAction {
|
||||
return []component.OverflowAction{}
|
||||
}
|
||||
|
||||
func (p *Page) NavItem() component.NavItem {
|
||||
return component.NavItem{
|
||||
Name: "Skin Grabber",
|
||||
//Icon: icon.OtherIcon,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Page) Layout(gtx C, th *material.Theme) D {
|
||||
margin := layout.Inset{
|
||||
Top: unit.Dp(25),
|
||||
Bottom: unit.Dp(25),
|
||||
Right: unit.Dp(35),
|
||||
Left: unit.Dp(35),
|
||||
}
|
||||
|
||||
switch p.State {
|
||||
case messages.UIStateConnect:
|
||||
// display login page
|
||||
return margin.Layout(gtx, material.Label(th, 100, "connect Client").Layout)
|
||||
case messages.UIStateConnecting:
|
||||
// display connecting to server
|
||||
return margin.Layout(gtx, material.Label(th, 100, "Connecting").Layout)
|
||||
case messages.UIStateMain:
|
||||
// show the main ui
|
||||
return margin.Layout(gtx, func(gtx C) D {
|
||||
return layout.Flex{
|
||||
Axis: layout.Vertical,
|
||||
}.Layout(gtx,
|
||||
layout.Rigid(material.Label(th, 20, "Skin Basic UI").Layout),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return layout.Flex{}.Layout(gtx)
|
||||
}
|
||||
|
||||
func (u *Page) handler(name string, data interface{}) messages.MessageResponse {
|
||||
r := messages.MessageResponse{
|
||||
Ok: false,
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
switch name {
|
||||
case messages.SetUIState:
|
||||
state := data.(messages.UIState)
|
||||
u.State = state
|
||||
u.Router.Invalidate()
|
||||
r.Ok = true
|
||||
|
||||
case messages.Init:
|
||||
init := data.(messages.InitPayload)
|
||||
_ = init
|
||||
r.Ok = true
|
||||
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (p *Page) Handler() gui.HandlerFunc {
|
||||
return p.handler
|
||||
}
|
|
@ -11,7 +11,7 @@ import (
|
|||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/paint"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
||||
)
|
||||
|
||||
|
@ -86,7 +86,7 @@ func drawTile(img *image.RGBA, min, pos protocol.ChunkPos, tile *image.RGBA) {
|
|||
), tile, image.Point{}, draw.Src)
|
||||
}
|
||||
|
||||
func (m *Map) Update(u *utils.UpdateMapPayload) {
|
||||
func (m *Map) Update(u *messages.UpdateMapPayload) {
|
||||
if m.MapImage == nil {
|
||||
m.zoom = 1
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"gioui.org/x/component"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/gui/pages"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -19,7 +19,7 @@ type Page struct {
|
|||
*pages.Router
|
||||
|
||||
worldMap *Map
|
||||
State utils.UIState
|
||||
State messages.UIState
|
||||
chunkCount int
|
||||
voidGen bool
|
||||
worldName string
|
||||
|
@ -58,20 +58,20 @@ func (p *Page) Layout(gtx C, th *material.Theme) D {
|
|||
}
|
||||
|
||||
switch p.State {
|
||||
case utils.UIStateConnect:
|
||||
case messages.UIStateConnect:
|
||||
// display login page
|
||||
return margin.Layout(gtx, material.Label(th, 100, "connect Client").Layout)
|
||||
case utils.UIStateConnecting:
|
||||
case messages.UIStateConnecting:
|
||||
// display connecting to server
|
||||
return margin.Layout(gtx, material.Label(th, 100, "Connecting").Layout)
|
||||
case utils.UIStateMain:
|
||||
case messages.UIStateMain:
|
||||
// show the main ui
|
||||
return margin.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
return margin.Layout(gtx, func(gtx C) D {
|
||||
return layout.Flex{
|
||||
Axis: layout.Vertical,
|
||||
}.Layout(gtx,
|
||||
layout.Rigid(material.Label(th, 20, "World Downloader Basic UI").Layout),
|
||||
layout.Flexed(1, func(gtx layout.Context) layout.Dimensions {
|
||||
layout.Flexed(1, func(gtx C) D {
|
||||
return layout.Center.Layout(gtx, p.worldMap.Layout)
|
||||
}),
|
||||
)
|
||||
|
@ -81,39 +81,39 @@ func (p *Page) Layout(gtx C, th *material.Theme) D {
|
|||
return layout.Flex{}.Layout(gtx)
|
||||
}
|
||||
|
||||
func (u *Page) handler(name string, data interface{}) utils.MessageResponse {
|
||||
r := utils.MessageResponse{
|
||||
func (u *Page) handler(name string, data interface{}) messages.MessageResponse {
|
||||
r := messages.MessageResponse{
|
||||
Ok: false,
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
switch name {
|
||||
case utils.SetUIStateName:
|
||||
state := data.(utils.UIState)
|
||||
case messages.SetUIState:
|
||||
state := data.(messages.UIState)
|
||||
u.State = state
|
||||
u.Router.Invalidate()
|
||||
r.Ok = true
|
||||
|
||||
case utils.InitName:
|
||||
init := data.(utils.InitPayload)
|
||||
case messages.Init:
|
||||
init := data.(messages.InitPayload)
|
||||
_ = init
|
||||
r.Ok = true
|
||||
|
||||
case utils.UpdateMapName:
|
||||
update_map := data.(utils.UpdateMapPayload)
|
||||
case messages.UpdateMap:
|
||||
update_map := data.(messages.UpdateMapPayload)
|
||||
u.chunkCount = update_map.ChunkCount
|
||||
u.worldMap.Update(&update_map)
|
||||
u.Router.Invalidate()
|
||||
r.Ok = true
|
||||
|
||||
case utils.SetVoidGenName:
|
||||
set_void_gen := data.(utils.SetVoidGenPayload)
|
||||
case messages.SetVoidGen:
|
||||
set_void_gen := data.(messages.SetVoidGenPayload)
|
||||
u.voidGen = set_void_gen.Value
|
||||
u.Router.Invalidate()
|
||||
r.Ok = true
|
||||
|
||||
case utils.SetWorldNameName:
|
||||
set_world_name := data.(utils.SetWorldNamePayload)
|
||||
case messages.SetWorldName:
|
||||
set_world_name := data.(messages.SetWorldNamePayload)
|
||||
u.worldName = set_world_name.WorldName
|
||||
u.Router.Invalidate()
|
||||
r.Ok = true
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package settings
|
||||
|
||||
import (
|
||||
"gioui.org/layout"
|
||||
"gioui.org/unit"
|
||||
"gioui.org/widget"
|
||||
"gioui.org/widget/material"
|
||||
"github.com/bedrock-tool/bedrocktool/subcommands/skins"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
)
|
||||
|
||||
type skinsSettings struct {
|
||||
skins *skins.SkinCMD
|
||||
|
||||
Filter widget.Editor
|
||||
Proxy widget.Bool
|
||||
serverAddress widget.Editor
|
||||
}
|
||||
|
||||
func (s *skinsSettings) Init() {
|
||||
s.skins = utils.ValidCMDs["skins"].(*skins.SkinCMD)
|
||||
s.serverAddress.SingleLine = true
|
||||
s.Filter.SingleLine = true
|
||||
s.Proxy.Value = true
|
||||
}
|
||||
|
||||
func (s *skinsSettings) Apply() {
|
||||
s.skins.Filter = s.Filter.Text()
|
||||
s.skins.NoProxy = !s.Proxy.Value
|
||||
s.skins.ServerAddress = s.serverAddress.Text()
|
||||
}
|
||||
|
||||
func (s *skinsSettings) Layout(gtx layout.Context, th *material.Theme) layout.Dimensions {
|
||||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
|
||||
layout.Rigid(material.CheckBox(th, &s.Proxy, "Enable Proxy").Layout),
|
||||
layout.Rigid(material.Editor(th, &s.Filter, "Player name filter").Layout),
|
||||
layout.Rigid(layout.Spacer{Height: unit.Dp(15)}.Layout),
|
||||
layout.Rigid(material.Editor(th, &s.serverAddress, "server Address").Layout),
|
||||
)
|
||||
}
|
||||
|
||||
func init() {
|
||||
Settings["skins"] = &skinsSettings{}
|
||||
}
|
|
@ -2,10 +2,10 @@ package gui
|
|||
|
||||
import (
|
||||
"gioui.org/layout"
|
||||
"github.com/bedrock-tool/bedrocktool/utils"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
)
|
||||
|
||||
type C = layout.Context
|
||||
type D = layout.Dimensions
|
||||
|
||||
type HandlerFunc = func(name string, data interface{}) utils.MessageResponse
|
||||
type HandlerFunc = func(name string, data interface{}) messages.MessageResponse
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package messages
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
@ -6,6 +6,11 @@ import (
|
|||
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
||||
)
|
||||
|
||||
type MessageResponse struct {
|
||||
Ok bool
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
type UIState = int
|
||||
|
||||
const (
|
||||
|
@ -16,27 +21,39 @@ const (
|
|||
|
||||
type HandlerFunc = func(name string, data interface{}) MessageResponse
|
||||
|
||||
var SetUIStateName = "set_ui_state"
|
||||
//
|
||||
|
||||
var SetVoidGenName = "set_void_gen"
|
||||
const SetUIState = "set_ui_state"
|
||||
|
||||
type SetUIStatePayload = UIState
|
||||
|
||||
//
|
||||
|
||||
const SetVoidGen = "set_void_gen"
|
||||
|
||||
type SetVoidGenPayload struct {
|
||||
Value bool
|
||||
}
|
||||
|
||||
var SetWorldNameName = "set_world_name"
|
||||
//
|
||||
|
||||
const SetWorldName = "set_world_name"
|
||||
|
||||
type SetWorldNamePayload struct {
|
||||
WorldName string
|
||||
}
|
||||
|
||||
var InitName = "init"
|
||||
//
|
||||
|
||||
var Init = "init"
|
||||
|
||||
type InitPayload struct {
|
||||
Handler HandlerFunc
|
||||
}
|
||||
|
||||
var UpdateMapName = "update_map"
|
||||
//
|
||||
|
||||
var UpdateMap = "update_map"
|
||||
|
||||
type UpdateMapPayload struct {
|
||||
ChunkCount int
|
||||
|
@ -46,3 +63,12 @@ type UpdateMapPayload struct {
|
|||
BoundsMin protocol.ChunkPos
|
||||
BoundsMax protocol.ChunkPos
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var NewSkin = "new_skin"
|
||||
|
||||
type NewSkinPayload struct {
|
||||
PlayerName string
|
||||
Skin *protocol.Skin
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package behaviourpack
|
||||
|
||||
import "github.com/sandertv/gophertunnel/minecraft/protocol"
|
||||
import (
|
||||
"github.com/sandertv/gophertunnel/minecraft/protocol"
|
||||
)
|
||||
|
||||
type EntityDescription struct {
|
||||
Identifier string `json:"identifier"`
|
||||
|
@ -24,7 +26,7 @@ type entityBehaviour struct {
|
|||
type EntityIn struct {
|
||||
Identifier string
|
||||
Attr []protocol.AttributeValue
|
||||
Meta map[uint32]any
|
||||
Meta protocol.EntityMetadata
|
||||
}
|
||||
|
||||
func (bp *BehaviourPack) AddEntity(entity EntityIn) {
|
||||
|
@ -71,5 +73,12 @@ func (bp *BehaviourPack) AddEntity(entity EntityIn) {
|
|||
}
|
||||
}
|
||||
|
||||
hasCollision := entity.Meta.Flag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagHasCollision)
|
||||
hasGravity := entity.Meta.Flag(protocol.EntityDataKeyFlags, protocol.EntityDataFlagHasGravity)
|
||||
entry.MinecraftEntity.Components["minecraft:physics"] = map[string]any{
|
||||
"has_collision": hasCollision,
|
||||
"has_gravity": hasGravity,
|
||||
}
|
||||
|
||||
bp.entities[entity.Identifier] = entry
|
||||
}
|
||||
|
|
12
utils/iui.go
12
utils/iui.go
|
@ -9,19 +9,15 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/bedrock-tool/bedrocktool/locale"
|
||||
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
||||
"github.com/google/subcommands"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type MessageResponse struct {
|
||||
Ok bool
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
type UI interface {
|
||||
Init() bool
|
||||
Start(context.Context, context.CancelFunc) error
|
||||
Message(name string, data interface{}) MessageResponse
|
||||
Message(name string, data interface{}) messages.MessageResponse
|
||||
ServerInput(context.Context, string) (string, string, error)
|
||||
}
|
||||
|
||||
|
@ -29,8 +25,8 @@ type BaseUI struct {
|
|||
UI
|
||||
}
|
||||
|
||||
func (u *BaseUI) Message(name string, data interface{}) MessageResponse {
|
||||
return MessageResponse{
|
||||
func (u *BaseUI) Message(name string, data interface{}) messages.MessageResponse {
|
||||
return messages.MessageResponse{
|
||||
Ok: false,
|
||||
Data: nil,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue