diff --git a/Makefile b/Makefile index 9de9081..fb79b69 100644 --- a/Makefile +++ b/Makefile @@ -4,4 +4,5 @@ build: go build -o dist/game.exe dep: go mod tidy - +doc: + godoc -http=:3000 \ No newline at end of file diff --git a/src/konstructor/config.go b/src/konstructor/config.go index 6c15920..642fc8c 100644 --- a/src/konstructor/config.go +++ b/src/konstructor/config.go @@ -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 diff --git a/src/konstructor/interface.domain.go b/src/konstructor/interface.domain.go index 39e4a28..fb7d81c 100644 --- a/src/konstructor/interface.domain.go +++ b/src/konstructor/interface.domain.go @@ -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) } diff --git a/src/konstructor/interface.engine.go b/src/konstructor/interface.engine.go index e326183..34e89c5 100644 --- a/src/konstructor/interface.engine.go +++ b/src/konstructor/interface.engine.go @@ -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() diff --git a/src/konstructor/kcontext.go b/src/konstructor/kcontext.go index 1ae323d..158c0f8 100644 --- a/src/konstructor/kcontext.go +++ b/src/konstructor/kcontext.go @@ -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 } diff --git a/src/konstructor/konstructor.go b/src/konstructor/konstructor.go index 531bc5f..16a9332 100644 --- a/src/konstructor/konstructor.go +++ b/src/konstructor/konstructor.go @@ -7,6 +7,7 @@ type Konstructor struct { EngineWrapper EngineWrapperInterface } +// Framework initialization func (k Konstructor) Init() { k.Domain.Init() k.EngineWrapper.Init(EngineArgs{ diff --git a/src/konstructor/layout.font.go b/src/konstructor/layout.font.go index c919f67..077c125 100644 --- a/src/konstructor/layout.font.go +++ b/src/konstructor/layout.font.go @@ -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" } diff --git a/src/konstructor/layout.render.go b/src/konstructor/layout.render.go index c73a1e9..85cfb1b 100644 --- a/src/konstructor/layout.render.go +++ b/src/konstructor/layout.render.go @@ -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 diff --git a/src/konstructor/object.go b/src/konstructor/object.go index 28250e9..62d595c 100644 --- a/src/konstructor/object.go +++ b/src/konstructor/object.go @@ -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] + "/" } diff --git a/src/konstructor/object.item.go b/src/konstructor/object.item.go index a0046a1..7a19d6b 100644 --- a/src/konstructor/object.item.go +++ b/src/konstructor/object.item.go @@ -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" } diff --git a/src/konstructor/object.npc.go b/src/konstructor/object.npc.go index 1e655b3..e051b29 100644 --- a/src/konstructor/object.npc.go +++ b/src/konstructor/object.npc.go @@ -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" } diff --git a/src/konstructor/object.platform.go b/src/konstructor/object.platform.go index 63b4df7..2ddd11d 100644 --- a/src/konstructor/object.platform.go +++ b/src/konstructor/object.platform.go @@ -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" } diff --git a/src/konstructor/object.player.go b/src/konstructor/object.player.go index b978985..3cf8af3 100644 --- a/src/konstructor/object.player.go +++ b/src/konstructor/object.player.go @@ -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" } diff --git a/src/konstructor/screen.dialog.go b/src/konstructor/screen.dialog.go index 9b71f5d..2d9da90 100644 --- a/src/konstructor/screen.dialog.go +++ b/src/konstructor/screen.dialog.go @@ -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 diff --git a/src/konstructor/screen.menu.go b/src/konstructor/screen.menu.go index 229d6d2..2c146d1 100644 --- a/src/konstructor/screen.menu.go +++ b/src/konstructor/screen.menu.go @@ -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 diff --git a/src/konstructor/screen.playground.go b/src/konstructor/screen.playground.go index ba4bd15..318755b 100644 --- a/src/konstructor/screen.playground.go +++ b/src/konstructor/screen.playground.go @@ -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" } diff --git a/src/konstructor/screen.type.go b/src/konstructor/screen.type.go index 50eddbd..b56b0d6 100644 --- a/src/konstructor/screen.type.go +++ b/src/konstructor/screen.type.go @@ -1,5 +1,6 @@ package konstructor +// Type of screen type for method input validation type ScreenType string const (