From 21c43afa18d792b6478275dbd9530baeda1998a0 Mon Sep 17 00:00:00 2001 From: "Marcel M. Otte" Date: Mon, 30 Oct 2023 22:51:13 +0100 Subject: [PATCH] Fix references in graphical code to protocol/packet packages --- internal/ui/fieldadd.go | 6 +++--- internal/ui/fieldeditor.go | 12 +++++------- internal/ui/metadata.go | 5 ++--- internal/ui/packeteditor.go | 3 +-- internal/ui/packetfieldeditor.go | 3 +-- internal/ui/packetfilehandler.go | 3 +-- internal/ui/protocoleditor.go | 3 +-- internal/ui/protocolfilehandler.go | 7 +++---- packet/packet.go | 2 +- protocol/protocol_test.go | 2 +- 10 files changed, 19 insertions(+), 27 deletions(-) diff --git a/internal/ui/fieldadd.go b/internal/ui/fieldadd.go index 85d06b3..6fb5f3f 100644 --- a/internal/ui/fieldadd.go +++ b/internal/ui/fieldadd.go @@ -2,14 +2,14 @@ package ui import ( "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 func GetAdder(pEd *ProtocolEditor) *widget.Button { fieldAdder := widget.NewButton("Add Field", func() { - f := protocolctl.NewEmptyField() - index := protocolctl.AppendField(pEd.Reference, *f) + f := protocol.NewEmptyField() + index := pEd.Reference.AppendField(*f) pEd.AddFieldCreator(CreateFieldEditor(pEd, index, f)) }) return fieldAdder diff --git a/internal/ui/fieldeditor.go b/internal/ui/fieldeditor.go index 247a37e..d985f57 100644 --- a/internal/ui/fieldeditor.go +++ b/internal/ui/fieldeditor.go @@ -10,7 +10,6 @@ import ( "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" "gitea.mmo.to/ppForge/ppforge/protocol" - "gitea.mmo.to/ppForge/ppforge/protocolctl" ) // 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 { bits, _ = strconv.Atoi(fc.SizeValue.Text) } - protocolctl.UpdateFieldByElement( - ed.Reference, + ed.Reference.UpdateFieldByElement( fc.Index, - protocolctl.NewField( + protocol.NewField( fc.NameValue.Text, fc.DescValue.Text, fc.RegExValue.Text, @@ -56,20 +54,20 @@ func CreateFieldEditor(ed *ProtocolEditor, index int, ref *protocol.Field) *Fiel fc.PayloadCheck.Checked, ), ) - fmt.Printf("%s", protocolctl.ToJson(ed.Reference)) + fmt.Printf("%s", ed.Reference.ToJSON()) } fc.Representation = container.New(layout.NewFormLayout()) toolbar := widget.NewToolbar() toolbar.Append(widget.NewToolbarAction(theme.DeleteIcon(), func() { - protocolctl.RemoveFieldByElement(ed.Reference, fc.Index) + ed.Reference.RemoveFieldByElement(fc.Index) ed.Redraw() })) fc.Representation.Add(toolbar) addtool := widget.NewToolbar() addtool.Append(widget.NewToolbarSpacer()) 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() })) fc.Representation.Add(container.NewBorder(nil, nil, nil, addtool, widget.NewLabel("Field Values"))) diff --git a/internal/ui/metadata.go b/internal/ui/metadata.go index cd2b018..ab10fa7 100644 --- a/internal/ui/metadata.go +++ b/internal/ui/metadata.go @@ -9,7 +9,6 @@ import ( "fyne.io/fyne/v2/widget" "gitea.mmo.to/ppForge/ppforge/packet" "gitea.mmo.to/ppForge/ppforge/protocol" - "gitea.mmo.to/ppForge/ppforge/protocolctl" ) type Metadata struct { @@ -90,7 +89,7 @@ func NewMetadataProtocol() *ProtocolMetadata { func (md *ProtocolMetadata) SetProtocol(prot *protocol.Protocol) { setfunc := func(s string) { - protocolctl.UpdateMetaData( + protocol.UpdateMetaData( prot, md.NameValue.Text, md.VersionValue.Text, @@ -99,7 +98,7 @@ func (md *ProtocolMetadata) SetProtocol(prot *protocol.Protocol) { md.ExtendsValue.Text, md.DescValue.Text, ) - fmt.Printf("%s", protocolctl.ToJson(prot)) + fmt.Printf("%s", prot.ToJSON()) } md.NameValue.SetText(prot.Metadata.Name) md.VersionValue.SetText(prot.Metadata.Version) diff --git a/internal/ui/packeteditor.go b/internal/ui/packeteditor.go index b51de2f..bdcc369 100644 --- a/internal/ui/packeteditor.go +++ b/internal/ui/packeteditor.go @@ -6,7 +6,6 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "gitea.mmo.to/ppForge/ppforge/packet" - "gitea.mmo.to/ppForge/ppforge/packetctl" ) type PacketEditor struct { @@ -30,7 +29,7 @@ func NewPacketEditor(ref *packet.Packet) *PacketEditor { } func (ed *PacketEditor) Redraw() { - json := packetctl.ToJson(ed.Reference) + json := ed.Reference.ToJSON() fmt.Printf("%s\n", json) ed.FieldContainer.RemoveAll() diff --git a/internal/ui/packetfieldeditor.go b/internal/ui/packetfieldeditor.go index 7d2cd49..76fd4ae 100644 --- a/internal/ui/packetfieldeditor.go +++ b/internal/ui/packetfieldeditor.go @@ -5,7 +5,6 @@ import ( "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/widget" "gitea.mmo.to/ppForge/ppforge/packet" - "gitea.mmo.to/ppForge/ppforge/packetctl" ) type PacketFieldEditor struct { @@ -34,7 +33,7 @@ func CreatePacketFieldEditor( setfunc := func(s string) { //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{} diff --git a/internal/ui/packetfilehandler.go b/internal/ui/packetfilehandler.go index e3f2aeb..146d34b 100644 --- a/internal/ui/packetfilehandler.go +++ b/internal/ui/packetfilehandler.go @@ -3,7 +3,6 @@ package ui import ( "fyne.io/fyne/v2/container" "gitea.mmo.to/ppForge/ppforge/packet" - "gitea.mmo.to/ppForge/ppforge/packetctl" ) // PacketFileHandler implements TabProvider, FileHandler @@ -21,7 +20,7 @@ func NewPacketFileHandler() *PacketFileHandler { pfh := PacketFileHandler{} pfh.name = "*new" pfh.changed = true - pfh.Reference = packetctl.NewPacketStructure() + pfh.Reference = packet.NewPacketStructure() pfh.PacketEditor = NewPacketEditor(pfh.Reference) return &pfh } diff --git a/internal/ui/protocoleditor.go b/internal/ui/protocoleditor.go index 420d4ab..5216f78 100644 --- a/internal/ui/protocoleditor.go +++ b/internal/ui/protocoleditor.go @@ -6,7 +6,6 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "gitea.mmo.to/ppForge/ppforge/protocol" - "gitea.mmo.to/ppForge/ppforge/protocolctl" ) type ProtocolEditor struct { @@ -33,7 +32,7 @@ func (ed *ProtocolEditor) AddFieldCreator(fieldCreator *FieldEditor) { } func (ed *ProtocolEditor) Redraw() { - json := protocolctl.ToJson(ed.Reference) + json := ed.Reference.ToJSON() fmt.Printf("%s", json) ed.FieldContainer.RemoveAll() // existing fields diff --git a/internal/ui/protocolfilehandler.go b/internal/ui/protocolfilehandler.go index f168f36..f1b534b 100644 --- a/internal/ui/protocolfilehandler.go +++ b/internal/ui/protocolfilehandler.go @@ -6,7 +6,6 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "gitea.mmo.to/ppForge/ppforge/protocol" - "gitea.mmo.to/ppForge/ppforge/protocolctl" ) // implements FileHandler, TabProvider @@ -24,13 +23,13 @@ func NewProtocolFileHandler() *ProtocolFileHandler { pfh := ProtocolFileHandler{} pfh.name = "*new" pfh.changed = true - pfh.ProtocolEditor = NewProtocolEditor(protocolctl.NewProtocolStructure()) + pfh.ProtocolEditor = NewProtocolEditor(protocol.NewProtocolStructure()) pfh.Reference = pfh.ProtocolEditor.Reference return &pfh } func (pfh *ProtocolFileHandler) Load() error { - prot, err := protocolctl.LoadNew(pfh.Path()) + prot, err := protocol.LoadNew(pfh.Path()) if err != nil { // process error err = nil @@ -55,7 +54,7 @@ func (pfh *ProtocolFileHandler) Open(path string) error { return pfh.Load() } func (pfh *ProtocolFileHandler) Save() error { - err := protocolctl.Save(pfh.Reference, pfh.path) + err := pfh.Reference.Save(pfh.path) if err != nil { fmt.Printf("%v\n", err) } diff --git a/packet/packet.go b/packet/packet.go index 432f845..4a1c6bc 100644 --- a/packet/packet.go +++ b/packet/packet.go @@ -161,7 +161,7 @@ func (pack *Packet) UpdateData() { pack.Sha1 = fmt.Sprintf("%x", sha1.Sum(pack.data)) } -func (pack *Packet) ToJson() string { +func (pack *Packet) ToJSON() string { pack.UpdateData() data, err := json.MarshalIndent(*pack, "", " ") if err != nil { diff --git a/protocol/protocol_test.go b/protocol/protocol_test.go index fc3c464..695251c 100644 --- a/protocol/protocol_test.go +++ b/protocol/protocol_test.go @@ -144,5 +144,5 @@ func TestRemoveFieldByElement(t *testing.T) { func TestToJson(t *testing.T) { p := GenerateStructure() - fmt.Print(p.ToJson()) + fmt.Print(p.ToJSON()) }