Client initial commit.

This commit is contained in:
2024-12-10 18:55:23 -05:00
commit ca681f08cd
20 changed files with 870 additions and 0 deletions

BIN
client/fonts/bitbybit.ttf Normal file

Binary file not shown.

81
client/fonts/fonts.go Normal file
View File

@@ -0,0 +1,81 @@
package fonts
import (
"bytes"
"log"
_ "embed"
"github.com/hajimehoshi/ebiten/v2/text/v2"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
"golang.org/x/image/font/sfnt"
)
const (
FontDPI = 72
FontSizeStandard = 16
FontSizeLarge = 24
)
type FontStruct struct {
Standard font.Face
Large font.Face
New *text.GoTextFaceSource
Bitfont *text.GoTextFaceSource
}
var (
//go:embed vcrmono.ttf
vcrmono_ttf []byte
//go:embed bitbybit.ttf
bitbybit_ttf []byte
LaunchyFont FontStruct
)
func LoadFontFatal(src []byte) *sfnt.Font {
tt, err := opentype.Parse(src)
if err != nil {
log.Fatal(err)
}
return tt
}
func GetFaceFatal(fnt *sfnt.Font, dpi, size float64) font.Face {
var face font.Face
var err error
if dpi > 0 && size > 0 && fnt != nil {
face, err = opentype.NewFace(fnt, &opentype.FaceOptions{
Size: size,
DPI: dpi,
Hinting: font.HintingVertical,
})
if err != nil {
log.Fatal(err)
}
}
return face
}
func init() {
LaunchyFont = FontStruct{}
fnt := LoadFontFatal(vcrmono_ttf)
LaunchyFont.Standard = GetFaceFatal(fnt, FontDPI, FontSizeStandard)
LaunchyFont.Large = GetFaceFatal(fnt, FontDPI, FontSizeLarge)
s, err := text.NewGoTextFaceSource(bytes.NewReader(vcrmono_ttf))
if err != nil {
log.Fatal(err)
}
LaunchyFont.New = s
s, err = text.NewGoTextFaceSource(bytes.NewReader(bitbybit_ttf))
if err != nil {
log.Fatal(err)
}
LaunchyFont.Bitfont = s
}

BIN
client/fonts/vcrmono.ttf Normal file

Binary file not shown.