Skip to content

Commit

Permalink
Merge branch 'refactoring'
Browse files Browse the repository at this point in the history
  • Loading branch information
shivas committed Sep 15, 2021
2 parents f1e6633 + 97e914e commit 89a01d6
Show file tree
Hide file tree
Showing 29 changed files with 978 additions and 395 deletions.
22 changes: 20 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,30 @@ tasks:
resources:
desc: Compile resource file
cmds:
- rsrc -manifest ./cmd/abyss-blackbox/main.manifest -ico ./trig_96x96.ico,./images/plus.ico,./images/switch-char.ico -o ./cmd/abyss-blackbox/rsrc.syso
- rsrc -manifest ./cmd/abyss-blackbox/main.manifest -ico ./trig_96x96.ico,./images/plus.ico,./images/switch-char.ico,./images/select-area.ico -o ./cmd/abyss-blackbox/rsrc.syso

debug:
desc: Builds artifacts for release
deps: [install-deps, resources]
cmds:
- go generate ./...
- go build -trimpath -ldflags "-s -w -X github.com/shivas/abyss-blackbox/internal/version.RecorderVersion={{.GIT_VERSION}} -X github.com/shivas/abyss-blackbox/internal/version.GoVersion={{.GO_VERSION}}" -o abyss-blackbox.exe ./cmd/abyss-blackbox
- go build -trimpath -ldflags="-s -w" ./cmd/extract/
vars:
GIT_VERSION:
sh: git describe --tags --always
GO_VERSION:
sh: go env GOVERSION

release:
desc: Builds artifacts for release
deps: [install-deps, resources]
cmds:
- go generate ./...
- go build -trimpath -ldflags="-H windowsgui -s -w" -o abyss-blackbox.exe ./cmd/abyss-blackbox
- go build -trimpath -ldflags="-H windowsgui -s -w -X github.com/shivas/abyss-blackbox/internal/version.RecorderVersion={{.GIT_VERSION}} -X github.com/shivas/abyss-blackbox/internal/version.GoVersion={{.GO_VERSION}}" -o abyss-blackbox.exe ./cmd/abyss-blackbox
- go build -trimpath -ldflags="-s -w" ./cmd/extract/
vars:
GIT_VERSION:
sh: git describe --tags --always
GO_VERSION:
sh: go env GOVERSION
115 changes: 29 additions & 86 deletions cmd/abyss-blackbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/lxn/win"
"github.com/shivas/abyss-blackbox/combatlog"
"github.com/shivas/abyss-blackbox/internal/charmanager"
"github.com/shivas/abyss-blackbox/internal/config"
"github.com/shivas/abyss-blackbox/internal/mainwindow"
"github.com/shivas/abyss-blackbox/internal/uploader"
"github.com/shivas/abyss-blackbox/screen"
Expand All @@ -26,17 +27,10 @@ var recordingChannel chan *image.Paletted
var notificationChannel chan NotificationMessage
var recorder *Recorder

const (
hotkeyRecoder = iota + 1
hotkeyWeather30
hotkeyWeather50
hotkeyWeather70
)

func main() {
var err error

currentSettings, err := readConfig()
currentSettings, err := config.Read()
if err != nil {
log.Fatal(err)
}
Expand All @@ -60,22 +54,17 @@ func main() {
comboModel = append(comboModel, &mainwindow.WindowComboBoxItem{WindowTitle: title, WindowHandle: handle})
}

logFiles, _ := clr.GetLogFiles(time.Now(), time.Duration(24)*time.Hour)
charMap := clr.MapCharactersToFiles(logFiles)

charManager := charmanager.New(func(s1, s2 string) {
notificationChannel <- NotificationMessage{Title: s1, Message: s2}
})

actions := make(map[string]walk.EventHandler)
actions["add_character"] = charManager.EventHandlerCharAdd

armw := mainwindow.NewAbyssRecorderWindow(currentSettings, drawStuff, comboModel, actions)
armw := mainwindow.NewAbyssRecorderWindow(currentSettings, drawStuff, comboModel, actions, clr)
_ = charManager.MainWindow(armw).LoadCache() // assign window to control widgets
charManager.RefreshUI()

mainwindow.BuildSettingsWidget(charMap, armw.CombatLogCharacterGroup)

charManager.OnActivateCharacter =
func(char charmanager.Character) {
if char.CharacterID > 0 {
Expand All @@ -87,7 +76,7 @@ func main() {
currentSettings.ActiveCharacter = char.CharacterID
armw.AutoUploadCheckbox.SetEnabled(char.CharacterID > 0)

_ = writeConfig(currentSettings)
_ = config.Write(currentSettings)
}

_ = charManager.SetActiveCharacter(currentSettings.ActiveCharacter)
Expand All @@ -96,21 +85,6 @@ func main() {
walk.MsgBox(armw.MainWindow, "No signed in EVE clients detected", "Please login with atleast one character and then restart this application", walk.MsgBoxIconWarning)
}

armw.ChooseLogDirButton.Clicked().Attach(func() {
fd := walk.FileDialog{}
accepted, _ := fd.ShowBrowseFolder(armw.MainWindow)
if accepted {
_ = armw.EVEGameLogsFolderLabel.SetText(fd.FilePath)
clr.SetLogFolder(fd.FilePath)
logFiles, err = clr.GetLogFiles(time.Now(), time.Duration(24)*time.Hour)
if err != nil {
return
}
charMap := clr.MapCharactersToFiles(logFiles)
mainwindow.BuildSettingsWidget(charMap, armw.CombatLogCharacterGroup)
}
})

notificationIcon := CreateNotificationIcon(armw.MainWindow)

defer func() {
Expand Down Expand Up @@ -146,21 +120,22 @@ func main() {
}

recorder.Start(charsChecked)

_ = armw.MainWindow.Menu().Actions().At(0).SetVisible(false)
armw.CombatLogCharacterGroup.SetEnabled(false)
armw.CaptureSettingsGroup.SetEnabled(false)
armw.ChooseLogDirButton.SetEnabled(false)
armw.LootRecordDiscriminatorEdit.SetEnabled(false)
armw.TestServer.SetEnabled(false)
_ = armw.Toolbar.Actions().At(3).SetEnabled(false)
_ = armw.RecordingButton.SetText("Stop recording")
} else {
filename, errr := recorder.Stop()
if errr != nil {
walk.MsgBox(armw.MainWindow, "Error writing recording", err.Error(), walk.MsgBoxIconWarning)
walk.MsgBox(armw.MainWindow, "Error writing recording", errr.Error(), walk.MsgBoxIconWarning)
}

char := charManager.ActiveCharacter()

if armw.AutoUploadCheckbox.Checked() && char != nil {
if armw.AutoUploadCheckbox.Checked() && char != nil && errr == nil {
go func(fn string, t string) {
uploadFile, uploadErr := uploader.Upload(fn, t)
if uploadErr != nil {
Expand All @@ -171,74 +146,42 @@ func main() {
}(filename, char.CharacterToken)
}

_ = armw.MainWindow.Menu().Actions().At(0).SetVisible(true)
armw.CombatLogCharacterGroup.SetEnabled(true)
armw.CaptureSettingsGroup.SetEnabled(true)
armw.ChooseLogDirButton.SetEnabled(true)
armw.TestServer.SetEnabled(true)
armw.LootRecordDiscriminatorEdit.SetEnabled(true)
_ = armw.Toolbar.Actions().At(3).SetEnabled(true)
_ = armw.RecordingButton.SetText("Start recording")
}
}

armw.RecordingButton.Clicked().Attach(recordingButtonHandler)
armw.PresetSaveButton.Clicked().Attach(func() {
p := config.Preset{X: currentSettings.X, Y: currentSettings.Y, H: currentSettings.H}
_, _ = mainwindow.RunNewPresetDialog(armw.MainWindow, p, currentSettings)
_ = config.Write(currentSettings)
armw.RefreshPresets(currentSettings)
})

armw.RefreshPresets(currentSettings)

armw.MainWindow.Hotkey().Attach(func(hkid int) {
switch hkid {
case hotkeyRecoder:
case config.HotkeyRecoder:
recordingButtonHandler()
case hotkeyWeather30:
case config.HotkeyWeather30:
recorder.GetWeatherStrengthListener(30)()
case hotkeyWeather50:
case config.HotkeyWeather50:
recorder.GetWeatherStrengthListener(50)()
case hotkeyWeather70:
case config.HotkeyWeather70:
recorder.GetWeatherStrengthListener(70)()
}
})

walk.RegisterGlobalHotKey(armw.MainWindow, hotkeyRecoder, currentSettings.RecorderShortcut)
walk.RegisterGlobalHotKey(armw.MainWindow, hotkeyWeather30, currentSettings.Weather30Shortcut)
walk.RegisterGlobalHotKey(armw.MainWindow, hotkeyWeather50, currentSettings.Weather50Shortcut)
walk.RegisterGlobalHotKey(armw.MainWindow, hotkeyWeather70, currentSettings.Weather70Shortcut)

shortcutRecorderHandler := GetShortcutRecordingHandler(
armw.RecorderShortcutEdit,
armw.RecorderShortcutRecordButton,
armw.MainWindow,
hotkeyRecoder,
currentSettings,
currentSettings.RecorderShortcut,
)

shortcutWeather30Handler := GetShortcutRecordingHandler(
armw.Weather30ShortcutEdit,
armw.Weather30ShortcutRecordButton,
armw.MainWindow,
hotkeyWeather30,
currentSettings,
currentSettings.Weather30Shortcut,
)

shortcutWeather50Handler := GetShortcutRecordingHandler(
armw.Weather50ShortcutEdit,
armw.Weather50ShortcutRecordButton,
armw.MainWindow,
hotkeyWeather50,
currentSettings,
currentSettings.Weather50Shortcut,
)

shortcutWeather70Handler := GetShortcutRecordingHandler(
armw.Weather70ShortcutEdit,
armw.Weather70ShortcutRecordButton,
armw.MainWindow,
hotkeyWeather70,
currentSettings,
currentSettings.Weather70Shortcut,
)

armw.RecorderShortcutRecordButton.Clicked().Attach(shortcutRecorderHandler)
armw.Weather30ShortcutRecordButton.Clicked().Attach(shortcutWeather30Handler)
armw.Weather50ShortcutRecordButton.Clicked().Attach(shortcutWeather50Handler)
armw.Weather70ShortcutRecordButton.Clicked().Attach(shortcutWeather70Handler)
walk.RegisterGlobalHotKey(armw.MainWindow, config.HotkeyRecoder, currentSettings.RecorderShortcut)
walk.RegisterGlobalHotKey(armw.MainWindow, config.HotkeyWeather30, currentSettings.Weather30Shortcut)
walk.RegisterGlobalHotKey(armw.MainWindow, config.HotkeyWeather50, currentSettings.Weather50Shortcut)
walk.RegisterGlobalHotKey(armw.MainWindow, config.HotkeyWeather70, currentSettings.Weather70Shortcut)

go func(cw *walk.CustomWidget) {
t := time.NewTicker(time.Second)
Expand Down Expand Up @@ -285,7 +228,7 @@ func main() {
walk.Clipboard().ContentsChanged().Attach(recorder.ClipboardListener)

defer func() {
err = writeConfig(currentSettings)
err = config.Write(currentSettings)
if err != nil {
log.Fatalf("failed to save settings after main window close: %v", err)
}
Expand Down
18 changes: 16 additions & 2 deletions cmd/abyss-blackbox/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/lxn/walk"
"github.com/shivas/abyss-blackbox/combatlog"
"github.com/shivas/abyss-blackbox/encoding"
"github.com/shivas/abyss-blackbox/internal/config"
"github.com/shivas/abyss-blackbox/internal/version"
)

const (
Expand All @@ -28,7 +30,7 @@ type Recorder struct {
state int
frameChan chan *image.Paletted
loot chan string
config *captureConfig
config *config.CaptureConfig
done chan bool
frames []*image.Paletted
delays []int
Expand All @@ -41,7 +43,7 @@ type Recorder struct {
}

// NewRecorder constructs Recorder
func NewRecorder(frameChan chan *image.Paletted, c *captureConfig, nc chan NotificationMessage, clr *combatlog.Reader) *Recorder {
func NewRecorder(frameChan chan *image.Paletted, c *config.CaptureConfig, nc chan NotificationMessage, clr *combatlog.Reader) *Recorder {
return &Recorder{
frameChan: frameChan,
loot: make(chan string, 2),
Expand Down Expand Up @@ -121,6 +123,10 @@ func (r *Recorder) StartLoop() {
if r.state == RecorderRunning { // append to buffer
r.frames = append(r.frames, frame)
r.delays = append(r.delays, 10)

if r.weatherStrength == 0 && (len(r.frames)%180 == 0) { // remind every 3 minutes skipping initial frame
r.notificationChannel <- NotificationMessage{"Reminder", "Please record weather strength!"}
}
}
r.Unlock()
default:
Expand Down Expand Up @@ -218,6 +224,14 @@ func (r *Recorder) Stop() (string, error) {
TestServer: r.config.TestServer,
WeatherStrength: int32(r.weatherStrength),
LootRecordDiscriminator: r.config.LootRecordDiscriminator,
RecorderVersion: version.RecorderVersion,
ManualAbyssTypeOverride: r.config.AbyssTypeOverride,
}

if r.config.AbyssTypeOverride {
abyssFile.AbyssShipType = encoding.AbyssRecording_AbyssShipType(r.config.AbyssShipType)
abyssFile.AbyssTier = int32(r.config.AbyssTier)
abyssFile.AbyssWheather = r.config.AbyssWeather
}

err = abyssFile.Encode(file)
Expand Down
Binary file modified cmd/abyss-blackbox/rsrc.syso
Binary file not shown.
37 changes: 0 additions & 37 deletions cmd/abyss-blackbox/shortcuts.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/shivas/abyss-blackbox

go 1.13
go 1.16

require (
github.com/disintegration/gift v1.2.1
Expand Down
Binary file added images/select-area.ico
Binary file not shown.
Loading

0 comments on commit 89a01d6

Please sign in to comment.