Skip to content

Commit

Permalink
move things from pkg/common to pkg/window
Browse files Browse the repository at this point in the history
some interfaces should not be in common

what is common at all?
  • Loading branch information
gucio321 committed Nov 27, 2024
1 parent 8ee50eb commit 104a633
Show file tree
Hide file tree
Showing 25 changed files with 166 additions and 171 deletions.
9 changes: 5 additions & 4 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/gucio321/HellSpawner/pkg/common/hsfiletypes"
"github.com/gucio321/HellSpawner/pkg/common/hsproject"
"github.com/gucio321/HellSpawner/pkg/config"
"github.com/gucio321/HellSpawner/pkg/window/editor"
"github.com/gucio321/HellSpawner/pkg/window/popup/aboutdialog"
"github.com/gucio321/HellSpawner/pkg/window/popup/preferences"
"github.com/gucio321/HellSpawner/pkg/window/popup/projectproperties"
Expand Down Expand Up @@ -62,7 +63,7 @@ type editorConstructor func(
data *[]byte,
x, y float32,
project *hsproject.Project,
) (common.EditorWindow, error)
) (editor.Editor, error)

// App represents an app
type App struct {
Expand All @@ -81,11 +82,11 @@ type App struct {
mpqExplorer *mpqexplorer.MPQExplorer
console *console.Console

editors []common.EditorWindow
editors []editor.Editor
editorConstructors map[hsfiletypes.FileType]editorConstructor

editorManagerMutex sync.RWMutex
focusedEditor common.EditorWindow
focusedEditor editor.Editor

fontFixed *g.FontInfo
fontFixedSmall *g.FontInfo
Expand All @@ -101,7 +102,7 @@ type App struct {
func Create() (*App, error) {
result := &App{
Flags: &Flags{},
editors: make([]common.EditorWindow, 0),
editors: make([]editor.Editor, 0),
editorConstructors: make(map[hsfiletypes.FileType]editorConstructor),
TextureLoader: common.NewTextureLoader(),
abyssWrapper: abysswrapper.Create(),
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/app_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/gucio321/HellSpawner/pkg/common"
"github.com/gucio321/HellSpawner/pkg/common/state"
"github.com/gucio321/HellSpawner/pkg/window/toolwindow"
)

// State creates a new app state
Expand Down Expand Up @@ -33,7 +34,7 @@ func (a *App) State() state.AppState {
// RestoreAppState restores an app state
func (a *App) RestoreAppState(appState state.AppState) {
for _, toolState := range appState.ToolWindows {
var tool common.ToolWindow
var tool toolwindow.ToolWindow

switch toolState.Type {
case state.ToolWindowTypeConsole:
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/menubar.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/gravestench/osinfo"
"github.com/pkg/browser"

"github.com/gucio321/HellSpawner/pkg/common"
"github.com/gucio321/HellSpawner/pkg/common/hsproject"
"github.com/gucio321/HellSpawner/pkg/window"
)

const (
Expand Down Expand Up @@ -387,7 +387,7 @@ func (a *App) renderEditors() {
}

func (a *App) renderWindows() {
windows := []common.Renderable{
windows := []window.Renderable{
a.projectExplorer,
a.mpqExplorer,
a.console,
Expand Down
31 changes: 0 additions & 31 deletions pkg/common/editorwindow.go
Original file line number Diff line number Diff line change
@@ -1,32 +1 @@
package common

import (
"github.com/AllenDang/giu"

"github.com/gucio321/HellSpawner/pkg/common/state"
)

// EditorWindow represents editor window
type EditorWindow interface {
Renderable
MainMenuUpdater

// HasFocus returns true if editor is focused
HasFocus() (hasFocus bool)
// GetWindowTitle controls what the window title for this editor appears as
GetWindowTitle() string
// Show sets Visible to true
Show()
// SetVisible can be used to set Visible to false if the editor should be closed
SetVisible(bool)
// GetID returns a unique identifier for this editor window
GetID() string
// BringToFront brings this editor to the front of the application, giving it focus
BringToFront()
// State returns the current state of this editor, in a JSON-serializable struct
State() state.EditorState
// Save writes any changes made in the editor to the file that is open in the editor.
Save()

Size(float32, float32) *giu.WindowWidget
}
21 changes: 0 additions & 21 deletions pkg/common/toolwindow.go

This file was deleted.

12 changes: 6 additions & 6 deletions pkg/window/editor/animdata/animation_data_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
)

// static check, to ensure, if D2 editor implemented editoWindow
var _ common.EditorWindow = &AnimationDataEditor{}
var _ editor.Editor = &AnimationDataEditor{}

// AnimationDataEditor represents a cof editor
type AnimationDataEditor struct {
*editor.Editor
*editor.EditorBase
d2 *d2animdata.AnimationData
state []byte
textureLoader common.TextureLoader
Expand All @@ -34,14 +34,14 @@ func Create(_ *config.Config,
pathEntry *common.PathEntry,
state []byte,
data *[]byte, x, y float32, project *hsproject.Project,
) (common.EditorWindow, error) {
) (editor.Editor, error) {
d2, err := d2animdata.Load(*data)
if err != nil {
return nil, fmt.Errorf("error loading animation data file: %w", err)
}

result := &AnimationDataEditor{
Editor: editor.New(pathEntry, x, y, project),
EditorBase: editor.New(pathEntry, x, y, project),
d2: d2,
state: state,
textureLoader: tl,
Expand Down Expand Up @@ -88,7 +88,7 @@ func (e *AnimationDataEditor) GenerateSaveData() []byte {

// Save saves an editor
func (e *AnimationDataEditor) Save() {
e.Editor.Save(e)
e.EditorBase.Save(e)
}

// Cleanup hides an editor
Expand All @@ -101,5 +101,5 @@ func (e *AnimationDataEditor) Cleanup() {
}
}

e.Editor.Cleanup()
e.EditorBase.Cleanup()
}
12 changes: 6 additions & 6 deletions pkg/window/editor/cof/cof_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
)

// static check, to ensure, if cof editor implemented editoWindow
var _ common.EditorWindow = &Editor{}
var _ editor.Editor = &Editor{}

// Editor represents a cof editor
type Editor struct {
*editor.Editor
*editor.EditorBase
cof *d2cof.COF
textureLoader common.TextureLoader
state []byte
Expand All @@ -35,14 +35,14 @@ func Create(_ *config.Config,
pathEntry *common.PathEntry,
state []byte,
data *[]byte, x, y float32, project *hsproject.Project,
) (common.EditorWindow, error) {
) (editor.Editor, error) {
cof, err := d2cof.Unmarshal(*data)
if err != nil {
return nil, fmt.Errorf("error loading cof file: %w", err)
}

result := &Editor{
Editor: editor.New(pathEntry, x, y, project),
EditorBase: editor.New(pathEntry, x, y, project),
cof: cof,
textureLoader: tl,
state: state,
Expand Down Expand Up @@ -89,7 +89,7 @@ func (e *Editor) GenerateSaveData() []byte {

// Save saves an editor
func (e *Editor) Save() {
e.Editor.Save(e)
e.EditorBase.Save(e)
}

// Cleanup hides an editor
Expand All @@ -102,5 +102,5 @@ func (e *Editor) Cleanup() {
}
}

e.Editor.Cleanup()
e.EditorBase.Cleanup()
}
12 changes: 6 additions & 6 deletions pkg/window/editor/dc6/dc6_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
)

// static check, to ensure, if dc6 editor implemented editoWindow
var _ common.EditorWindow = &Editor{}
var _ editor.Editor = &Editor{}

// Editor represents a dc6 editor
type Editor struct {
*editor.Editor
*editor.EditorBase
dc6 *d2dc6.DC6
textureLoader common.TextureLoader
config *config.Config
Expand All @@ -39,14 +39,14 @@ func Create(cfg *config.Config,
pathEntry *common.PathEntry,
state []byte,
data *[]byte, x, y float32, project *hsproject.Project,
) (common.EditorWindow, error) {
) (editor.Editor, error) {
dc6, err := d2dc6.Load(*data)
if err != nil {
return nil, fmt.Errorf("error loading DC6 animation: %w", err)
}

result := &Editor{
Editor: editor.New(pathEntry, x, y, project),
EditorBase: editor.New(pathEntry, x, y, project),
dc6: dc6,
textureLoader: textureLoader,
selectPalette: false,
Expand Down Expand Up @@ -119,7 +119,7 @@ func (e *Editor) GenerateSaveData() []byte {

// Save saves editor's data
func (e *Editor) Save() {
e.Editor.Save(e)
e.EditorBase.Save(e)
}

// Cleanup hides editor
Expand All @@ -131,5 +131,5 @@ func (e *Editor) Cleanup() {
}
}

e.Editor.Cleanup()
e.EditorBase.Cleanup()
}
12 changes: 6 additions & 6 deletions pkg/window/editor/dcc/dcc_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
)

// static check, to ensure, if dc6 editor implemented editoWindow
var _ common.EditorWindow = &Editor{}
var _ editor.Editor = &Editor{}

// Editor represents a new dcc editor
type Editor struct {
*editor.Editor
*editor.EditorBase
dcc *d2dcc.DCC
config *config.Config
selectPalette bool
Expand All @@ -40,14 +40,14 @@ func Create(cfg *config.Config,
pathEntry *common.PathEntry,
state []byte,
data *[]byte, x, y float32, project *hsproject.Project,
) (common.EditorWindow, error) {
) (editor.Editor, error) {
dcc, err := d2dcc.Load(*data)
if err != nil {
return nil, fmt.Errorf("error loading dcc animation: %w", err)
}

result := &Editor{
Editor: editor.New(pathEntry, x, y, project),
EditorBase: editor.New(pathEntry, x, y, project),
dcc: dcc,
config: cfg,
selectPalette: false,
Expand Down Expand Up @@ -119,7 +119,7 @@ func (e *Editor) GenerateSaveData() []byte {

// Save saves editor
func (e *Editor) Save() {
e.Editor.Save(e)
e.EditorBase.Save(e)
}

// Cleanup hides editor
Expand All @@ -131,5 +131,5 @@ func (e *Editor) Cleanup() {
}
}

e.Editor.Cleanup()
e.EditorBase.Cleanup()
}
14 changes: 7 additions & 7 deletions pkg/window/editor/ds1/ds1_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
"github.com/gucio321/HellSpawner/pkg/window/editor"
)

// static check if Editor implemented common.EditorWindow
var _ common.EditorWindow = &Editor{}
// static check if Editor implemented editor.Editor
var _ editor.Editor = &Editor{}

// Editor represents ds1 editor
type Editor struct {
*editor.Editor
*editor.EditorBase
ds1 *d2ds1.DS1
deleteButtonTexture *g.Texture
textureLoader common.TextureLoader
Expand All @@ -36,14 +36,14 @@ func Create(_ *config.Config,
pathEntry *common.PathEntry,
state []byte,
data *[]byte, x, y float32, project *hsproject.Project,
) (common.EditorWindow, error) {
) (editor.Editor, error) {
ds1, err := d2ds1.Unmarshal(*data)
if err != nil {
return nil, fmt.Errorf("error loading DS1 file: %w", err)
}

result := &Editor{
Editor: editor.New(pathEntry, x, y, project),
EditorBase: editor.New(pathEntry, x, y, project),
ds1: ds1,
textureLoader: tl,
state: state,
Expand Down Expand Up @@ -95,7 +95,7 @@ func (e *Editor) GenerateSaveData() []byte {

// Save saves editors data
func (e *Editor) Save() {
e.Editor.Save(e)
e.EditorBase.Save(e)
}

// Cleanup hides editor
Expand All @@ -107,5 +107,5 @@ func (e *Editor) Cleanup() {
}
}

e.Editor.Cleanup()
e.EditorBase.Cleanup()
}
Loading

0 comments on commit 104a633

Please sign in to comment.