Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form system broke after I wrote some shit codes #283

Closed
Endermanbugzjfc opened this issue Sep 22, 2021 · 3 comments
Closed

Form system broke after I wrote some shit codes #283

Endermanbugzjfc opened this issue Sep 22, 2021 · 3 comments

Comments

@Endermanbugzjfc
Copy link
Contributor

Endermanbugzjfc commented Sep 22, 2021

Reproduce

  1. Use my shit form package
  2. Call <- forms.ExitConfirmation(ps, nil)

Error

  • Expecting form appears on the screen, but it doesn't
  • No error on the console
  • Tested with Goland debugger, the SendForm() code is reached

Form package

Why I create this package

Implement a form submit and close callback system using channel.

Package content

package form_api

type Form interface {
	C() (Form, chan Form)
}

type baseForm struct {
	c chan Form
}

func (f baseForm) C() (Form, chan Form) {
	f.c = make(chan Form)
	return f, f.c
}

type closer struct {
	closed bool

	baseForm
}

func (c closer) Closed() bool {
	return c.closed
}
package form_api

import (
	"github.com/df-mc/dragonfly/server/player/form"
)

type Custom struct {
	closer
}

func (c Custom) Close(submitter form.Submitter) {
	c.closed = true
	c.Submit(submitter)
}

func (c Custom) Submit(form.Submitter) {
	select {
	case c.c <- c:
	default:
	}
}

Form

package forms

import (
	form_api "ZSMC-df/api/form-api"
	"ZSMC-df/api/message"
	player_session "ZSMC-df/player-session"
	"github.com/df-mc/dragonfly/server/player/form"
)

type ExitConfirmationForm struct {
	Y form.Button
	N form.Button

	form_api.Menu
}

func ExitConfirmation(ps *player_session.PlayerSession, _ form_api.Form) chan form_api.Form {
	f, c := ExitConfirmationForm{}.C()
	ps.P.SendForm(form.NewModal(f.(ExitConfirmationForm), ps.Message(message.New().
		FormTitle().
		Eng("Exit Confirmation").
		Zho("退出確認").
		Chs("退出确认"),
	)).WithBody(ps.Message(message.New().
		Text("§e").
		Eng("Are you sure to ").
		Zho("您是否要與伺服器").
		Chs("").
		Text("§l§6").
		Eng("disconnect from the server?").
		Zho("中斷連線?").
		Chs("中断连线?"),
	)))
	return c
}

Environment

  • github.com/df-mc/dragonfly v0.3.0
  • MCBE 1.17.11
  • macOS Big Sur 11.5.2
@Sandertv
Copy link
Member

Does this happen without your package?

@Endermanbugzjfc
Copy link
Contributor Author

Does this happen without your package?

No, I checked out the commit before I create the package, the form was shown.

@Endermanbugzjfc
Copy link
Contributor Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants