Line data Source code
1 : package resources
2 :
3 : import (
4 : "github.com/kijimaD/ruins/internal/components"
5 : "github.com/kijimaD/ruins/internal/config"
6 : "github.com/kijimaD/ruins/internal/i18n"
7 : "github.com/kijimaD/ruins/internal/inputmapper"
8 : "github.com/kijimaD/ruins/internal/rawschema"
9 : "github.com/mlange-42/ark/ecs"
10 : )
11 :
12 : // Resources はゲーム固有のリソース管理を担当する
13 : // engine/resources.ResourceProviderインターフェースを実装する
14 : type Resources struct {
15 : ScreenDimensions ScreenDimensions
16 : SpriteSheets map[string]components.SpriteSheet
17 : Sprites *SpriteStore // スプライトから解決した画像のキャッシュ。等倍と縮小の両方を持つ
18 : UIResources UIResources
19 : RawMaster rawschema.Raws
20 : ConditionDefs components.ConditionDefs
21 : SkillDefs components.SkillDefs
22 : WeatherDefs components.WeatherDefs
23 : TileEnvDefs components.TileEnvDefs
24 : NeedDefs components.NeedDefs
25 : MaterialDefs components.MaterialDefs
26 : CalendarDefs components.CalendarDefs
27 : I18N i18n.Catalog // 国際化のマスタ。全言語の訳を持つ読み取り専用データ。現在言語は UserSettings が持ち query.T が引く
28 : Config *config.Config // 実行設定。起動時に注入する
29 : SingletonEntity ecs.Entity // シングルトンエンティティIDキャッシュ
30 :
31 : // InputSource は Action の入力供給源。nil なら本番どおりキーボードから変換する。
32 : // 再生ドライバだけが Action 列を返す供給源を差し、キー入力を経由せず本番フローを駆動する。
33 : // world 単位で持つことでグローバル可変状態を作らず、押し込んだ先の state にも同じ源が効く
34 : InputSource inputmapper.Source
35 : }
36 :
37 : // ScreenDimensions contains current screen dimensions
38 : type ScreenDimensions struct {
39 : Width int
40 : Height int
41 : }
42 :
43 : // GetScreenDimensions はスクリーン寸法を取得する
44 : func (r *Resources) GetScreenDimensions() (width, height int) {
45 1 : return r.ScreenDimensions.Width, r.ScreenDimensions.Height
46 1 : }
47 :
48 : // SetScreenDimensions はスクリーン寸法を設定する
49 : func (r *Resources) SetScreenDimensions(width, height int) {
50 1 : r.ScreenDimensions.Width = width
51 1 : r.ScreenDimensions.Height = height
52 1 : }
53 :
54 : // SetSpriteSheets はスプライトシートを設定し、解決キャッシュにも同じシートを渡す。
55 : // 元画像と解決キャッシュがずれないよう、設定はこの1経路にまとめる。
56 : func (r *Resources) SetSpriteSheets(sheets map[string]components.SpriteSheet) {
57 1 : r.SpriteSheets = sheets
58 1 : r.Sprites.SetSheets(sheets)
59 1 : }
60 :
61 : // InitializeResources は engine/resources.ResourceInitializer インターフェースを実装する
62 : func (r *Resources) InitializeResources() error {
63 1 : *r = *InitGameResources()
64 1 : return nil
65 1 : }
66 :
67 : // InitGameResources はゲームリソースを初期化する
68 : func InitGameResources() *Resources {
69 1 : return &Resources{
70 1 : SpriteSheets: map[string]components.SpriteSheet{},
71 1 : UIResources: UIResources{},
72 1 : Sprites: NewSpriteStore(),
73 1 : // 全言語の訳を持つ不変マスタを常に持たせる。どのワールドでも res.I18N が非 nil になる。
74 1 : I18N: i18n.NewCatalog(),
75 1 : }
76 : }
|