Skip to content

Commit 52806a7

Browse files
authored
Improve design documents (#128)
* docs: add some design contents * docs: プレイヤーの動きに関するStateについて情報整理 * chore: 起動できるようにebitengineを更新 * fix: 内部Stateの扱いを改善しつつ、上昇と下降時の不具合を修正 * chore: WebAssembly関連の文書や処理、ファイルを更新・改善 * chore: CIでの設定も更新 * chore: golangci-lintの指摘対応 * fix: 先の変更によりプレイ画面でキー入力を受け付けなくなっていたのを修正 * chore: デバッグのための設定を追加 * fix: テキスト表示の仕組み変更に伴って位置ズレが生じていたのを修正
1 parent cbb5a2c commit 52806a7

29 files changed

+1095
-341
lines changed

.github/workflows/gh-pages.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Setup Go
17-
uses: actions/setup-go@v4
17+
uses: actions/setup-go@v5
1818
with:
19-
go-version: '1.20.1'
19+
go-version: '1.24.4'
2020

2121
- name: Checkout
2222
uses: actions/checkout@v4
@@ -26,10 +26,10 @@ jobs:
2626
GOOS=js GOARCH=wasm go build -ldflags="-X 'main.Revision=$(git rev-parse --short HEAD)'" -o ./public/kuronan-dash.wasm
2727
2828
- name: Copy wasm exec
29-
run: cp $(go env GOROOT)/misc/wasm/wasm_exec.js ./public
29+
run: cp $(go env GOROOT)/lib/wasm/wasm_exec.js ./public/js
3030

3131
- name: Deploy GitHub pages
32-
uses: peaceiris/actions-gh-pages@v3
32+
uses: peaceiris/actions-gh-pages@v4
3333
with:
3434
github_token: ${{ secrets.GITHUB_TOKEN }}
3535
publish_dir: ./public

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
matrix:
1212
os: [ubuntu-latest, macos-latest, windows-latest]
13-
go: ['1.20.1']
13+
go: ['1.24.4']
1414
name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
1515
runs-on: ${{ matrix.os }}
1616
env:
@@ -20,7 +20,7 @@ jobs:
2020
shell: bash
2121
steps:
2222
- name: Setup Go
23-
uses: actions/setup-go@v4
23+
uses: actions/setup-go@v5
2424
with:
2525
go-version: ${{ matrix.go }}
2626

.github/workflows/test-and-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
matrix:
1919
os: [ubuntu-latest, macos-latest, windows-latest]
20-
go: ['1.20.1']
20+
go: ['1.24.4']
2121
name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
2222
runs-on: ${{ matrix.os }}
2323
env:
@@ -27,7 +27,7 @@ jobs:
2727
shell: bash
2828
steps:
2929
- name: Setup Go
30-
uses: actions/setup-go@v4
30+
uses: actions/setup-go@v5
3131
with:
3232
go-version: ${{ matrix.go }}
3333

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "go",
1111
"request": "launch",
1212
"mode": "auto",
13-
"program": "${fileDirname}",
13+
"program": "./",
1414
"env": {},
1515
"args": []
1616
}

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@
88
},
99
"custom": true, // Enable the `custom` dictionary
1010
"internal-terms": false // Disable the `internal-terms` dictionary
11-
}
11+
},
12+
"cSpell.words": [
13+
"gomobile",
14+
"miniweb"
15+
],
16+
"sarif-viewer.connectToGithubCodeScanning": "off"
1217
}

assets/fonts/fonts.go

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,55 @@
11
package fonts
22

33
import (
4+
"bytes"
45
"fmt"
56

6-
"github.com/golang/freetype/truetype"
7-
"golang.org/x/image/font"
7+
"github.com/hajimehoshi/ebiten/v2/text/v2"
88
)
99

1010
var (
11-
GamerFontSS font.Face
11+
// GamerFontSS is the very small size font of the strong gamer font.
12+
GamerFontSS *text.GoTextFace
13+
1214
// GamerFontS is the small size font of the strong gamer font.
13-
GamerFontS font.Face
15+
GamerFontS *text.GoTextFace
1416

1517
// GamerFontM is the middle size font of the strong gamer font.
16-
GamerFontM font.Face
18+
GamerFontM *text.GoTextFace
1719

1820
// GamerFontL is the large size font of the strong gamer font.
19-
GamerFontL font.Face
21+
GamerFontL *text.GoTextFace
2022

2123
// GamerFontLL is the extra large size font of the strong gamer font.
22-
GamerFontLL font.Face
24+
GamerFontLL *text.GoTextFace
2325
)
2426

2527
// LoadFonts loads the fonts data.
2628
func LoadFonts() error {
27-
tt, err := truetype.Parse(the_strong_gamer_ttf)
29+
fontSource, err := text.NewGoTextFaceSource(bytes.NewReader(the_strong_gamer_ttf))
2830
if err != nil {
29-
return fmt.Errorf("failed to load TheStrongGamer font,%s", err)
31+
return fmt.Errorf("failed to load font, %v", err)
3032
}
3133

32-
const dpi = 72
33-
GamerFontSS = truetype.NewFace(tt, &truetype.Options{
34-
Size: 12,
35-
DPI: dpi,
36-
Hinting: font.HintingFull,
37-
})
38-
GamerFontS = truetype.NewFace(tt, &truetype.Options{
39-
Size: 16,
40-
DPI: dpi,
41-
Hinting: font.HintingFull,
42-
})
43-
GamerFontM = truetype.NewFace(tt, &truetype.Options{
44-
Size: 24,
45-
DPI: dpi,
46-
Hinting: font.HintingFull,
47-
})
48-
GamerFontL = truetype.NewFace(tt, &truetype.Options{
49-
Size: 36,
50-
DPI: dpi,
51-
Hinting: font.HintingFull,
52-
})
53-
GamerFontLL = truetype.NewFace(tt, &truetype.Options{
54-
Size: 60,
55-
DPI: dpi,
56-
Hinting: font.HintingFull,
57-
})
34+
GamerFontSS = &text.GoTextFace{
35+
Source: fontSource,
36+
Size: 12,
37+
}
38+
GamerFontS = &text.GoTextFace{
39+
Source: fontSource,
40+
Size: 16,
41+
}
42+
GamerFontM = &text.GoTextFace{
43+
Source: fontSource,
44+
Size: 24,
45+
}
46+
GamerFontL = &text.GoTextFace{
47+
Source: fontSource,
48+
Size: 36,
49+
}
50+
GamerFontLL = &text.GoTextFace{
51+
Source: fontSource,
52+
Size: 60,
53+
}
5854
return nil
5955
}

assets/messages/ui_texts.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ package messages
22

33
// Texts for UI
44
const (
5-
TitleStart = "Spaceキー を おすか スタートボタン を\nマウス や タッチ で おしてね!"
6-
SelectStart = "さゆう の カーソルキー を おすか マウス や タッチ で キャラ を えらんだら スペースキー を おすか しゅっぱつボタン を おしてね"
7-
GameStart = "Spaceキー を おすか\nボタン を マウス や タッチ で おしてね!"
5+
SelectStart = "さゆう の カーソルキー を おすか キャラ を おして えらんだら スペースキー を おすか しゅっぱつボタン を おしてね"
6+
GameStart = "Spaceキー を おすか ボタン を おしてね!"
87
GameReady = "Ready?"
98
GameGo = "Go!"
109
GamePause = "いちじ ていし しているよ!"
1110
GameStageClear = "やったね! ステージクリアー だよ!"
12-
GameStageClear2 = "Spaceキー を おすか マウス や タッチ で ボタン を おして"
11+
GameStageClear2 = "Spaceキー を おすか ボタン を おして"
1312
GameStageClear3 = "つぎの ステージ へ すすもう。"
14-
GameOver = "ゲームオーバー! Spaceキー を おすか ボタン を おして\nタイトル へ もどろう"
13+
GameOver = "ゲームオーバー! Spaceキー を おすか ボタン を おしてね!"
1514
)

assets/se/type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ const (
88
Drop
99
Attack
1010
Blocked
11+
SpVoice
1112
)

documents/design/README.md

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ sequenceDiagram
5858

5959
* SceneManager: ゲームの各画面を`Scene`と表現しており、それらの画面遷移を制御する仕組み
6060

61-
### Titleシーンの懸案事項
61+
### `SceneManager`の懸案事項
6262

63-
`Scene``Update`メソッドで`GameState`という状態を示す情報を渡しているが、現状この内部は`SceneManager`のポインタが入っているのみ。
63+
`Scene``Update`メソッドで`GameState`という状態を示す情報を渡しているが、
64+
現状この内部は`SceneManager`のポインタが入っているのみ。
6465

65-
画面遷移するため`Scene`から`SceneManager``GoTo`メソッドを呼び出したかったのだと思うが、これでは各`Scene`が「自分の次はXX画面に遷移する」という情報を知っている必要があり、設計的に微妙。これでは、`SceneManager`に仕事してもらえていない状態。
66+
画面遷移するため`Scene`から`SceneManager``GoTo`メソッドを呼び出したかったのだと思うが、これでは各`Scene`が「自分の次はXX画面に遷移する」という情報を知っている必要があり、設計的に微妙。画面遷移の順序を自由にするため、`Scene`同士はできるだけ疎結合にしたい。
67+
68+
`Scene`から`Scene`への遷移については、`SceneManager`に任せたい。
6669

6770
例えば、`Scene`作成時にチャンネルを渡しておいて、そのチャンネルに対して通知すれば`SceneManager`が次の画面への遷移を実行してくれる・・という機構にすれば、各所が名前の通りの働きになるのではないだろうか。その方が画面遷移の制御コードが`SceneManager`に集約できるのと、ジワッと画面遷移するような処理も一箇所で実装するだけで済みそう。
6871

@@ -225,8 +228,12 @@ classDiagram
225228
- tension
226229
}
227230
231+
class VelocityController {
232+
<<interface>>
233+
}
234+
228235
Scene <|-- Stage01Scene
229-
Field <|-- PrairieLane
236+
Field <|-- PrairieField
230237
231238
Stage01Scene --> charaPlayer
232239
Stage01Scene --> Field
@@ -240,6 +247,11 @@ classDiagram
240247
241248
charaPlayer --> StateMachine
242249
charaPlayer --> StepAnimation
250+
charaPlayer --> VelocityController
251+
252+
VelocityController <|-- KuronaVc
253+
VelocityController <|-- KomaVc
254+
VelocityController <|-- ShishimaruVc
243255
```
244256

245257
### GameStateのステートマシン図
@@ -269,5 +281,95 @@ stateDiagram-v2
269281

270282
### プレイヤーStateのステートマシン図
271283

272-
WIP
284+
`chara.Player`が内部で`StateMachine`実装に移譲して管理しているプレイヤーキャラのStateについて記述する。
285+
286+
まずは現状を書き出してみる。
287+
288+
```mermaid
289+
stateDiagram-v2
290+
[*] --> Dash
291+
292+
Dash --> Walk: 1
293+
Walk --> Dash: 2
294+
295+
Dash --> Ascending: 3
296+
Dash --> SkillEffect: 4
297+
298+
SkillAscending --> Dash: 5
299+
Ascending --> Dash: 5
300+
Descending --> Dash: 6
301+
SkillDescending --> Dash: 6
302+
303+
Walk --> SkillDash: 2
304+
SkillDash --> SkillWalk: 1
305+
SkillDash --> Dash: 7
306+
307+
SkillWalk --> SkillDash: 2
308+
SkillWalk --> Dash: 7
273309
310+
SkillWalk --> SkillAscending: 3
311+
SkillDash --> SkillAscending: 3
312+
Walk --> Ascending: 3
313+
314+
SkillWalk --> SkillDescending: 8
315+
SkillDash --> SkillDescending: 8
316+
Walk --> Descending: 8
317+
```
318+
319+
#### パターン一覧
320+
321+
1. スタミナ0または障害物に衝突中
322+
2. スタミナ回復または障害物との衝突解消
323+
3. ユーザーが上昇ボタン押下
324+
4. テンションMaxでユーザーがスキルボタン押下
325+
5. 上のレーンに到着
326+
6. 下のレーンに到着
327+
7. テンション0
328+
8. ユーザーが下降ボタンを押下
329+
330+
スキル発動後はエフェクトやボイスの再生などがあるため、状態遷移とそのための操作がやや複雑になっている。現状は、`Scene`の実装が、`Player``UpdateSkillEffect``FinishSpEffect`をUpdateのたびに呼び出し、返り値がtrueになったらrun状態に戻す、という実装。(書き出してみて分かったが、上昇・下降前後での状態遷移に不具合がある。)
331+
332+
すでにサウンドの再生にはチャンネルの仕組みを使っており、こちらも同様にチャンネルによる連携にしたい。
333+
スキルエフェクトを担う仕組みからチャンネルを渡しておけば実現できそう。
334+
335+
* `StateMachine`内部では`SkillEffect`に遷移する
336+
* 次回以降の状態遷移では、スキル完了フラグをチェック
337+
* チャンネルから完了通知があれば、スキル完了フラグをtrueにする
338+
* スキル完了フラグがtrueになったのを受けて、状態を`SkillDash`に変更
339+
340+
複雑になっている要因として、内部で「前の状態」を保持・更新して次回の状態遷移に用いている点が挙げられる。
341+
もっとシンプルに、上昇や下降が終了したらまずは`Dash`または`SkillDash`に遷移するようにした方がよいのではないだろうか。
342+
343+
これから作る理想の形としては以下。
344+
345+
```mermaid
346+
stateDiagram-v2
347+
[*] --> Dash
348+
349+
Dash --> Walk: 1
350+
Walk --> Dash: 2
351+
352+
Dash --> Ascending: 3
353+
Walk --> Ascending: 3
354+
Ascending --> Dash: 5
355+
Dash --> Descending: 8
356+
Walk --> Descending: 8
357+
Descending --> Dash: 6
358+
359+
Dash --> SkillEffect: 4
360+
Walk --> SkillEffect: 4
361+
362+
SkillEffect --> SkillDash: スキルエフェクト完了
363+
SkillDash --> SkillWalk: 1
364+
SkillWalk --> SkillDash: スタミナ回復、障害物除去
365+
366+
SkillDash --> SkillAscending: 3
367+
SkillWalk --> SkillAscending: 3
368+
SkillAscending --> SkillDash: 5
369+
SkillDash --> SkillDescending: 8
370+
SkillWalk --> SkillDescending: 8
371+
SkillDescending --> SkillDash: 6
372+
373+
SkillDash --> Dash: テンション0
374+
SkillWalk --> Walk: テンション0
375+
```

documents/developers-guide.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 前提条件
44

5-
- golang Ver. 1.9 以降
5+
- golang Ver. 1.24.4 以降
66

77
## 実行方法
88

@@ -38,6 +38,8 @@ miniweb -p 9000 public
3838

3939
上記を実行した場合、ブラウザで `http://localhost:9000/` を開きましょう。
4040

41+
`golang`自体の更新によってファイルの置き場所や処理が変わる場合があるので、 [公式のWiki](https://go.dev/wiki/WebAssembly) をチェックしよう。
42+
4143
### Mobile
4244

4345
スマホにデプロイして遊んでみる場合は、[gomobile](https://github.com/golang/mobile)を使うのが便利です。[公式の手順](https://github.com/golang/go/wiki/Mobile)を見ながらインストールします。

0 commit comments

Comments
 (0)