Fix references in graphical code to protocol/packet packages
Go / lint (push) Failing after 28s Details
Go / build (push) Failing after 3m24s Details

This commit is contained in:
Marcel M. Otte 2023-10-30 22:51:13 +01:00
parent 32b2f6054d
commit 21c43afa18
10 changed files with 19 additions and 27 deletions

View File

@ -2,14 +2,14 @@ package ui
import ( import (
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"gitea.mmo.to/ppForge/ppforge/protocolctl" "gitea.mmo.to/ppForge/ppforge/protocol"
) )
// GetAdder returns a fyne button which on click creates a new field in the editor // GetAdder returns a fyne button which on click creates a new field in the editor
func GetAdder(pEd *ProtocolEditor) *widget.Button { func GetAdder(pEd *ProtocolEditor) *widget.Button {
fieldAdder := widget.NewButton("Add Field", func() { fieldAdder := widget.NewButton("Add Field", func() {
f := protocolctl.NewEmptyField() f := protocol.NewEmptyField()
index := protocolctl.AppendField(pEd.Reference, *f) index := pEd.Reference.AppendField(*f)
pEd.AddFieldCreator(CreateFieldEditor(pEd, index, f)) pEd.AddFieldCreator(CreateFieldEditor(pEd, index, f))
}) })
return fieldAdder return fieldAdder

View File

@ -10,7 +10,6 @@ import (
"fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"gitea.mmo.to/ppForge/ppforge/protocol" "gitea.mmo.to/ppForge/ppforge/protocol"
"gitea.mmo.to/ppForge/ppforge/protocolctl"
) )
// FieldEditor is a struct holding all elements of the field editor ui // FieldEditor is a struct holding all elements of the field editor ui
@ -43,10 +42,9 @@ func CreateFieldEditor(ed *ProtocolEditor, index int, ref *protocol.Field) *Fiel
} else { } else {
bits, _ = strconv.Atoi(fc.SizeValue.Text) bits, _ = strconv.Atoi(fc.SizeValue.Text)
} }
protocolctl.UpdateFieldByElement( ed.Reference.UpdateFieldByElement(
ed.Reference,
fc.Index, fc.Index,
protocolctl.NewField( protocol.NewField(
fc.NameValue.Text, fc.NameValue.Text,
fc.DescValue.Text, fc.DescValue.Text,
fc.RegExValue.Text, fc.RegExValue.Text,
@ -56,20 +54,20 @@ func CreateFieldEditor(ed *ProtocolEditor, index int, ref *protocol.Field) *Fiel
fc.PayloadCheck.Checked, fc.PayloadCheck.Checked,
), ),
) )
fmt.Printf("%s", protocolctl.ToJson(ed.Reference)) fmt.Printf("%s", ed.Reference.ToJSON())
} }
fc.Representation = container.New(layout.NewFormLayout()) fc.Representation = container.New(layout.NewFormLayout())
toolbar := widget.NewToolbar() toolbar := widget.NewToolbar()
toolbar.Append(widget.NewToolbarAction(theme.DeleteIcon(), func() { toolbar.Append(widget.NewToolbarAction(theme.DeleteIcon(), func() {
protocolctl.RemoveFieldByElement(ed.Reference, fc.Index) ed.Reference.RemoveFieldByElement(fc.Index)
ed.Redraw() ed.Redraw()
})) }))
fc.Representation.Add(toolbar) fc.Representation.Add(toolbar)
addtool := widget.NewToolbar() addtool := widget.NewToolbar()
addtool.Append(widget.NewToolbarSpacer()) addtool.Append(widget.NewToolbarSpacer())
addtool.Append(widget.NewToolbarAction(theme.ContentAddIcon(), func() { addtool.Append(widget.NewToolbarAction(theme.ContentAddIcon(), func() {
protocolctl.AddField(ed.Reference, fc.Index+1, protocolctl.NewEmptyField()) ed.Reference.AddField(fc.Index+1, protocol.NewEmptyField())
ed.Redraw() ed.Redraw()
})) }))
fc.Representation.Add(container.NewBorder(nil, nil, nil, addtool, widget.NewLabel("Field Values"))) fc.Representation.Add(container.NewBorder(nil, nil, nil, addtool, widget.NewLabel("Field Values")))

View File

@ -9,7 +9,6 @@ import (
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"gitea.mmo.to/ppForge/ppforge/packet" "gitea.mmo.to/ppForge/ppforge/packet"
"gitea.mmo.to/ppForge/ppforge/protocol" "gitea.mmo.to/ppForge/ppforge/protocol"
"gitea.mmo.to/ppForge/ppforge/protocolctl"
) )
type Metadata struct { type Metadata struct {
@ -90,7 +89,7 @@ func NewMetadataProtocol() *ProtocolMetadata {
func (md *ProtocolMetadata) SetProtocol(prot *protocol.Protocol) { func (md *ProtocolMetadata) SetProtocol(prot *protocol.Protocol) {
setfunc := func(s string) { setfunc := func(s string) {
protocolctl.UpdateMetaData( protocol.UpdateMetaData(
prot, prot,
md.NameValue.Text, md.NameValue.Text,
md.VersionValue.Text, md.VersionValue.Text,
@ -99,7 +98,7 @@ func (md *ProtocolMetadata) SetProtocol(prot *protocol.Protocol) {
md.ExtendsValue.Text, md.ExtendsValue.Text,
md.DescValue.Text, md.DescValue.Text,
) )
fmt.Printf("%s", protocolctl.ToJson(prot)) fmt.Printf("%s", prot.ToJSON())
} }
md.NameValue.SetText(prot.Metadata.Name) md.NameValue.SetText(prot.Metadata.Name)
md.VersionValue.SetText(prot.Metadata.Version) md.VersionValue.SetText(prot.Metadata.Version)

View File

@ -6,7 +6,6 @@ import (
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"gitea.mmo.to/ppForge/ppforge/packet" "gitea.mmo.to/ppForge/ppforge/packet"
"gitea.mmo.to/ppForge/ppforge/packetctl"
) )
type PacketEditor struct { type PacketEditor struct {
@ -30,7 +29,7 @@ func NewPacketEditor(ref *packet.Packet) *PacketEditor {
} }
func (ed *PacketEditor) Redraw() { func (ed *PacketEditor) Redraw() {
json := packetctl.ToJson(ed.Reference) json := ed.Reference.ToJSON()
fmt.Printf("%s\n", json) fmt.Printf("%s\n", json)
ed.FieldContainer.RemoveAll() ed.FieldContainer.RemoveAll()

View File

@ -5,7 +5,6 @@ import (
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"gitea.mmo.to/ppForge/ppforge/packet" "gitea.mmo.to/ppForge/ppforge/packet"
"gitea.mmo.to/ppForge/ppforge/packetctl"
) )
type PacketFieldEditor struct { type PacketFieldEditor struct {
@ -34,7 +33,7 @@ func CreatePacketFieldEditor(
setfunc := func(s string) { setfunc := func(s string) {
//todo //todo
packetctl.UpdateField(&ed.Reference.Layers[lyridx], index, packetctl.NewFieldValue(s)) //ed.Reference.UpdateField(&ed.Reference.Layers[lyridx], index, packet.NewFieldValue(s))
} }
elements := []fyne.CanvasObject{} elements := []fyne.CanvasObject{}

View File

@ -3,7 +3,6 @@ package ui
import ( import (
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"gitea.mmo.to/ppForge/ppforge/packet" "gitea.mmo.to/ppForge/ppforge/packet"
"gitea.mmo.to/ppForge/ppforge/packetctl"
) )
// PacketFileHandler implements TabProvider, FileHandler // PacketFileHandler implements TabProvider, FileHandler
@ -21,7 +20,7 @@ func NewPacketFileHandler() *PacketFileHandler {
pfh := PacketFileHandler{} pfh := PacketFileHandler{}
pfh.name = "*new" pfh.name = "*new"
pfh.changed = true pfh.changed = true
pfh.Reference = packetctl.NewPacketStructure() pfh.Reference = packet.NewPacketStructure()
pfh.PacketEditor = NewPacketEditor(pfh.Reference) pfh.PacketEditor = NewPacketEditor(pfh.Reference)
return &pfh return &pfh
} }

View File

@ -6,7 +6,6 @@ import (
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"gitea.mmo.to/ppForge/ppforge/protocol" "gitea.mmo.to/ppForge/ppforge/protocol"
"gitea.mmo.to/ppForge/ppforge/protocolctl"
) )
type ProtocolEditor struct { type ProtocolEditor struct {
@ -33,7 +32,7 @@ func (ed *ProtocolEditor) AddFieldCreator(fieldCreator *FieldEditor) {
} }
func (ed *ProtocolEditor) Redraw() { func (ed *ProtocolEditor) Redraw() {
json := protocolctl.ToJson(ed.Reference) json := ed.Reference.ToJSON()
fmt.Printf("%s", json) fmt.Printf("%s", json)
ed.FieldContainer.RemoveAll() ed.FieldContainer.RemoveAll()
// existing fields // existing fields

View File

@ -6,7 +6,6 @@ import (
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"gitea.mmo.to/ppForge/ppforge/protocol" "gitea.mmo.to/ppForge/ppforge/protocol"
"gitea.mmo.to/ppForge/ppforge/protocolctl"
) )
// implements FileHandler, TabProvider // implements FileHandler, TabProvider
@ -24,13 +23,13 @@ func NewProtocolFileHandler() *ProtocolFileHandler {
pfh := ProtocolFileHandler{} pfh := ProtocolFileHandler{}
pfh.name = "*new" pfh.name = "*new"
pfh.changed = true pfh.changed = true
pfh.ProtocolEditor = NewProtocolEditor(protocolctl.NewProtocolStructure()) pfh.ProtocolEditor = NewProtocolEditor(protocol.NewProtocolStructure())
pfh.Reference = pfh.ProtocolEditor.Reference pfh.Reference = pfh.ProtocolEditor.Reference
return &pfh return &pfh
} }
func (pfh *ProtocolFileHandler) Load() error { func (pfh *ProtocolFileHandler) Load() error {
prot, err := protocolctl.LoadNew(pfh.Path()) prot, err := protocol.LoadNew(pfh.Path())
if err != nil { if err != nil {
// process error // process error
err = nil err = nil
@ -55,7 +54,7 @@ func (pfh *ProtocolFileHandler) Open(path string) error {
return pfh.Load() return pfh.Load()
} }
func (pfh *ProtocolFileHandler) Save() error { func (pfh *ProtocolFileHandler) Save() error {
err := protocolctl.Save(pfh.Reference, pfh.path) err := pfh.Reference.Save(pfh.path)
if err != nil { if err != nil {
fmt.Printf("%v\n", err) fmt.Printf("%v\n", err)
} }

View File

@ -161,7 +161,7 @@ func (pack *Packet) UpdateData() {
pack.Sha1 = fmt.Sprintf("%x", sha1.Sum(pack.data)) pack.Sha1 = fmt.Sprintf("%x", sha1.Sum(pack.data))
} }
func (pack *Packet) ToJson() string { func (pack *Packet) ToJSON() string {
pack.UpdateData() pack.UpdateData()
data, err := json.MarshalIndent(*pack, "", " ") data, err := json.MarshalIndent(*pack, "", " ")
if err != nil { if err != nil {

View File

@ -144,5 +144,5 @@ func TestRemoveFieldByElement(t *testing.T) {
func TestToJson(t *testing.T) { func TestToJson(t *testing.T) {
p := GenerateStructure() p := GenerateStructure()
fmt.Print(p.ToJson()) fmt.Print(p.ToJSON())
} }