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 (
"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

View File

@ -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")))

View File

@ -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)

View File

@ -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()

View File

@ -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{}

View File

@ -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
}

View File

@ -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

View File

@ -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)
}

View File

@ -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 {

View File

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