2022-11-03 13:54:49 +00:00
|
|
|
package d2target
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
2022-12-22 19:32:41 +00:00
|
|
|
const (
|
|
|
|
|
PrefixPadding = 10
|
|
|
|
|
PrefixWidth = 20
|
2023-01-24 01:19:38 +00:00
|
|
|
CenterPadding = 50
|
|
|
|
|
// 10px of padding top and bottom so text doesn't look squished
|
|
|
|
|
VerticalPadding = 20
|
2022-12-22 19:32:41 +00:00
|
|
|
)
|
|
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
type Class struct {
|
|
|
|
|
Fields []ClassField `json:"fields"`
|
|
|
|
|
Methods []ClassMethod `json:"methods"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ClassField struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
Visibility string `json:"visibility"`
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 08:47:13 +00:00
|
|
|
func (cf ClassField) Text(fontSize int) *MText {
|
2022-11-03 13:54:49 +00:00
|
|
|
return &MText{
|
|
|
|
|
Text: fmt.Sprintf("%s%s", cf.Name, cf.Type),
|
2023-02-06 08:47:13 +00:00
|
|
|
FontSize: fontSize,
|
2022-11-03 13:54:49 +00:00
|
|
|
IsBold: false,
|
|
|
|
|
IsItalic: false,
|
|
|
|
|
Shape: "class",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-22 19:32:41 +00:00
|
|
|
func (cf ClassField) VisibilityToken() string {
|
|
|
|
|
switch cf.Visibility {
|
|
|
|
|
case "protected":
|
|
|
|
|
return "#"
|
|
|
|
|
case "private":
|
|
|
|
|
return "-"
|
|
|
|
|
default:
|
|
|
|
|
return "+"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
type ClassMethod struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Return string `json:"return"`
|
|
|
|
|
Visibility string `json:"visibility"`
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 08:47:13 +00:00
|
|
|
func (cm ClassMethod) Text(fontSize int) *MText {
|
2022-11-03 13:54:49 +00:00
|
|
|
return &MText{
|
|
|
|
|
Text: fmt.Sprintf("%s%s", cm.Name, cm.Return),
|
2023-02-06 08:47:13 +00:00
|
|
|
FontSize: fontSize,
|
2022-11-03 13:54:49 +00:00
|
|
|
IsBold: false,
|
|
|
|
|
IsItalic: false,
|
|
|
|
|
Shape: "class",
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-22 19:32:41 +00:00
|
|
|
|
|
|
|
|
func (cm ClassMethod) VisibilityToken() string {
|
|
|
|
|
switch cm.Visibility {
|
|
|
|
|
case "protected":
|
|
|
|
|
return "#"
|
|
|
|
|
case "private":
|
|
|
|
|
return "-"
|
|
|
|
|
default:
|
|
|
|
|
return "+"
|
|
|
|
|
}
|
|
|
|
|
}
|