refactor(frontend): everything
The player.go and ui.go files have been separated into their own separate packages. Additionally, all go.mod files have been modified to point to local directories. This change should not only clean up the frontend codebase, but also make it easier to send/recieve data from the backend (at least regarding the player)
This commit is contained in:
parent
f800cafb1d
commit
a8e3d0b291
3
frontend/assets/fonts/go.mod
Normal file
3
frontend/assets/fonts/go.mod
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module github.com/devraza/ambition/frontend/assets/fonts
|
||||||
|
|
||||||
|
go 1.20
|
|
@ -1,20 +1,29 @@
|
||||||
module github.com/devraza/ambition
|
module github.com/devraza/ambition/frontend
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ebitenui/ebitenui v0.5.4
|
github.com/devraza/ambition/frontend/player v0.0.0-00010101000000-000000000000
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
github.com/devraza/ambition/frontend/ui v0.0.0-00010101000000-000000000000
|
||||||
github.com/hajimehoshi/ebiten/v2 v2.5.5
|
github.com/hajimehoshi/ebiten/v2 v2.5.5
|
||||||
golang.org/x/image v0.7.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/devraza/ambition/frontend/assets/fonts v0.0.0-00010101000000-000000000000 // indirect
|
||||||
github.com/ebitengine/purego v0.3.2 // indirect
|
github.com/ebitengine/purego v0.3.2 // indirect
|
||||||
|
github.com/ebitenui/ebitenui v0.5.4 // indirect
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||||
github.com/jezek/xgb v1.1.0 // indirect
|
github.com/jezek/xgb v1.1.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
|
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
|
||||||
|
golang.org/x/image v0.9.0 // indirect
|
||||||
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 // indirect
|
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 // indirect
|
||||||
golang.org/x/sync v0.2.0 // indirect
|
golang.org/x/sync v0.2.0 // indirect
|
||||||
golang.org/x/sys v0.8.0 // indirect
|
golang.org/x/sys v0.8.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace (
|
||||||
|
github.com/devraza/ambition/frontend/assets/fonts => ./assets/fonts
|
||||||
|
github.com/devraza/ambition/frontend/player => ./player
|
||||||
|
github.com/devraza/ambition/frontend/ui => ./ui
|
||||||
|
)
|
||||||
|
|
|
@ -24,8 +24,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
|
||||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=
|
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=
|
||||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
|
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
|
||||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||||
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
|
golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g=
|
||||||
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
|
golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
|
||||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||||
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 h1:539vykMVJsmdiucRtMmdeLLZaTVhWhaAHFcPabj2lws=
|
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 h1:539vykMVJsmdiucRtMmdeLLZaTVhWhaAHFcPabj2lws=
|
||||||
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY=
|
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY=
|
||||||
|
@ -59,8 +59,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// Random
|
// Misc.
|
||||||
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
// Logs
|
// Ambition
|
||||||
"log"
|
p "github.com/devraza/ambition/frontend/player"
|
||||||
|
u "github.com/devraza/ambition/frontend/ui"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
// Ebitengine
|
// Ebitengine
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
@ -15,12 +15,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Initialise the test player
|
// Initialise the test player
|
||||||
var testPlayer = initPlayer()
|
var testPlayer = p.GetPlayer()
|
||||||
|
|
||||||
// Create the `Game` struct
|
// Create the `Game` struct
|
||||||
type Game struct {
|
type Game struct {
|
||||||
ui UI
|
ui u.UI
|
||||||
activePlayer Player
|
activePlayer p.Player
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the window width/height
|
// Define the window width/height
|
||||||
|
@ -31,15 +31,15 @@ const (
|
||||||
|
|
||||||
// Update implements Game
|
// Update implements Game
|
||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
g.ui.base.Update()
|
g.ui.Base.Update()
|
||||||
g.activePlayer.update()
|
g.activePlayer.Update()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw implements Game
|
// Draw implements Game
|
||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
// Draw the UI onto the screen
|
// Draw the UI onto the screen
|
||||||
g.ui.base.Draw(screen)
|
g.ui.Base.Draw(screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Layout implements Game
|
// Layout implements Game
|
||||||
|
@ -63,13 +63,11 @@ func main() {
|
||||||
ebiten.SetWindowSize(window_width, window_height)
|
ebiten.SetWindowSize(window_width, window_height)
|
||||||
ebiten.SetWindowTitle(window_title)
|
ebiten.SetWindowTitle(window_title)
|
||||||
|
|
||||||
testPlayer := initPlayer()
|
|
||||||
|
|
||||||
// Initialise the game
|
// Initialise the game
|
||||||
game := Game{
|
game := Game{
|
||||||
// Initialise the UI
|
// Initialise the UI
|
||||||
activePlayer: testPlayer,
|
activePlayer: testPlayer,
|
||||||
ui: uiInit(window_width, window_height),
|
ui: u.UiInit(window_width, window_height),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log and exit on error
|
// Log and exit on error
|
||||||
|
|
3
frontend/player/go.mod
Normal file
3
frontend/player/go.mod
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module github.com/devraza/ambition/frontend/player
|
||||||
|
|
||||||
|
go 1.20
|
|
@ -1,16 +1,17 @@
|
||||||
package main
|
package player
|
||||||
|
|
||||||
import ()
|
import ()
|
||||||
|
|
||||||
// The player struct
|
// The player struct
|
||||||
type Player struct {
|
type Player struct {
|
||||||
health int
|
Health int
|
||||||
health_max int
|
MaxHealth int
|
||||||
defence int
|
Defence int
|
||||||
level int
|
Level int
|
||||||
exp float32
|
Exp float32
|
||||||
ambition float32
|
NextExp float32
|
||||||
ambition_max float32
|
Ambition float32
|
||||||
|
MaxAmbition float32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the maps for the level/(max) ambition gates
|
// Create the maps for the level/(max) ambition gates
|
||||||
|
@ -18,15 +19,16 @@ var level_gates = make(map[int]float32)
|
||||||
var level_ambition = make(map[int]float32)
|
var level_ambition = make(map[int]float32)
|
||||||
|
|
||||||
// TODO(midnadimple): Move player initialization to server upon login
|
// TODO(midnadimple): Move player initialization to server upon login
|
||||||
func initPlayer() Player {
|
func GetPlayer() Player {
|
||||||
return Player{
|
return Player{
|
||||||
health: 100,
|
Health: 100,
|
||||||
health_max: 100,
|
MaxHealth: 100,
|
||||||
defence: 0,
|
Defence: 0,
|
||||||
level: 1,
|
Level: 1,
|
||||||
exp: 0.0,
|
Exp: 0.0,
|
||||||
ambition: 0.0, // NOTE(midnadimple): In the future this will be affected by player activity
|
NextExp: 0.0,
|
||||||
ambition_max: level_ambition[1], // NOTE(midnadimple): In the future this will be affected by player activity
|
Ambition: 0.0, // NOTE(midnadimple): In the future this will be affected by player activity
|
||||||
|
MaxAmbition: level_ambition[1], // NOTE(midnadimple): In the future this will be affected by player activity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ func gain(basexp float32, modifier float32) float32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the player
|
// Update the player
|
||||||
func (p *Player) update() {
|
func (p *Player) Update() {
|
||||||
// TODO(midnadimple): update health upon damage
|
// TODO(midnadimple): update health upon damage
|
||||||
|
|
||||||
// Auto-generate the level gates
|
// Auto-generate the level gates
|
||||||
|
@ -70,10 +72,13 @@ func (p *Player) update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the XP needed for the player to reach the next level
|
||||||
|
p.NextExp = level_gates[p.Level]
|
||||||
|
|
||||||
// Set the XP to 0 and increase both the level and max ambition on level up
|
// Set the XP to 0 and increase both the level and max ambition on level up
|
||||||
if p.exp >= level_gates[p.level] {
|
if p.Exp >= level_gates[p.Level] {
|
||||||
p.exp = 0.0
|
p.Exp = 0.0
|
||||||
p.level += 1
|
p.Level += 1
|
||||||
p.ambition_max = level_ambition[p.level]
|
p.MaxAmbition = level_ambition[p.Level]
|
||||||
}
|
}
|
||||||
}
|
}
|
24
frontend/ui/go.mod
Normal file
24
frontend/ui/go.mod
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
module github.com/devraza/ambition/frontend/ui
|
||||||
|
|
||||||
|
go 1.20
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/devraza/ambition/frontend/assets/fonts v0.0.0-00010101000000-000000000000
|
||||||
|
github.com/ebitenui/ebitenui v0.5.4
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||||
|
golang.org/x/image v0.9.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/ebitengine/purego v0.3.2 // indirect
|
||||||
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
|
||||||
|
github.com/hajimehoshi/ebiten/v2 v2.5.4 // indirect
|
||||||
|
github.com/jezek/xgb v1.1.0 // indirect
|
||||||
|
golang.org/x/exp/shiny v0.0.0-20230522175609-2e198f4a06a1 // indirect
|
||||||
|
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 // indirect
|
||||||
|
golang.org/x/sync v0.2.0 // indirect
|
||||||
|
golang.org/x/sys v0.8.0 // indirect
|
||||||
|
)
|
||||||
|
|
||||||
|
replace github.com/devraza/ambition/frontend/assets/fonts => ../assets/fonts
|
||||||
|
replace github.com/devraza/ambition/frontend/player => ../player
|
61
frontend/ui/go.sum
Normal file
61
frontend/ui/go.sum
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/ebitengine/purego v0.3.2 h1:+pV+tskAkn/bxEcUzGtDfw2VAe3bRQ26kdzFjPPrCww=
|
||||||
|
github.com/ebitengine/purego v0.3.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
||||||
|
github.com/ebitenui/ebitenui v0.5.4 h1:iXFIa+W/MZG88gGDwOvCU9TSzecnZsXWkrve+jjorEI=
|
||||||
|
github.com/ebitenui/ebitenui v0.5.4/go.mod h1:2iyyjninLWNQLZ+pdV/eJ9vRnSs+I+HrzEBLEIH4Y9A=
|
||||||
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU=
|
||||||
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||||
|
github.com/hajimehoshi/bitmapfont/v2 v2.2.3 h1:jmq/TMNj352V062Tr5e3hAoipkoxCbY1JWTzor0zNps=
|
||||||
|
github.com/hajimehoshi/ebiten/v2 v2.5.4 h1:NvUU6LvVc6oc+u+rD9KfHMjruRdpNwbpalVUINNXufU=
|
||||||
|
github.com/hajimehoshi/ebiten/v2 v2.5.4/go.mod h1:mnHSOVysTr/nUZrN1lBTRqhK4NG+T9NR3JsJP2rCppk=
|
||||||
|
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
|
||||||
|
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
|
||||||
|
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||||
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/exp/shiny v0.0.0-20230522175609-2e198f4a06a1 h1:NxHSRPlbeyFGDc6rU7YsvxV/4bXS9XhuvUt5pP63XUs=
|
||||||
|
golang.org/x/exp/shiny v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
|
||||||
|
golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g=
|
||||||
|
golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
|
||||||
|
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 h1:539vykMVJsmdiucRtMmdeLLZaTVhWhaAHFcPabj2lws=
|
||||||
|
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
|
||||||
|
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||||
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
||||||
|
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// Image-related packages
|
// Image-related packages
|
||||||
|
@ -8,24 +8,30 @@ import (
|
||||||
// Misc.
|
// Misc.
|
||||||
// "fmt"
|
// "fmt"
|
||||||
|
|
||||||
|
// Ambition
|
||||||
|
p "github.com/devraza/ambition/frontend/player"
|
||||||
|
|
||||||
// EbitenUI
|
// EbitenUI
|
||||||
"github.com/ebitenui/ebitenui"
|
"github.com/ebitenui/ebitenui"
|
||||||
"github.com/ebitenui/ebitenui/image"
|
"github.com/ebitenui/ebitenui/image"
|
||||||
"github.com/ebitenui/ebitenui/widget"
|
"github.com/ebitenui/ebitenui/widget"
|
||||||
|
|
||||||
// Fonts
|
// Fonts
|
||||||
"github.com/devraza/ambition/assets/fonts"
|
"github.com/devraza/ambition/frontend/assets/fonts"
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"golang.org/x/image/font"
|
"golang.org/x/image/font"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The UI struct
|
// The UI struct
|
||||||
type UI struct {
|
type UI struct {
|
||||||
base ebitenui.UI
|
Base ebitenui.UI
|
||||||
colors map[string]color.RGBA
|
colors map[string]color.RGBA
|
||||||
width, height int
|
width, height int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the player from the `player` package
|
||||||
|
var player = p.GetPlayer()
|
||||||
|
|
||||||
// The `hazakura` colorscheme (default)
|
// The `hazakura` colorscheme (default)
|
||||||
var hazakura = map[string]color.RGBA{
|
var hazakura = map[string]color.RGBA{
|
||||||
// The monotone colors
|
// The monotone colors
|
||||||
|
@ -49,7 +55,7 @@ var hazakura = map[string]color.RGBA{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function for UI initialization
|
// Function for UI initialization
|
||||||
func uiInit(width, height int) UI {
|
func UiInit(width, height int) UI {
|
||||||
var ui UI
|
var ui UI
|
||||||
|
|
||||||
// Define the UI colors
|
// Define the UI colors
|
||||||
|
@ -194,14 +200,14 @@ func uiInit(width, height int) UI {
|
||||||
)
|
)
|
||||||
// Place the window and add the window to the UI
|
// Place the window and add the window to the UI
|
||||||
showWindow(chat, ui, float32(width)-float32(width)/3.6, float32(height)-float32(height)/3.5)
|
showWindow(chat, ui, float32(width)-float32(width)/3.6, float32(height)-float32(height)/3.5)
|
||||||
ui.base.AddWindow(chat)
|
ui.Base.AddWindow(chat)
|
||||||
|
|
||||||
// Set the position and size of the left bar
|
// Set the position and size of the left bar
|
||||||
leftBar.SetLocation(img.Rect(0, 0, int(float32(width)/3.5), height))
|
leftBar.SetLocation(img.Rect(0, 0, int(float32(width)/3.5), height))
|
||||||
// Add the left bar to the root container
|
// Add the left bar to the root container
|
||||||
root.AddChild(leftBar)
|
root.AddChild(leftBar)
|
||||||
|
|
||||||
ui.base.Container = root
|
ui.Base.Container = root
|
||||||
|
|
||||||
return ui
|
return ui
|
||||||
}
|
}
|
||||||
|
@ -251,46 +257,11 @@ func makeStatsBars(parent *widget.TabBookTab, ui UI, face font.Face) {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// Set the min, max, and current values for each progressbar
|
// Set the min, max, and current values for each progressbar
|
||||||
widget.ProgressBarOpts.Values(0, testPlayer.health, testPlayer.health),
|
widget.ProgressBarOpts.Values(0, player.Health, player.MaxHealth),
|
||||||
)
|
)
|
||||||
parent.AddChild(health)
|
parent.AddChild(health)
|
||||||
parent.AddChild(health_progressbar)
|
parent.AddChild(health_progressbar)
|
||||||
|
|
||||||
// Defence
|
|
||||||
defence := widget.NewText(
|
|
||||||
widget.TextOpts.Text("Defence", face, ui.colors["white"]),
|
|
||||||
widget.TextOpts.WidgetOpts(widget.WidgetOpts.LayoutData(widget.GridLayoutData{
|
|
||||||
HorizontalPosition: widget.GridLayoutPositionStart,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
defence_progressbar := widget.NewProgressBar(
|
|
||||||
widget.ProgressBarOpts.WidgetOpts(
|
|
||||||
// Set the required anchor layout data to determine where in the container to place the progressbar
|
|
||||||
widget.WidgetOpts.LayoutData(widget.AnchorLayoutData{
|
|
||||||
HorizontalPosition: widget.AnchorLayoutPositionCenter,
|
|
||||||
VerticalPosition: widget.AnchorLayoutPositionCenter,
|
|
||||||
}),
|
|
||||||
// Set the minimum size for the progressbar.
|
|
||||||
widget.WidgetOpts.MinSize(200, 20),
|
|
||||||
),
|
|
||||||
widget.ProgressBarOpts.Images(
|
|
||||||
// Set the track colors
|
|
||||||
&widget.ProgressBarImage{
|
|
||||||
Idle: image.NewNineSliceColor(ui.colors["black"]),
|
|
||||||
Hover: image.NewNineSliceColor(ui.colors["black"]),
|
|
||||||
},
|
|
||||||
// Set the progress colors
|
|
||||||
&widget.ProgressBarImage{
|
|
||||||
Idle: image.NewNineSliceColor(ui.colors["yellow"]),
|
|
||||||
Hover: image.NewNineSliceColor(ui.colors["yellow"]),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
// Set the min, max, and current values for each progressbar
|
|
||||||
widget.ProgressBarOpts.Values(0, testPlayer.health, testPlayer.health),
|
|
||||||
)
|
|
||||||
parent.AddChild(defence)
|
|
||||||
parent.AddChild(defence_progressbar)
|
|
||||||
|
|
||||||
// XP/Level
|
// XP/Level
|
||||||
level := widget.NewText(
|
level := widget.NewText(
|
||||||
widget.TextOpts.Text("Level", face, ui.colors["white"]),
|
widget.TextOpts.Text("Level", face, ui.colors["white"]),
|
||||||
|
@ -321,7 +292,7 @@ func makeStatsBars(parent *widget.TabBookTab, ui UI, face font.Face) {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// Set the min, max, and current values for each progressbar
|
// Set the min, max, and current values for each progressbar
|
||||||
widget.ProgressBarOpts.Values(0, testPlayer.health, testPlayer.health_max),
|
widget.ProgressBarOpts.Values(0, int(player.Exp), int(player.NextExp)),
|
||||||
)
|
)
|
||||||
parent.AddChild(level)
|
parent.AddChild(level)
|
||||||
parent.AddChild(level_progressbar)
|
parent.AddChild(level_progressbar)
|
||||||
|
@ -356,7 +327,7 @@ func makeStatsBars(parent *widget.TabBookTab, ui UI, face font.Face) {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// Set the min, max, and current values for each progressbar
|
// Set the min, max, and current values for each progressbar
|
||||||
widget.ProgressBarOpts.Values(0, testPlayer.health, testPlayer.health),
|
widget.ProgressBarOpts.Values(0, int(player.Ambition), int(player.MaxAmbition)),
|
||||||
)
|
)
|
||||||
parent.AddChild(ambition)
|
parent.AddChild(ambition)
|
||||||
parent.AddChild(ambition_progressbar)
|
parent.AddChild(ambition_progressbar)
|
Reference in a new issue