2019-10-24 09:31:59 -04:00
|
|
|
package OpenDiablo2
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
import "github.com/essial/OpenDiablo2/Palettes"
|
|
|
|
|
|
|
|
// MPQFontSize represents the size of a character in a font
|
2019-10-24 09:31:59 -04:00
|
|
|
type MPQFontSize struct {
|
|
|
|
Width uint8
|
|
|
|
Height uint8
|
|
|
|
}
|
|
|
|
|
2019-10-25 18:40:27 -04:00
|
|
|
// MPQFont represents a font
|
2019-10-24 09:31:59 -04:00
|
|
|
type MPQFont struct {
|
|
|
|
Engine *Engine
|
2019-10-25 18:40:27 -04:00
|
|
|
FontSprite *Sprite
|
2019-10-24 09:31:59 -04:00
|
|
|
Metrics map[uint8]MPQFontSize
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateMPQFont creates an instance of a MPQ Font
|
2019-10-25 18:40:27 -04:00
|
|
|
func CreateMPQFont(engine *Engine, font string, palette Palettes.Palette) *MPQFont {
|
2019-10-24 09:31:59 -04:00
|
|
|
result := &MPQFont{
|
|
|
|
Engine: engine,
|
|
|
|
Metrics: make(map[uint8]MPQFontSize),
|
|
|
|
}
|
|
|
|
result.FontSprite = result.Engine.LoadSprite(font+".dc6", palette)
|
|
|
|
woo := "Woo!\x01"
|
|
|
|
fontData := result.Engine.GetFile(font + ".tbl")
|
|
|
|
if string(fontData[0:5]) != woo {
|
|
|
|
panic("No woo :(")
|
|
|
|
}
|
|
|
|
for i := 12; i < len(fontData); i += 14 {
|
|
|
|
fontSize := MPQFontSize{
|
|
|
|
Width: fontData[i+3],
|
|
|
|
Height: fontData[i+4],
|
|
|
|
}
|
|
|
|
result.Metrics[fontData[i+8]] = fontSize
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|