base documentation of konstructor

This commit is contained in:
2023-07-08 16:34:53 +02:00
parent e5c2294f6c
commit 638fb415ec
17 changed files with 80 additions and 1 deletions

View File

@@ -4,4 +4,5 @@ build:
go build -o dist/game.exe
dep:
go mod tidy
doc:
godoc -http=:3000

View File

@@ -2,31 +2,37 @@ package konstructor
import "image/color"
// Windows resolution set
type ResolutionSet struct {
Width int
Height int
}
// QVGA resolution set
var QVGAResolutionSet = ResolutionSet{
Width: 320,
Height: 240,
}
// VGA resolution set
var VGAResolutionSet = ResolutionSet{
Width: 640,
Height: 480,
}
// SVGA resolution set
var SVGAResolutionSet = ResolutionSet{
Width: 800,
Height: 600,
}
// XGA resolution set
var XGAResolutionSet = ResolutionSet{
Width: 1024,
Height: 768,
}
// List of resolution sets
var ResolutionSets = []ResolutionSet{
QVGAResolutionSet,
VGAResolutionSet,
@@ -34,6 +40,7 @@ var ResolutionSets = []ResolutionSet{
XGAResolutionSet,
}
// Keyboard layout configuration
type KeyMap struct {
Up any
Down any
@@ -45,17 +52,21 @@ type KeyMap struct {
Action3 any
}
// Screen configuration
type ScreenConfig struct {
Width int
Height int
Scale int
}
// Header configuration
type HeaderConfig struct {
BackgroundColor color.Color
Height int
FontLayout FontLayout
}
// Game configuration
type Config struct {
Name string
Screen *ScreenConfig
@@ -63,6 +74,7 @@ type Config struct {
KeyMap KeyMap
}
// Set screen resolution config to a resolution set
func (c *Config) SetResolution(set ResolutionSet) {
c.Screen.Width = set.Width
c.Screen.Height = set.Height

View File

@@ -1,5 +1,7 @@
package konstructor
// Base fields for Domain layer.
// You need to include this of your game's domain struct
type DomainBaseFields struct {
MenuMap MenuMap
DialogMap DialogMap
@@ -10,40 +12,66 @@ type DomainBaseFields struct {
NPCTypeMap NPCTypeMap
}
// Domain interface.
// You need to implement this interface in your game's domain struct
type DomainInterface interface {
// Domain initialization. This variable will invoke only once when the game starts
Init()
// Return with the default KContext object
GetInitialKContext() *KContext
// Return with the default config object
GetInitialConfig() *Config
// Return with the menu map
GetMenuMap() MenuMap
// Return with a specific menu
GetMenu(name MenuMapKey) Menu
// Owerride a specific menu
SetMenu(name MenuMapKey, menu Menu)
// Return with the dialog map
GetDialogMap() DialogMap
// Return with a specific dialog
GetDialog(name DialogMapKey) Dialog
// Override a specific menu
SetDialog(name DialogMapKey, menu Dialog)
// Get levels
GetLevels() []Level
// Get a specific level
GetLevel(index int) Level
// Get players for multiplayer game
GetPlayers() []Player
// Get a specific player for multiplayer game
GetPlayer(index int) Player
// Get the player for simple player game
GetDefaultPlayer() Player
// Return with the platform type map
GetPlatformTypeMap() PlatformTypeMap
// Return with a specific platform type
GetPlatformType(name PlatformTypeMapKey) PlatformType
// Return with the item type map
GetItemTypeMap() ItemTypeMap
// Return with a specific item type
GetItemType(name ItemTypeMapKey) ItemType
// Return with the NPC type map
GetNPCTypeMap() NPCTypeMap
// Return with a specific NPC type
GetNPCType(name NPCTypeMapKey) NPCType
// Add item to inventory
AddToInventory(item *Item) bool
// Remove item from inventory
RemoveFromInventory(item *Item) bool
// Use inventory item
UseInventoryItem(item *Item) bool
// Process game flow by Domain layer
Process(DomainProcessArgs)
}

View File

@@ -1,11 +1,13 @@
package konstructor
// Initial arguments of an engine
type EngineArgs struct {
Domain DomainInterface
KContext *KContext
Config *Config
}
// Engine wrapper interface. You need to implement to this for your EntityWrapper, which can run your game engine
type EngineWrapperInterface interface {
Init(options EngineArgs)
Run()

View File

@@ -1,5 +1,6 @@
package konstructor
// Framework context (state)
type KContext struct {
ScreenType ScreenType
ActiveMenu MenuMapKey
@@ -10,6 +11,7 @@ type KContext struct {
LiveCount int
}
// Check the current screen type
func (c *KContext) ScreenTypeIs(name ScreenType) bool {
return c.ScreenType == name
}

View File

@@ -7,6 +7,7 @@ type Konstructor struct {
EngineWrapper EngineWrapperInterface
}
// Framework initialization
func (k Konstructor) Init() {
k.Domain.Init()
k.EngineWrapper.Init(EngineArgs{

View File

@@ -8,8 +8,10 @@ import (
"golang.org/x/image/font/opentype"
)
// Font name type for function input validation
type FontName string
// Font preset
type FontLayout struct {
Path string
DPI float64
@@ -19,6 +21,7 @@ type FontLayout struct {
cachedFontFace font.Face
}
// Get font face from the preset
func (fl *FontLayout) GetFontFace(scale int) font.Face {
if fl.cachedFontFace != nil {
return fl.cachedFontFace
@@ -34,6 +37,7 @@ func (fl *FontLayout) GetFontFace(scale int) font.Face {
return font_face
}
// Helper, which return the path of font
func GetFontPath(name FontName) string {
return "assets/fonts/" + string(name) + ".ttf"
}

View File

@@ -7,6 +7,7 @@ import (
"log"
)
// Element render options
type Render struct {
Image string
Width int
@@ -15,6 +16,7 @@ type Render struct {
cachedImage image.Image
}
// Get image object from image path
func (ro *Render) GetImage() image.Image {
if ro.cachedImage != nil {
return ro.cachedImage

View File

@@ -1,5 +1,6 @@
package konstructor
// Object type type for function input validation
type ObjectType string
const (
@@ -9,6 +10,7 @@ const (
PlayerObjectType ObjectType = "player"
)
// Map of object type's directories
type ObjectDirectoryMap map[ObjectType]string
var ObjectDirectories = ObjectDirectoryMap{
@@ -18,6 +20,7 @@ var ObjectDirectories = ObjectDirectoryMap{
PlayerObjectType: "players",
}
// Return with the path of a specific object type asset directory
func GetObjectDirectory(name ObjectType) string {
return "assets/images/" + ObjectDirectories[name] + "/"
}

View File

@@ -4,17 +4,20 @@ type ItemTypeMapKey string
type ItemTypeMap map[ItemTypeMapKey]ItemType
// Type of item
type ItemType struct {
ID string
Render Render
}
// Playground usable item, which can be put in the Inventory
type Item struct {
ID string
Type ItemType
Position Position
}
// Helper, which return with the path of a specific item type
func GetItemTypeImagePath(name ItemTypeMapKey) string {
return GetObjectDirectory(ItemObjectType) + string(name) + ".png"
}

View File

@@ -15,6 +15,7 @@ type NPC struct {
Position Position
}
// Helper, which return with the path of a specific NPC type
func GetNPCTypeImagePath(name NPCTypeMapKey) string {
return GetObjectDirectory(NPCObjectType) + string(name) + ".png"
}

View File

@@ -15,6 +15,7 @@ type Platform struct {
Position Position
}
// Helper, which return with the path of a specific platform type
func GetPlatformTypeImagePath(name PlatformTypeMapKey) string {
return GetObjectDirectory(PlatformObjectType) + string(name) + ".png"
}

View File

@@ -8,15 +8,18 @@ type InventoryItem struct {
Active bool
}
// Player inventory
type Inventory struct {
Items []InventoryItem
}
// Player type
type PlayerType struct {
ID PlayerTypeID
Render Render
}
// Playable character
type Player struct {
ID string
Type PlayerType
@@ -24,6 +27,7 @@ type Player struct {
Inventory Inventory
}
// Helper, which return with the path of a specific player type
func GetPlayerTypeImagePath(name PlayerTypeID) string {
return GetObjectDirectory(PlayerObjectType) + string(name) + ".png"
}

View File

@@ -6,23 +6,27 @@ type DialogMapKey string
type DialogMap map[DialogMapKey]Dialog
// Layout of dialog
type DialogLayout struct {
Render Render
ChoiceFont FontLayout
}
// Choicable answer in a dialog (by player)
type DialogChoice struct {
ID string
Label string
Handler func()
}
// Dialog between player and NPC
type Dialog struct {
CurrentSelected int
Layout DialogLayout
Choices []DialogChoice
}
// Return with color of choice
func (dialog *Dialog) GetChoiceColor(i int) color.Color {
if dialog.CurrentSelected == i {
return dialog.Layout.ChoiceFont.SelectedColor

View File

@@ -4,24 +4,29 @@ import "image/color"
type MenuMapKey string
// Map of menus
type MenuMap map[MenuMapKey]Menu
// Layout of menu
type MenuLayout struct {
MenuItemFont FontLayout
}
// Menu item
type MenuItem struct {
ID string
Label string
Handler func()
}
// Game menu
type Menu struct {
CurrentSelected int
Layout MenuLayout
MenuItems []MenuItem
}
// Return with the color of menu item
func (menu *Menu) GetMenuItemColor(i int) color.Color {
if menu.CurrentSelected == i {
return menu.Layout.MenuItemFont.SelectedColor

View File

@@ -1,13 +1,16 @@
package konstructor
// ID of playground for method input validation
type PlaygroundID string
// Position configuration
type Position struct {
X int
Y int
Z int
}
// Displayable section of a level
type Playground struct {
ID PlaygroundID
Render Render
@@ -16,12 +19,14 @@ type Playground struct {
Items []Item
}
// Game level
type Level struct {
ID string
Name string
Playgrounds []Playground
}
// Return with the path of a specific playground background
func GetPlaygroundImagePath(name PlaygroundID) string {
return "assets/images/playgrounds/" + string(name) + ".png"
}

View File

@@ -1,5 +1,6 @@
package konstructor
// Type of screen type for method input validation
type ScreenType string
const (