Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ permissions: read-all

on: [push, pull_request]

env:
GO_VERSION: "1.21.0"

jobs:
lint-backend:
name: Lint Backend
Expand All @@ -13,7 +16,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"

- uses: golangci/golangci-lint-action@v6
with:
Expand All @@ -23,20 +26,15 @@ jobs:
name: Lint Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version-file: 'frontend/.nvmrc'
- name: Setup Bun
uses: oven-sh/setup-bun@v1

- name: Enable corepack
run: corepack enable
- name: Check out code
uses: actions/checkout@v2

- name: Lint
working-directory: ./frontend
run: |
pnpm install
pnpm run lint
run: bun install && bun run lint

test:
name: Test
Expand All @@ -46,7 +44,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"

- name: Test
run: go test -v ./...
Expand All @@ -61,7 +59,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"

- name: Build wasm
run: go build -ldflags="-s -w" -v -o build.wasm ./wasm
Expand All @@ -75,17 +73,14 @@ jobs:
needs:
- lint-frontend
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version-file: 'frontend/.nvmrc'
- name: Setup Bun
uses: oven-sh/setup-bun@v1

- name: Enable corepack
run: corepack enable
- name: Check out
uses: actions/checkout@v2

- name: Build frontend
working-directory: frontend
run: |
pnpm install
pnpm run build
bun install
bun run build
22 changes: 10 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ on:
tags:
- v*

env:
GO_VERSION: "1.21.0"

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- uses: actions/setup-node@v4
with:
node-version-file: 'frontend/.nvmrc'
- name: Check out
uses: actions/checkout@v2

- name: Enable corepack
run: corepack enable
- name: Setup Bun
uses: oven-sh/setup-bun@v1

- name: Build wasm
run: go build -ldflags="-s -w" -v -o frontend/static/calculator.wasm ./wasm
Expand All @@ -32,12 +30,12 @@ jobs:
- name: Build frontend
working-directory: frontend
run: |
pnpm install
pnpm run build
bun install
bun run build
ls -lah build

- uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./frontend/build
exclude_assets: ''
exclude_assets: ""
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PHONY: wasm
wasm:
GOOS=js GOARCH=wasm go build -ldflags="-s -w" -v -o frontend/static/calculator.wasm ./wasm
dev: wasm
cd frontend; bun install; bun run dev
57 changes: 42 additions & 15 deletions data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package data
import (
"bytes"
"compress/gzip"
"embed"
"encoding/json"
"fmt"
"io"
"regexp"
"strings"

_ "embed"
)
Expand Down Expand Up @@ -53,17 +57,8 @@ var (
SkillTreeData SkillTree
)

//go:embed stat_descriptions.json.gz
var statTranslationsGz []byte
var StatTranslationsJSON []byte

//go:embed passive_skill_stat_descriptions.json.gz
var passiveSkillStatTranslationsGz []byte
var PassiveSkillStatTranslationsJSON []byte

//go:embed passive_skill_aura_stat_descriptions.json.gz
var passiveSkillAuraStatTranslationsGz []byte
var PassiveSkillAuraStatTranslationsJSON []byte
//go:embed trs/*
var trs embed.FS

//go:embed possible_stats.json.gz
var possibleStatsGz []byte
Expand Down Expand Up @@ -124,13 +119,45 @@ func init() {
panic(err)
}

StatTranslationsJSON = unzipTo(statTranslationsGz)
PassiveSkillStatTranslationsJSON = unzipTo(passiveSkillStatTranslationsGz)
PassiveSkillAuraStatTranslationsJSON = unzipTo(passiveSkillAuraStatTranslationsGz)

PossibleStatsJSON = unzipTo(possibleStatsGz)
}

func getLocale(locale string) string {
matches := regexp.MustCompile(`(?mi)en|zh`).FindStringSubmatch(locale)
if len(matches) > 0 {
return strings.ToLower(matches[0])
}

return "en"
}

func StatTranslationsJSON(locale string) string {
var gz, err = trs.ReadFile(fmt.Sprintf("trs/%s/stat_descriptions.json.gz", getLocale(locale)))
if err != nil {
panic(err)
}

return string(unzipTo(gz))
}

func PassiveSkillStatTranslationsJSON(locale string) string {
var gz, err = trs.ReadFile(fmt.Sprintf("trs/%s/passive_skill_stat_descriptions.json.gz", getLocale(locale)))
if err != nil {
panic(err)
}

return string(unzipTo(gz))
}

func PassiveSkillAuraStatTranslationsJSON(locale string) string {
var gz, err = trs.ReadFile(fmt.Sprintf("trs/%s/passive_skill_aura_stat_descriptions.json.gz", getLocale(locale)))
if err != nil {
panic(err)
}

return string(unzipTo(gz))
}

func unzipJSONTo[T any](data []byte) T {
out := new(T)
if err := json.Unmarshal(unzipTo(data), &out); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions data/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package data

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_getLocale(t *testing.T) {
assert.Equal(t, getLocale("zh-CN"), "zh")
assert.Equal(t, getLocale("zh-TW"), "zh")
assert.Equal(t, getLocale("en-US"), "en")
assert.Equal(t, getLocale("other"), "en")
}
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file added data/trs/zh/stat_descriptions.json.gz
Binary file not shown.
1 change: 0 additions & 1 deletion frontend/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ node_modules
!.env.example

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
src/wasm_exec.js
Binary file added frontend/bun.lockb
Binary file not shown.
7 changes: 4 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
"@typescript-eslint/parser": "^6.5.0",
"autoprefixer": "^10.4.15",
"comlink": "^4.4.1",
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-svelte3": "^4.0.0",
"eslint": "^8.48.0",
"postcss": "^8.4.29",
"prettier": "^3.0.3",
"prettier-plugin-svelte": "^3.0.3",
"prettier": "^3.0.3",
"sass": "^1.66.1",
"svelte": "^4.2.0",
"svelte-canvas": "^0.9.3",
"svelte-check": "^3.5.1",
"svelte-i18n": "^4.0.0",
"svelte-preprocess": "^5.0.4",
"svelte-select": "^5.7.0",
"svelte-tiny-virtual-list": "^2.0.5",
"svelte": "^4.2.0",
"tailwindcss": "^3.3.3",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
Expand Down
Loading
Loading