Skip to content

Commit

Permalink
Merge pull request #5 from shivas/fittings
Browse files Browse the repository at this point in the history
Fittings
  • Loading branch information
shivas authored Aug 23, 2022
2 parents 89a01d6 + beea0eb commit c9fce12
Show file tree
Hide file tree
Showing 28 changed files with 1,685 additions and 259 deletions.
16 changes: 16 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ tasks:
sh: git describe --tags --always
GO_VERSION:
sh: go env GOVERSION

win7:
desc: Builds artifacts for release
deps: [install-deps, resources]
env:
GOARCH: 386
cmds:
- go generate ./...
- 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-blackbox32.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

67 changes: 34 additions & 33 deletions cmd/abyss-blackbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ import (
"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/fittings"
"github.com/shivas/abyss-blackbox/internal/mainwindow"
"github.com/shivas/abyss-blackbox/internal/uploader"
"github.com/shivas/abyss-blackbox/screen"
)

const EVEClientWindowRe = "^EVE -.*$"

var previewChannel chan image.Image
var recordingChannel chan *image.Paletted
var notificationChannel chan NotificationMessage
var recorder *Recorder
var (
previewChannel chan image.Image
recordingChannel chan *image.Paletted
notificationChannel chan NotificationMessage
recorder *Recorder
)

func main() {
var err error
Expand Down Expand Up @@ -61,23 +64,22 @@ func main() {
actions := make(map[string]walk.EventHandler)
actions["add_character"] = charManager.EventHandlerCharAdd

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

charManager.OnActivateCharacter =
func(char charmanager.Character) {
if char.CharacterID > 0 {
_ = armw.MainWindow.SetTitle("Abyssal.Space Blackbox Recorder - " + char.CharacterName)
}
charManager.OnActivateCharacter = func(char charmanager.Character) {
if char.CharacterID > 0 {
_ = armw.MainWindow.SetTitle("Abyssal.Space Blackbox Recorder - " + char.CharacterName)
}

notificationChannel <- NotificationMessage{Title: "Active character set to:", Message: char.CharacterName}
notificationChannel <- NotificationMessage{Title: "Active character set to:", Message: char.CharacterName}

currentSettings.ActiveCharacter = char.CharacterID
armw.AutoUploadCheckbox.SetEnabled(char.CharacterID > 0)
currentSettings.ActiveCharacter = char.CharacterID
armw.AutoUploadCheckbox.SetEnabled(char.CharacterID > 0)

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

_ = charManager.SetActiveCharacter(currentSettings.ActiveCharacter)

Expand All @@ -100,35 +102,32 @@ func main() {

recordingButtonHandler := func() {
if recorder.Status() == RecorderStopped {
charsChecked := []string{}
if runnerModel, ok := armw.RunnerTableView.Model().(*mainwindow.RunnerModel); ok {
checkedChars := runnerModel.GetCheckedCharacters()

checkboxes := armw.CombatLogCharacterGroup.Children()
for i := 0; i < checkboxes.Len(); i++ {
cb, ok := checkboxes.At(i).(*walk.CheckBox)
if !ok {
continue
if len(checkedChars) == 0 {
walk.MsgBox(armw.MainWindow, "No characters selected", "Please choose atleast one character to capture combat log", walk.MsgBoxIconWarning)
return
}

if cb.Checked() {
charsChecked = append(charsChecked, cb.Text())
if len(checkedChars) > 3 {
walk.MsgBox(armw.MainWindow, "Too much characters selected", "Please choose up-to 3 characters to capture combat log", walk.MsgBoxIconWarning)
return
}
}

if len(charsChecked) == 0 {
walk.MsgBox(armw.MainWindow, "No characters selected", "Please choose atleast one character to capture combat log", walk.MsgBoxIconWarning)
return
recorder.Start(checkedChars)
}

recorder.Start(charsChecked)

_ = armw.MainWindow.Menu().Actions().At(0).SetVisible(false)
armw.CombatLogCharacterGroup.SetEnabled(false)
armw.RunnerCharacterGroup.SetEnabled(false)
armw.RunnerTableView.SetEnabled(false)
armw.ManageFittingsButton.SetEnabled(false)
armw.CaptureSettingsGroup.SetEnabled(false)
armw.TestServer.SetEnabled(false)
_ = armw.Toolbar.Actions().At(3).SetEnabled(false)
_ = armw.RecordingButton.SetText("Stop recording")
} else {
filename, errr := recorder.Stop()
filename, errr := recorder.Stop(armw.FittingManager)
if errr != nil {
walk.MsgBox(armw.MainWindow, "Error writing recording", errr.Error(), walk.MsgBoxIconWarning)
}
Expand All @@ -147,7 +146,9 @@ func main() {
}

_ = armw.MainWindow.Menu().Actions().At(0).SetVisible(true)
armw.CombatLogCharacterGroup.SetEnabled(true)
armw.RunnerCharacterGroup.SetEnabled(true)
armw.RunnerTableView.SetEnabled(true)
armw.ManageFittingsButton.SetEnabled(true)
armw.CaptureSettingsGroup.SetEnabled(true)
armw.TestServer.SetEnabled(true)
_ = armw.Toolbar.Actions().At(3).SetEnabled(true)
Expand Down Expand Up @@ -311,7 +312,7 @@ func paletted(img *image.NRGBA, cutoff uint32) *image.Paletted {
palette := []color.Color{color.White, color.Black}
buffimg := image.NewPaletted(img.Rect, palette)

var threshold = cutoff << 8
threshold := cutoff << 8

for y := 0; y < img.Rect.Dy(); y++ {
for x := 0; x < img.Rect.Dx(); x++ {
Expand Down
51 changes: 35 additions & 16 deletions cmd/abyss-blackbox/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"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/fittings"
"github.com/shivas/abyss-blackbox/internal/version"
)

Expand All @@ -26,7 +27,7 @@ const (
)

type Recorder struct {
sync.Mutex
mutex sync.Mutex
state int
frameChan chan *image.Paletted
loot chan string
Expand Down Expand Up @@ -82,8 +83,8 @@ func (r *Recorder) GetWeatherStrengthListener(strength int) func() {
return
}

r.Lock()
defer r.Unlock()
r.mutex.Lock()
defer r.mutex.Unlock()
r.weatherStrength = strength
r.notificationChannel <- NotificationMessage{Title: "Abyssal.Space recorder", Message: fmt.Sprintf("Weather strength set to: %d%%", strength)}
}
Expand All @@ -98,7 +99,7 @@ func (r *Recorder) StartLoop() {
return // exit loop

case lootSnapshot := <-r.loot:
r.Lock()
r.mutex.Lock()

switch r.state {
case RecorderAwaitingInitialLoot:
Expand All @@ -116,10 +117,10 @@ func (r *Recorder) StartLoop() {
log.Printf("dropped loot record, %v", lootSnapshot)
}

r.Unlock()
r.mutex.Unlock()

case frame := <-r.frameChan:
r.Lock()
r.mutex.Lock()
if r.state == RecorderRunning { // append to buffer
r.frames = append(r.frames, frame)
r.delays = append(r.delays, 10)
Expand All @@ -128,7 +129,7 @@ func (r *Recorder) StartLoop() {
r.notificationChannel <- NotificationMessage{"Reminder", "Please record weather strength!"}
}
}
r.Unlock()
r.mutex.Unlock()
default:
time.Sleep(1 * time.Millisecond)
}
Expand All @@ -138,8 +139,8 @@ func (r *Recorder) StartLoop() {

// Start recording of abyssal run
func (r *Recorder) Start(characters []string) {
r.Lock()
defer r.Unlock()
r.mutex.Lock()
defer r.mutex.Unlock()

// make sure recordings folder exists
_, err := os.Stat(r.config.Recordings)
Expand Down Expand Up @@ -183,15 +184,33 @@ func (r *Recorder) Start(characters []string) {
}

// Stop stops recording and writes .abyss file if frames captured
func (r *Recorder) Stop() (string, error) {
r.Lock()
defer r.Unlock()
func (r *Recorder) Stop(fm *fittings.FittingsManager) (string, error) {
r.mutex.Lock()
defer r.mutex.Unlock()

if len(r.frames) == 0 {
r.state = RecorderStopped
return r.recordingName, fmt.Errorf("there was no frames captured, skipping recording of abyss run")
}

runFittings := make(map[string]*encoding.Fit, len(r.charactersTracking))

for char := range r.charactersTracking {
fit := fm.GetFittingForPilot(char)
if fit != nil {
runFittings[char] = &encoding.Fit{
Source: fit.Source,
ForeignID: fit.ForeignID,
FittingName: fit.FittingName,
EFT: fit.EFT,
FFH: fit.FFH,
Price: fit.Price,
ShipName: fit.ShipName,
ShipTypeID: fit.ShipTypeID,
}
}
}

file, _ := os.Create(r.recordingName)
defer file.Close()

Expand Down Expand Up @@ -226,6 +245,7 @@ func (r *Recorder) Stop() (string, error) {
LootRecordDiscriminator: r.config.LootRecordDiscriminator,
RecorderVersion: version.RecorderVersion,
ManualAbyssTypeOverride: r.config.AbyssTypeOverride,
Fittings: runFittings,
}

if r.config.AbyssTypeOverride {
Expand All @@ -234,8 +254,7 @@ func (r *Recorder) Stop() (string, error) {
abyssFile.AbyssWheather = r.config.AbyssWeather
}

err = abyssFile.Encode(file)
return r.recordingName, err
return r.recordingName, abyssFile.Encode(file)
}

// StopLoop stops main recording loop
Expand All @@ -245,8 +264,8 @@ func (r *Recorder) StopLoop() {

// Status returns status of recorder
func (r *Recorder) Status() int {
r.Lock()
defer r.Unlock()
r.mutex.Lock()
defer r.mutex.Unlock()

return r.state
}
8 changes: 8 additions & 0 deletions cmd/extract/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func main() {
fmt.Println("Recording is from Live server (tranquility)")
}

for pilot, fit := range abyssFile.Fittings {
fmt.Printf("Pilot with fit: %q\n", pilot)
fmt.Println("----------")
fmt.Printf("fit:\n%s\n", fit.EFT)
fmt.Println("----------")
fmt.Printf("Name: %q, FFH: %s, ShipName: %q ShipTypeID: %d, Price: %2f\n", fit.FittingName, fit.FFH, fit.ShipName, fit.ShipTypeID, fit.Price)
}

fmt.Printf("Recorded weather strength: %d%% and loot record discriminator: %q\n", abyssFile.WeatherStrength, abyssFile.LootRecordDiscriminator)

for _, logRecord := range abyssFile.CombatLog {
Expand Down
47 changes: 47 additions & 0 deletions cmd/windowsversion/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"
"log"

"golang.org/x/sys/windows/registry"
)

func main() {

k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
if err != nil {
log.Fatal(err)
}
defer k.Close()

cv, _, err := k.GetStringValue("CurrentVersion")
if err != nil {
log.Fatal(err)
}
fmt.Printf("CurrentVersion: %s\n", cv)

pn, _, err := k.GetStringValue("ProductName")
if err != nil {
log.Fatal(err)
}
fmt.Printf("ProductName: %s\n", pn)

maj, _, err := k.GetIntegerValue("CurrentMajorVersionNumber")
if err != nil {
log.Fatal(err)
}
fmt.Printf("CurrentMajorVersionNumber: %d\n", maj)

min, _, err := k.GetIntegerValue("CurrentMinorVersionNumber")
if err != nil {
log.Fatal(err)
}
fmt.Printf("CurrentMinorVersionNumber: %d\n", min)

cb, _, err := k.GetStringValue("CurrentBuild")
if err != nil {
log.Fatal(err)
}
fmt.Printf("CurrentVersion: %s\n", cb)
}
Loading

0 comments on commit c9fce12

Please sign in to comment.