MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / LoadPanelLayout

Function LoadPanelLayout

internal/templates/panel.go:646–716  ·  view source on GitHub ↗

LoadPanelLayout loads a panel layout definition from the datafiles directory. name is relative to the panel-layouts/ subdirectory and has no extension. Example: LoadPanelLayout("character/status")

(name string)

Source from the content-addressed store, hash-verified

644// name is relative to the panel-layouts/ subdirectory and has no extension.
645// Example: LoadPanelLayout("character/status")
646func LoadPanelLayout(name string) (*PanelLayout, error) {
647 dataFiles := string(configs.GetFilePathsConfig().DataFiles)
648 path := dataFiles + "/panel-layouts/" + name + ".yaml"
649
650 data, err := os.ReadFile(path)
651 if err != nil {
652 return nil, fmt.Errorf("panel layout %q: %w", name, err)
653 }
654
655 var def panelLayoutDef
656 if err := yaml.Unmarshal(data, &def); err != nil {
657 return nil, fmt.Errorf("panel layout %q: %w", name, err)
658 }
659
660 border := borderFull
661 if borderStyle(def.Border) == borderOpen {
662 border = borderOpen
663 }
664
665 chars := charsetForName(def.Charset)
666
667 gap := def.Gap
668 if gap < 0 {
669 gap = 0
670 }
671
672 layout := &PanelLayout{
673 border: border,
674 chars: chars,
675 gap: gap,
676 margin: def.Margin,
677 defaultColor: def.DefaultColor,
678 byID: make(map[string]*Panel),
679 }
680
681 for _, sd := range def.Slots {
682 slot := &layoutSlot{}
683 for _, rd := range sd.Rows {
684 var rowPanels []*Panel
685 for _, pd := range rd.Panels {
686 cols := pd.Columns
687 if cols < 1 {
688 cols = 1
689 }
690 colGap := pd.ColumnGap
691 if colGap < 1 {
692 colGap = defaultColumnGap
693 }
694 panelChars := chars
695 if pd.Charset != "" {
696 panelChars = charsetForName(pd.Charset)
697 }
698 p := &Panel{
699 id: pd.ID,
700 title: pd.Title,
701 width: pd.Width,
702 border: border,
703 chars: panelChars,

Callers 15

buildStorageTextFunction · 0.92
PanelLayoutLoadFunction · 0.92
buildConditionsPanelFunction · 0.92
buildPeepPanelFunction · 0.92
buildPeepInventoryPanelFunction · 0.92
buildInventoryPanelFunction · 0.92
buildQuestsPanelFunction · 0.92
buildCooldownsPanelFunction · 0.92
buildSkillsPanelFunction · 0.92
buildJobsPanelFunction · 0.92
buildStatusPanelFunction · 0.92
buildStatusTrainPanelFunction · 0.92

Calls 4

GetFilePathsConfigFunction · 0.92
borderStyleTypeAlias · 0.85
charsetForNameFunction · 0.85
ReadFileMethod · 0.45

Tested by

no test coverage detected