LCOV - code coverage report
Current view: top level - widgets/entityspec - uses.go Coverage Total Hit
Test: coverage.lcov Lines: 94.4 % 36 34
Test Date: 2026-11-19 00:25:22 Functions: - 0 0

            Line data    Source code
       1              : package entityspec
       2              : 
       3              : import (
       4              :         "github.com/kijimaD/ruins/internal/raw"
       5              :         w "github.com/kijimaD/ruins/internal/world"
       6              :         "github.com/kijimaD/ruins/internal/world/query"
       7              :         "github.com/mlange-42/ark/ecs"
       8              : )
       9              : 
      10              : // UseHints は実体の性質・使い道を「用途」見出しでまとめた行の並びを返す。
      11              : // 各判定は item_action_state の動詞タブの Accept と同条件にし、使える動詞と出る性質を一致させる。
      12              : // 死んだ実体や性質を持たない実体には nil を返す。
      13              : func UseHints(world w.World, e ecs.Entity) []SpecRow {
      14            1 :         if !world.ECS.Alive(e) {
      15            0 :                 return nil
      16            0 :         }
      17            1 :         c := world.Components
      18            1 :         consumable := c.Consumable.Has(e)
      19            1 :         nutrition := c.ProvidesNutrition.Has(e)
      20            1 :         healing := c.ProvidesHealing.Has(e)
      21            1 : 
      22            1 :         var uses []string
      23            1 :         if consumable && (nutrition || healing) { // acceptConsumeFood
      24            1 :                 uses = append(uses, query.T(world, "Edible"))
      25            1 :         }
      26            1 :         if c.Book.Has(e) {
      27            1 :                 uses = append(uses, query.T(world, "Readable"))
      28            1 :         }
      29            1 :         if consumable && !nutrition && !healing { // acceptUseTool
      30            1 :                 uses = append(uses, query.T(world, "Usable"))
      31            1 :         }
      32              :         // 武器も防具も装備スロットに付けるので同じ「装備できる」にまとめる
      33            1 :         if c.Wearable.Has(e) || c.Melee.Has(e) || c.Fire.Has(e) {
      34            1 :                 uses = append(uses, query.T(world, "Wearable"))
      35            1 :         }
      36              :         // 装着アイテムはキューブの展開空間の設備画面から装着できる
      37            1 :         if c.Deployable.Has(e) {
      38            1 :                 uses = append(uses, query.T(world, "Deployable"))
      39            1 :         }
      40              :         // 道具は専用コンポーネントを持たず raw 定義の有無で判定する
      41            1 :         if _, ok := raw.FindTool(world.Resources.RawMaster, query.GetEntityID(e, world)); ok {
      42            1 :                 uses = append(uses, query.T(world, "Breaks objects efficiently"))
      43            1 :         }
      44            1 :         if len(uses) == 0 {
      45            1 :                 return nil
      46            1 :         }
      47              : 
      48            1 :         rows := make([]SpecRow, 0, len(uses)+1)
      49            1 :         rows = append(rows, SpecRow{Label: query.T(world, "Uses"), Header: true})
      50            1 :         for _, u := range uses {
      51            1 :                 rows = append(rows, SpecRow{Label: u, Indent: 1})
      52            1 :         }
      53            1 :         return rows
      54              : }
        

Generated by: LCOV version 2.0-1