base documentation of konstructor
This commit is contained in:
3
Makefile
3
Makefile
@@ -4,4 +4,5 @@ build:
|
|||||||
go build -o dist/game.exe
|
go build -o dist/game.exe
|
||||||
dep:
|
dep:
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
doc:
|
||||||
|
godoc -http=:3000
|
||||||
@@ -2,31 +2,37 @@ package konstructor
|
|||||||
|
|
||||||
import "image/color"
|
import "image/color"
|
||||||
|
|
||||||
|
// Windows resolution set
|
||||||
type ResolutionSet struct {
|
type ResolutionSet struct {
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QVGA resolution set
|
||||||
var QVGAResolutionSet = ResolutionSet{
|
var QVGAResolutionSet = ResolutionSet{
|
||||||
Width: 320,
|
Width: 320,
|
||||||
Height: 240,
|
Height: 240,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VGA resolution set
|
||||||
var VGAResolutionSet = ResolutionSet{
|
var VGAResolutionSet = ResolutionSet{
|
||||||
Width: 640,
|
Width: 640,
|
||||||
Height: 480,
|
Height: 480,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SVGA resolution set
|
||||||
var SVGAResolutionSet = ResolutionSet{
|
var SVGAResolutionSet = ResolutionSet{
|
||||||
Width: 800,
|
Width: 800,
|
||||||
Height: 600,
|
Height: 600,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XGA resolution set
|
||||||
var XGAResolutionSet = ResolutionSet{
|
var XGAResolutionSet = ResolutionSet{
|
||||||
Width: 1024,
|
Width: 1024,
|
||||||
Height: 768,
|
Height: 768,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List of resolution sets
|
||||||
var ResolutionSets = []ResolutionSet{
|
var ResolutionSets = []ResolutionSet{
|
||||||
QVGAResolutionSet,
|
QVGAResolutionSet,
|
||||||
VGAResolutionSet,
|
VGAResolutionSet,
|
||||||
@@ -34,6 +40,7 @@ var ResolutionSets = []ResolutionSet{
|
|||||||
XGAResolutionSet,
|
XGAResolutionSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keyboard layout configuration
|
||||||
type KeyMap struct {
|
type KeyMap struct {
|
||||||
Up any
|
Up any
|
||||||
Down any
|
Down any
|
||||||
@@ -45,17 +52,21 @@ type KeyMap struct {
|
|||||||
Action3 any
|
Action3 any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Screen configuration
|
||||||
type ScreenConfig struct {
|
type ScreenConfig struct {
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
Scale int
|
Scale int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Header configuration
|
||||||
type HeaderConfig struct {
|
type HeaderConfig struct {
|
||||||
BackgroundColor color.Color
|
BackgroundColor color.Color
|
||||||
Height int
|
Height int
|
||||||
FontLayout FontLayout
|
FontLayout FontLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Game configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string
|
Name string
|
||||||
Screen *ScreenConfig
|
Screen *ScreenConfig
|
||||||
@@ -63,6 +74,7 @@ type Config struct {
|
|||||||
KeyMap KeyMap
|
KeyMap KeyMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set screen resolution config to a resolution set
|
||||||
func (c *Config) SetResolution(set ResolutionSet) {
|
func (c *Config) SetResolution(set ResolutionSet) {
|
||||||
c.Screen.Width = set.Width
|
c.Screen.Width = set.Width
|
||||||
c.Screen.Height = set.Height
|
c.Screen.Height = set.Height
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package konstructor
|
package konstructor
|
||||||
|
|
||||||
|
// Base fields for Domain layer.
|
||||||
|
// You need to include this of your game's domain struct
|
||||||
type DomainBaseFields struct {
|
type DomainBaseFields struct {
|
||||||
MenuMap MenuMap
|
MenuMap MenuMap
|
||||||
DialogMap DialogMap
|
DialogMap DialogMap
|
||||||
@@ -10,40 +12,66 @@ type DomainBaseFields struct {
|
|||||||
NPCTypeMap NPCTypeMap
|
NPCTypeMap NPCTypeMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Domain interface.
|
||||||
|
// You need to implement this interface in your game's domain struct
|
||||||
type DomainInterface interface {
|
type DomainInterface interface {
|
||||||
|
// Domain initialization. This variable will invoke only once when the game starts
|
||||||
Init()
|
Init()
|
||||||
|
|
||||||
|
// Return with the default KContext object
|
||||||
GetInitialKContext() *KContext
|
GetInitialKContext() *KContext
|
||||||
|
// Return with the default config object
|
||||||
GetInitialConfig() *Config
|
GetInitialConfig() *Config
|
||||||
|
|
||||||
|
// Return with the menu map
|
||||||
GetMenuMap() MenuMap
|
GetMenuMap() MenuMap
|
||||||
|
// Return with a specific menu
|
||||||
GetMenu(name MenuMapKey) Menu
|
GetMenu(name MenuMapKey) Menu
|
||||||
|
// Owerride a specific menu
|
||||||
SetMenu(name MenuMapKey, menu Menu)
|
SetMenu(name MenuMapKey, menu Menu)
|
||||||
|
|
||||||
|
// Return with the dialog map
|
||||||
GetDialogMap() DialogMap
|
GetDialogMap() DialogMap
|
||||||
|
// Return with a specific dialog
|
||||||
GetDialog(name DialogMapKey) Dialog
|
GetDialog(name DialogMapKey) Dialog
|
||||||
|
// Override a specific menu
|
||||||
SetDialog(name DialogMapKey, menu Dialog)
|
SetDialog(name DialogMapKey, menu Dialog)
|
||||||
|
|
||||||
|
// Get levels
|
||||||
GetLevels() []Level
|
GetLevels() []Level
|
||||||
|
// Get a specific level
|
||||||
GetLevel(index int) Level
|
GetLevel(index int) Level
|
||||||
|
|
||||||
|
// Get players for multiplayer game
|
||||||
GetPlayers() []Player
|
GetPlayers() []Player
|
||||||
|
// Get a specific player for multiplayer game
|
||||||
GetPlayer(index int) Player
|
GetPlayer(index int) Player
|
||||||
|
// Get the player for simple player game
|
||||||
GetDefaultPlayer() Player
|
GetDefaultPlayer() Player
|
||||||
|
|
||||||
|
// Return with the platform type map
|
||||||
GetPlatformTypeMap() PlatformTypeMap
|
GetPlatformTypeMap() PlatformTypeMap
|
||||||
|
// Return with a specific platform type
|
||||||
GetPlatformType(name PlatformTypeMapKey) PlatformType
|
GetPlatformType(name PlatformTypeMapKey) PlatformType
|
||||||
|
|
||||||
|
// Return with the item type map
|
||||||
GetItemTypeMap() ItemTypeMap
|
GetItemTypeMap() ItemTypeMap
|
||||||
|
// Return with a specific item type
|
||||||
GetItemType(name ItemTypeMapKey) ItemType
|
GetItemType(name ItemTypeMapKey) ItemType
|
||||||
|
|
||||||
|
// Return with the NPC type map
|
||||||
GetNPCTypeMap() NPCTypeMap
|
GetNPCTypeMap() NPCTypeMap
|
||||||
|
// Return with a specific NPC type
|
||||||
GetNPCType(name NPCTypeMapKey) NPCType
|
GetNPCType(name NPCTypeMapKey) NPCType
|
||||||
|
|
||||||
|
// Add item to inventory
|
||||||
AddToInventory(item *Item) bool
|
AddToInventory(item *Item) bool
|
||||||
|
// Remove item from inventory
|
||||||
RemoveFromInventory(item *Item) bool
|
RemoveFromInventory(item *Item) bool
|
||||||
|
// Use inventory item
|
||||||
UseInventoryItem(item *Item) bool
|
UseInventoryItem(item *Item) bool
|
||||||
|
|
||||||
|
// Process game flow by Domain layer
|
||||||
Process(DomainProcessArgs)
|
Process(DomainProcessArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package konstructor
|
package konstructor
|
||||||
|
|
||||||
|
// Initial arguments of an engine
|
||||||
type EngineArgs struct {
|
type EngineArgs struct {
|
||||||
Domain DomainInterface
|
Domain DomainInterface
|
||||||
KContext *KContext
|
KContext *KContext
|
||||||
Config *Config
|
Config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Engine wrapper interface. You need to implement to this for your EntityWrapper, which can run your game engine
|
||||||
type EngineWrapperInterface interface {
|
type EngineWrapperInterface interface {
|
||||||
Init(options EngineArgs)
|
Init(options EngineArgs)
|
||||||
Run()
|
Run()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package konstructor
|
package konstructor
|
||||||
|
|
||||||
|
// Framework context (state)
|
||||||
type KContext struct {
|
type KContext struct {
|
||||||
ScreenType ScreenType
|
ScreenType ScreenType
|
||||||
ActiveMenu MenuMapKey
|
ActiveMenu MenuMapKey
|
||||||
@@ -10,6 +11,7 @@ type KContext struct {
|
|||||||
LiveCount int
|
LiveCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the current screen type
|
||||||
func (c *KContext) ScreenTypeIs(name ScreenType) bool {
|
func (c *KContext) ScreenTypeIs(name ScreenType) bool {
|
||||||
return c.ScreenType == name
|
return c.ScreenType == name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ type Konstructor struct {
|
|||||||
EngineWrapper EngineWrapperInterface
|
EngineWrapper EngineWrapperInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Framework initialization
|
||||||
func (k Konstructor) Init() {
|
func (k Konstructor) Init() {
|
||||||
k.Domain.Init()
|
k.Domain.Init()
|
||||||
k.EngineWrapper.Init(EngineArgs{
|
k.EngineWrapper.Init(EngineArgs{
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import (
|
|||||||
"golang.org/x/image/font/opentype"
|
"golang.org/x/image/font/opentype"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Font name type for function input validation
|
||||||
type FontName string
|
type FontName string
|
||||||
|
|
||||||
|
// Font preset
|
||||||
type FontLayout struct {
|
type FontLayout struct {
|
||||||
Path string
|
Path string
|
||||||
DPI float64
|
DPI float64
|
||||||
@@ -19,6 +21,7 @@ type FontLayout struct {
|
|||||||
cachedFontFace font.Face
|
cachedFontFace font.Face
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get font face from the preset
|
||||||
func (fl *FontLayout) GetFontFace(scale int) font.Face {
|
func (fl *FontLayout) GetFontFace(scale int) font.Face {
|
||||||
if fl.cachedFontFace != nil {
|
if fl.cachedFontFace != nil {
|
||||||
return fl.cachedFontFace
|
return fl.cachedFontFace
|
||||||
@@ -34,6 +37,7 @@ func (fl *FontLayout) GetFontFace(scale int) font.Face {
|
|||||||
return font_face
|
return font_face
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper, which return the path of font
|
||||||
func GetFontPath(name FontName) string {
|
func GetFontPath(name FontName) string {
|
||||||
return "assets/fonts/" + string(name) + ".ttf"
|
return "assets/fonts/" + string(name) + ".ttf"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Element render options
|
||||||
type Render struct {
|
type Render struct {
|
||||||
Image string
|
Image string
|
||||||
Width int
|
Width int
|
||||||
@@ -15,6 +16,7 @@ type Render struct {
|
|||||||
cachedImage image.Image
|
cachedImage image.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get image object from image path
|
||||||
func (ro *Render) GetImage() image.Image {
|
func (ro *Render) GetImage() image.Image {
|
||||||
if ro.cachedImage != nil {
|
if ro.cachedImage != nil {
|
||||||
return ro.cachedImage
|
return ro.cachedImage
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package konstructor
|
package konstructor
|
||||||
|
|
||||||
|
// Object type type for function input validation
|
||||||
type ObjectType string
|
type ObjectType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -9,6 +10,7 @@ const (
|
|||||||
PlayerObjectType ObjectType = "player"
|
PlayerObjectType ObjectType = "player"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Map of object type's directories
|
||||||
type ObjectDirectoryMap map[ObjectType]string
|
type ObjectDirectoryMap map[ObjectType]string
|
||||||
|
|
||||||
var ObjectDirectories = ObjectDirectoryMap{
|
var ObjectDirectories = ObjectDirectoryMap{
|
||||||
@@ -18,6 +20,7 @@ var ObjectDirectories = ObjectDirectoryMap{
|
|||||||
PlayerObjectType: "players",
|
PlayerObjectType: "players",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return with the path of a specific object type asset directory
|
||||||
func GetObjectDirectory(name ObjectType) string {
|
func GetObjectDirectory(name ObjectType) string {
|
||||||
return "assets/images/" + ObjectDirectories[name] + "/"
|
return "assets/images/" + ObjectDirectories[name] + "/"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,17 +4,20 @@ type ItemTypeMapKey string
|
|||||||
|
|
||||||
type ItemTypeMap map[ItemTypeMapKey]ItemType
|
type ItemTypeMap map[ItemTypeMapKey]ItemType
|
||||||
|
|
||||||
|
// Type of item
|
||||||
type ItemType struct {
|
type ItemType struct {
|
||||||
ID string
|
ID string
|
||||||
Render Render
|
Render Render
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Playground usable item, which can be put in the Inventory
|
||||||
type Item struct {
|
type Item struct {
|
||||||
ID string
|
ID string
|
||||||
Type ItemType
|
Type ItemType
|
||||||
Position Position
|
Position Position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper, which return with the path of a specific item type
|
||||||
func GetItemTypeImagePath(name ItemTypeMapKey) string {
|
func GetItemTypeImagePath(name ItemTypeMapKey) string {
|
||||||
return GetObjectDirectory(ItemObjectType) + string(name) + ".png"
|
return GetObjectDirectory(ItemObjectType) + string(name) + ".png"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type NPC struct {
|
|||||||
Position Position
|
Position Position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper, which return with the path of a specific NPC type
|
||||||
func GetNPCTypeImagePath(name NPCTypeMapKey) string {
|
func GetNPCTypeImagePath(name NPCTypeMapKey) string {
|
||||||
return GetObjectDirectory(NPCObjectType) + string(name) + ".png"
|
return GetObjectDirectory(NPCObjectType) + string(name) + ".png"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type Platform struct {
|
|||||||
Position Position
|
Position Position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper, which return with the path of a specific platform type
|
||||||
func GetPlatformTypeImagePath(name PlatformTypeMapKey) string {
|
func GetPlatformTypeImagePath(name PlatformTypeMapKey) string {
|
||||||
return GetObjectDirectory(PlatformObjectType) + string(name) + ".png"
|
return GetObjectDirectory(PlatformObjectType) + string(name) + ".png"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,18 @@ type InventoryItem struct {
|
|||||||
Active bool
|
Active bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Player inventory
|
||||||
type Inventory struct {
|
type Inventory struct {
|
||||||
Items []InventoryItem
|
Items []InventoryItem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Player type
|
||||||
type PlayerType struct {
|
type PlayerType struct {
|
||||||
ID PlayerTypeID
|
ID PlayerTypeID
|
||||||
Render Render
|
Render Render
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Playable character
|
||||||
type Player struct {
|
type Player struct {
|
||||||
ID string
|
ID string
|
||||||
Type PlayerType
|
Type PlayerType
|
||||||
@@ -24,6 +27,7 @@ type Player struct {
|
|||||||
Inventory Inventory
|
Inventory Inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper, which return with the path of a specific player type
|
||||||
func GetPlayerTypeImagePath(name PlayerTypeID) string {
|
func GetPlayerTypeImagePath(name PlayerTypeID) string {
|
||||||
return GetObjectDirectory(PlayerObjectType) + string(name) + ".png"
|
return GetObjectDirectory(PlayerObjectType) + string(name) + ".png"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,23 +6,27 @@ type DialogMapKey string
|
|||||||
|
|
||||||
type DialogMap map[DialogMapKey]Dialog
|
type DialogMap map[DialogMapKey]Dialog
|
||||||
|
|
||||||
|
// Layout of dialog
|
||||||
type DialogLayout struct {
|
type DialogLayout struct {
|
||||||
Render Render
|
Render Render
|
||||||
ChoiceFont FontLayout
|
ChoiceFont FontLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Choicable answer in a dialog (by player)
|
||||||
type DialogChoice struct {
|
type DialogChoice struct {
|
||||||
ID string
|
ID string
|
||||||
Label string
|
Label string
|
||||||
Handler func()
|
Handler func()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dialog between player and NPC
|
||||||
type Dialog struct {
|
type Dialog struct {
|
||||||
CurrentSelected int
|
CurrentSelected int
|
||||||
Layout DialogLayout
|
Layout DialogLayout
|
||||||
Choices []DialogChoice
|
Choices []DialogChoice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return with color of choice
|
||||||
func (dialog *Dialog) GetChoiceColor(i int) color.Color {
|
func (dialog *Dialog) GetChoiceColor(i int) color.Color {
|
||||||
if dialog.CurrentSelected == i {
|
if dialog.CurrentSelected == i {
|
||||||
return dialog.Layout.ChoiceFont.SelectedColor
|
return dialog.Layout.ChoiceFont.SelectedColor
|
||||||
|
|||||||
@@ -4,24 +4,29 @@ import "image/color"
|
|||||||
|
|
||||||
type MenuMapKey string
|
type MenuMapKey string
|
||||||
|
|
||||||
|
// Map of menus
|
||||||
type MenuMap map[MenuMapKey]Menu
|
type MenuMap map[MenuMapKey]Menu
|
||||||
|
|
||||||
|
// Layout of menu
|
||||||
type MenuLayout struct {
|
type MenuLayout struct {
|
||||||
MenuItemFont FontLayout
|
MenuItemFont FontLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Menu item
|
||||||
type MenuItem struct {
|
type MenuItem struct {
|
||||||
ID string
|
ID string
|
||||||
Label string
|
Label string
|
||||||
Handler func()
|
Handler func()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Game menu
|
||||||
type Menu struct {
|
type Menu struct {
|
||||||
CurrentSelected int
|
CurrentSelected int
|
||||||
Layout MenuLayout
|
Layout MenuLayout
|
||||||
MenuItems []MenuItem
|
MenuItems []MenuItem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return with the color of menu item
|
||||||
func (menu *Menu) GetMenuItemColor(i int) color.Color {
|
func (menu *Menu) GetMenuItemColor(i int) color.Color {
|
||||||
if menu.CurrentSelected == i {
|
if menu.CurrentSelected == i {
|
||||||
return menu.Layout.MenuItemFont.SelectedColor
|
return menu.Layout.MenuItemFont.SelectedColor
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
package konstructor
|
package konstructor
|
||||||
|
|
||||||
|
// ID of playground for method input validation
|
||||||
type PlaygroundID string
|
type PlaygroundID string
|
||||||
|
|
||||||
|
// Position configuration
|
||||||
type Position struct {
|
type Position struct {
|
||||||
X int
|
X int
|
||||||
Y int
|
Y int
|
||||||
Z int
|
Z int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Displayable section of a level
|
||||||
type Playground struct {
|
type Playground struct {
|
||||||
ID PlaygroundID
|
ID PlaygroundID
|
||||||
Render Render
|
Render Render
|
||||||
@@ -16,12 +19,14 @@ type Playground struct {
|
|||||||
Items []Item
|
Items []Item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Game level
|
||||||
type Level struct {
|
type Level struct {
|
||||||
ID string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
Playgrounds []Playground
|
Playgrounds []Playground
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return with the path of a specific playground background
|
||||||
func GetPlaygroundImagePath(name PlaygroundID) string {
|
func GetPlaygroundImagePath(name PlaygroundID) string {
|
||||||
return "assets/images/playgrounds/" + string(name) + ".png"
|
return "assets/images/playgrounds/" + string(name) + ".png"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package konstructor
|
package konstructor
|
||||||
|
|
||||||
|
// Type of screen type for method input validation
|
||||||
type ScreenType string
|
type ScreenType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Reference in New Issue
Block a user