From 04ed9466f41c57ac70a177c27ec4c622769cff23 Mon Sep 17 00:00:00 2001 From: Natureknight Date: Wed, 1 Jul 2020 15:59:24 +0300 Subject: [PATCH] fixed linting issues in d2screen and d2render (#487) (#512) --- CONTRIBUTORS | 1 + d2core/d2render/d2render.go | 19 +++++++++++++++++-- d2core/d2screen/d2screen.go | 9 +++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 95dd8607..23615fd6 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -19,6 +19,7 @@ Maxime "malavv" Lavigne Ripolak dafe presiyan +Natureknight * DIABLO2 LOGO Jose Pardilla (th3-prophetman) diff --git a/d2core/d2render/d2render.go b/d2core/d2render/d2render.go index d0178a29..4cec0221 100644 --- a/d2core/d2render/d2render.go +++ b/d2core/d2render/d2render.go @@ -8,13 +8,17 @@ import ( ) var ( - ErrWasInit = errors.New("rendering system is already initialized") - ErrNotInit = errors.New("rendering system has not been initialized") + // ErrWasInit holding an error instance for initialized rendering system + ErrWasInit = errors.New("rendering system is already initialized") + // ErrNotInit holding an error instance for non-initialized rendering system + ErrNotInit = errors.New("rendering system has not been initialized") + // ErrInvalidRenderer holding an error instance for invalid rendering system specification ErrInvalidRenderer = errors.New("invalid rendering system specified") ) var singleton d2interface.Renderer +// Initialize the renderer func Initialize(rend d2interface.Renderer) error { verifyNotInit() singleton = rend @@ -22,57 +26,68 @@ func Initialize(rend d2interface.Renderer) error { return nil } +// SetWindowIcon sets the window icon by a given file name as string func SetWindowIcon(fileName string) { verifyWasInit() singleton.SetWindowIcon(fileName) } +// Run will run the renderer func Run(f func(d2interface.Surface) error, width, height int, title string) error { verifyWasInit() singleton.Run(f, width, height, title) return nil } +// IsDrawingSkipped checks whether the drawing is skipped func IsDrawingSkipped() bool { verifyWasInit() return singleton.IsDrawingSkipped() } +// CreateSurface creates a new surface, which returns the newly created surface or error func CreateSurface(surface d2interface.Surface) (d2interface.Surface, error) { verifyWasInit() return singleton.CreateSurface(surface) } +// NewSurface adds a new surface, and returns the new surface or error func NewSurface(width, height int, filter d2interface.Filter) (d2interface.Surface, error) { verifyWasInit() return singleton.NewSurface(width, height, filter) } +// IsFullScreen checks whether the window is on full screen func IsFullScreen() bool { verifyWasInit() return singleton.IsFullScreen() } +// SetFullScreen sets the window in fullscreen or windowed mode depending on the fullScreen flag func SetFullScreen(fullScreen bool) { verifyWasInit() singleton.SetFullScreen(fullScreen) } +// SetVSyncEnabled sets or unsets the VSync depending on the given vsync parameter flag func SetVSyncEnabled(vsync bool) { verifyWasInit() singleton.SetVSyncEnabled(vsync) } +// GetVSyncEnabled checks whether the VSync is enabled or not func GetVSyncEnabled() bool { verifyWasInit() return singleton.GetVSyncEnabled() } +// GetCursorPos returns the exact current position of the cursor func GetCursorPos() (int, int) { verifyWasInit() return singleton.GetCursorPos() } +// CurrentFPS returns the current frames per second func CurrentFPS() float64 { verifyWasInit() return singleton.CurrentFPS() diff --git a/d2core/d2screen/d2screen.go b/d2core/d2screen/d2screen.go index 65c26fb7..e43cdacf 100644 --- a/d2core/d2screen/d2screen.go +++ b/d2core/d2screen/d2screen.go @@ -10,8 +10,10 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui" ) +// Screen is an exported interface type Screen interface{} +// ScreenLoadHandler is an exported interface type ScreenLoadHandler interface { // OnLoad performs all necessary loading to prepare a screen to be shown such as loading assets, placing and binding // of ui elements, etc. This loading is done asynchronously. The provided channel will allow implementations to @@ -19,14 +21,17 @@ type ScreenLoadHandler interface { OnLoad(loading LoadingState) } +// ScreenUnloadHandler is an exported interface type ScreenUnloadHandler interface { OnUnload() error } +// ScreenRenderHandler is an exported interface type ScreenRenderHandler interface { Render(target d2interface.Surface) error } +// ScreenAdvanceHandler is an exported interface type ScreenAdvanceHandler interface { Advance(elapsed float64) error } @@ -38,10 +43,12 @@ var singleton struct { currentScreen Screen } +// SetNextScreen is about to set a given screen as next func SetNextScreen(screen Screen) { singleton.nextScreen = screen } +// Advance updates the UI on every frame func Advance(elapsed float64) error { switch { case singleton.loadingScreen != nil: @@ -97,6 +104,7 @@ func Advance(elapsed float64) error { return nil } +// Render renders the UI by a given surface func Render(surface d2interface.Surface) error { if handler, ok := singleton.currentScreen.(ScreenRenderHandler); ok { if err := handler.Render(surface); err != nil { @@ -107,6 +115,7 @@ func Render(surface d2interface.Surface) error { return nil } +// LoadingState represents the loading state type LoadingState struct { updates chan loadingUpdate }