Skip to content

Commit

Permalink
Move Vassal structs to root
Browse files Browse the repository at this point in the history
  • Loading branch information
sayden committed Oct 29, 2024
1 parent 6b48bea commit 9d8394c
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 111 deletions.
124 changes: 13 additions & 111 deletions output/counters_to_vassal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,122 +12,24 @@ import (
"github.com/sayden/counters/fsops"
)

type gameModule struct {
XMLName xml.Name `xml:"VASSAL.build.GameModule"`
ModuleOther1 string `xml:"ModuleOther1,attr"`
ModuleOther2 string `xml:"ModuleOther2,attr"`
VassalVersion string `xml:"VassalVersion,attr"`
Description string `xml:"description,attr"`
Name string `xml:"name,attr"`
NextPieceSlotId string `xml:"nextPieceSlotId,attr"`
Version string `xml:"version,attr"`
BasicCommandEncoder capture `xml:"VASSAL.build.module.BasicCommandEncoder"`
Documentation capture `xml:"VASSAL.build.module.Documentation"`
Chatter capture `xml:"VASSAL.build.module.Chatter"`
KeyNamer capture `xml:"VASSAL.build.module.KeyNamer"`
PieceWindow PieceWindow
DiceButton []DiceButton `xml:"VASSAL.build.module.DiceButton"`
PlayerRoster capture `xml:"VASSAL.build.module.PlayerRoster"`
GlobalOptions capture `xml:"VASSAL.build.module.GlobalOptions"`
GamePieceDefinitions capture `xml:"VASSAL.build.module.gamepieceimage.GamePieceImageDefinitions"`
GlobalProperties capture `xml:"VASSAL.build.module.properties.GlobalProperties"`
GlobalTranslatableMessages capture `xml:"VASSAL.build.module.properties.GlobalTranslatableMessages"`
PrototypesContainer capture `xml:"VASSAL.build.module.PrototypesContainer"`
Language capture `xml:"VASSAL.i18n.Language"`
Map capture `xml:"VASSAL.build.module.Map"`
}

type capture struct {
Raw string `xml:",innerxml"`
}
type DiceButton struct {
Raw string `xml:",innerxml"`
AddToTotal int `xml:"addToTotal,attr"`
CanDisable bool `xml:"canDisable,attr"`
DisabledIcon string `xml:"disabledIcon,attr"`
Hotkey string `xml:"hotkey,attr"`
Icon string `xml:"icon,attr"`
KeepCount string `xml:"keepCount,attr"`
KeepDice string `xml:"keepDice,attr"`
KeepOption string `xml:"keepOption,attr"`
LockAdd string `xml:"lockAdd,attr"`
LockDice string `xml:"lockDice,attr"`
LockPlus string `xml:"lockPlus,attr"`
LockSides string `xml:"lockSides,attr"`
NDice string `xml:"nDice,attr"`
NSides string `xml:"nSides,attr"`
Name string `xml:"name,attr"`
Plus string `xml:"plus,attr"`
Prompt string `xml:"prompt,attr"`
PropertyGate string `xml:"propertyGate,attr"`
ReportFormat string `xml:"reportFormat,attr"`
ReportTotal string `xml:"reportTotal,attr"`
SortDice string `xml:"sortDice,attr"`
Text string `xml:"text,attr"`
Tooltip string `xml:"tooltip,attr"`
}

type PieceWindow struct {
XMLName xml.Name `xml:"VASSAL.build.module.PieceWindow"`
DefaultWidth string `xml:"defaultWidth,attr"`
Hidden string `xml:"hidden,attr"`
Hotkey string `xml:"hotkey,attr"`
Icon string `xml:"icon,attr"`
Scale string `xml:"scale,attr"`
Text string `xml:"text,attr"`
ToolTip string `xml:"tooltip,attr"`
TabWidget tabWidget
}

type tabWidget struct {
XMLName xml.Name `xml:"VASSAL.build.widget.TabWidget"`
EntryName string `xml:"entryName,attr"`
ListWidget []listWidget `xml:"VASSAL.build.widget.ListWidget"`
}

type listWidget struct {
XMLName xml.Name `xml:"VASSAL.build.widget.ListWidget"`
Divider string `xml:"divider,attr"`
EntryName string `xml:"entryName,attr"`
Height string `xml:"height,attr"`
Scale string `xml:"scale,attr"`
Width string `xml:"width,attr"`
PieceSlot []pieceSlot
}

type pieceSlot struct {
XMLName xml.Name `xml:"VASSAL.build.widget.PieceSlot"`
EntryName string `xml:"entryName,attr"`
Gpid string `xml:"gpid,attr"`
Height int `xml:"height,attr"`
Width int `xml:"width,attr"`
Data string `xml:",chardata"`
}

type templateData struct {
Filename string
PieceName string
Id string
}

// GetVassalDataForCounters returns the Vassal module data for the counters
func GetVassalDataForCounters(t *counters.CounterTemplate, xmlFilepath string) ([]byte, error) {
var g gameModule
var g counters.GameModule
err := fsops.ReadMarkupFile(xmlFilepath, &g)
if err != nil {
return nil, errors.Wrap(err, "error trying to decode content")
}

tw := tabWidget{
tw := counters.TabWidget{
EntryName: "Forces",
ListWidget: make([]listWidget, 0),
ListWidget: make([]counters.ListWidget, 0),
}

forces := make(map[string]listWidget)
forces := make(map[string]counters.ListWidget)

forces["Markers"] = listWidget{
forces["Markers"] = counters.ListWidget{
EntryName: "Markers",
PieceSlot: make([]pieceSlot, 0),
PieceSlot: make([]counters.PieceSlot, 0),
Scale: "1.0",
Height: "215",
Width: "562",
Expand All @@ -152,7 +54,7 @@ func GetVassalDataForCounters(t *counters.CounterTemplate, xmlFilepath string) (
for _, file := range files {
buf := bytes.NewBufferString("")
if err = xmlTemplate.ExecuteTemplate(
buf, "xml", templateData{
buf, "xml", counters.TemplateData{
Filename: file, //+1 because file number starts in 1 instead of 0 when they are generated
PieceName: file,
Id: fmt.Sprintf("%d", id),
Expand All @@ -162,7 +64,7 @@ func GetVassalDataForCounters(t *counters.CounterTemplate, xmlFilepath string) (
}
id++

piece := pieceSlot{
piece := counters.PieceSlot{
EntryName: file,
Gpid: fmt.Sprintf("%d", gpid),
Height: t.Height,
Expand All @@ -182,7 +84,7 @@ func GetVassalDataForCounters(t *counters.CounterTemplate, xmlFilepath string) (
for i, counter := range t.Counters {
buf := bytes.NewBufferString("")
if err = xmlTemplate.ExecuteTemplate(
buf, "xml", templateData{
buf, "xml", counters.TemplateData{
Filename: counter.GetCounterFilename(
t.PositionNumberForFilename,
"",
Expand All @@ -197,7 +99,7 @@ func GetVassalDataForCounters(t *counters.CounterTemplate, xmlFilepath string) (
}
id++

piece := pieceSlot{
piece := counters.PieceSlot{
EntryName: counter.GetTextInPosition(t.PositionNumberForFilename),
Gpid: fmt.Sprintf("%d", gpid),
Height: t.Height,
Expand All @@ -206,9 +108,9 @@ func GetVassalDataForCounters(t *counters.CounterTemplate, xmlFilepath string) (
}

if _, ok := forces[counter.Extra.Side]; !ok {
forces[counter.Extra.Side] = listWidget{
forces[counter.Extra.Side] = counters.ListWidget{
EntryName: counter.Extra.Side,
PieceSlot: make([]pieceSlot, 0),
PieceSlot: make([]counters.PieceSlot, 0),
Scale: "1.0",
Height: "215",
Width: "562",
Expand All @@ -223,7 +125,7 @@ func GetVassalDataForCounters(t *counters.CounterTemplate, xmlFilepath string) (
gpid++
}

tw.ListWidget = append(tw.ListWidget, mapToArray[listWidget](forces)...)
tw.ListWidget = append(tw.ListWidget, mapToArray[counters.ListWidget](forces)...)
g.PieceWindow.TabWidget = tw

byt, err := xml.MarshalIndent(g, "", " ")
Expand Down
107 changes: 107 additions & 0 deletions vassal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package counters

import "encoding/xml"

type GameModule struct {
XMLName xml.Name `xml:"VASSAL.build.GameModule"`

ModuleOther1 string `xml:"ModuleOther1,attr"`
ModuleOther2 string `xml:"ModuleOther2,attr"`
VassalVersion string `xml:"VassalVersion,attr"`
Description string `xml:"description,attr"`
Name string `xml:"name,attr"`
NextPieceSlotId string `xml:"nextPieceSlotId,attr"`
Version string `xml:"version,attr"`
BasicCommandEncoder Capture `xml:"VASSAL.build.module.BasicCommandEncoder"`
Documentation Capture `xml:"VASSAL.build.module.Documentation"`
Chatter Capture `xml:"VASSAL.build.module.Chatter"`
KeyNamer Capture `xml:"VASSAL.build.module.KeyNamer"`
PieceWindow PieceWindow
DiceButton []DiceButton `xml:"VASSAL.build.module.DiceButton"`
PlayerRoster Capture `xml:"VASSAL.build.module.PlayerRoster"`
GlobalOptions Capture `xml:"VASSAL.build.module.GlobalOptions"`
GamePieceDefinitions Capture `xml:"VASSAL.build.module.gamepieceimage.GamePieceImageDefinitions"`
GlobalProperties Capture `xml:"VASSAL.build.module.properties.GlobalProperties"`
GlobalTranslatableMessages Capture `xml:"VASSAL.build.module.properties.GlobalTranslatableMessages"`
PrototypesContainer Capture `xml:"VASSAL.build.module.PrototypesContainer"`
Language Capture `xml:"VASSAL.i18n.Language"`
Map Capture `xml:"VASSAL.build.module.Map"`
}

type Capture struct {
Raw string `xml:",innerxml"`
}

type DiceButton struct {
Raw string `xml:",innerxml"`
AddToTotal int `xml:"addToTotal,attr"`
CanDisable bool `xml:"canDisable,attr"`
DisabledIcon string `xml:"disabledIcon,attr"`
Hotkey string `xml:"hotkey,attr"`
Icon string `xml:"icon,attr"`
KeepCount string `xml:"keepCount,attr"`
KeepDice string `xml:"keepDice,attr"`
KeepOption string `xml:"keepOption,attr"`
LockAdd string `xml:"lockAdd,attr"`
LockDice string `xml:"lockDice,attr"`
LockPlus string `xml:"lockPlus,attr"`
LockSides string `xml:"lockSides,attr"`
NDice string `xml:"nDice,attr"`
NSides string `xml:"nSides,attr"`
Name string `xml:"name,attr"`
Plus string `xml:"plus,attr"`
Prompt string `xml:"prompt,attr"`
PropertyGate string `xml:"propertyGate,attr"`
ReportFormat string `xml:"reportFormat,attr"`
ReportTotal string `xml:"reportTotal,attr"`
SortDice string `xml:"sortDice,attr"`
Text string `xml:"text,attr"`
Tooltip string `xml:"tooltip,attr"`
}

type PieceWindow struct {
XMLName xml.Name `xml:"VASSAL.build.module.PieceWindow"`

DefaultWidth string `xml:"defaultWidth,attr"`
Hidden string `xml:"hidden,attr"`
Hotkey string `xml:"hotkey,attr"`
Icon string `xml:"icon,attr"`
Scale string `xml:"scale,attr"`
Text string `xml:"text,attr"`
ToolTip string `xml:"tooltip,attr"`
TabWidget TabWidget
}

type TabWidget struct {
XMLName xml.Name `xml:"VASSAL.build.widget.TabWidget"`

EntryName string `xml:"entryName,attr"`
ListWidget []ListWidget `xml:"VASSAL.build.widget.ListWidget"`
}

type ListWidget struct {
XMLName xml.Name `xml:"VASSAL.build.widget.ListWidget"`

Divider string `xml:"divider,attr"`
EntryName string `xml:"entryName,attr"`
Height string `xml:"height,attr"`
Scale string `xml:"scale,attr"`
Width string `xml:"width,attr"`
PieceSlot []PieceSlot
}

type PieceSlot struct {
XMLName xml.Name `xml:"VASSAL.build.widget.PieceSlot"`

EntryName string `xml:"entryName,attr"`
Gpid string `xml:"gpid,attr"`
Height int `xml:"height,attr"`
Width int `xml:"width,attr"`
Data string `xml:",chardata"`
}

type TemplateData struct {
Filename string
PieceName string
Id string
}

0 comments on commit 9d8394c

Please sign in to comment.