LCOV - code coverage report
Current view: top level - world/query - name.go Coverage Total Hit
Test: coverage.lcov Lines: 100.0 % 16 16
Test Date: 2026-11-19 00:25:22 Functions: - 0 0

            Line data    Source code
       1              : package query
       2              : 
       3              : import (
       4              :         "github.com/kijimaD/ruins/internal/gamelog"
       5              :         w "github.com/kijimaD/ruins/internal/world"
       6              :         "github.com/mlange-42/ark/ecs"
       7              : )
       8              : 
       9              : // GetEntityName はエンティティの表示名を現在言語で返す。Name コンポーネントの英語原文を
      10              : // query.T で訳す。移行中の未訳 name は原文フォールバックでそのまま返る
      11              : func GetEntityName(entity ecs.Entity, world w.World) string {
      12            1 :         if !world.ECS.Alive(entity) || !world.Components.Name.Has(entity) {
      13            1 :                 return T(world, "Unknown")
      14            1 :         }
      15            1 :         name := world.Components.Name.Get(entity)
      16            1 :         if name.Custom != "" {
      17            1 :                 return name.Custom
      18            1 :         }
      19            1 :         return T(world, name.Name)
      20              : }
      21              : 
      22              : // GetEntityID はエンティティの同定キーを返す。raw 定義やレシピ参照との照合に使う。
      23              : // 表示名ではなく英語の id を返す。RawID コンポーネントを持たなければ空文字を返す
      24              : func GetEntityID(entity ecs.Entity, world w.World) string {
      25            1 :         if !world.ECS.Alive(entity) || !world.Components.RawID.Has(entity) {
      26            1 :                 return ""
      27            1 :         }
      28            1 :         return world.Components.RawID.Get(entity).ID
      29              : }
      30              : 
      31              : // NameMarkup はエンティティ種別に応じたタグで名前を包んだマークアップ文字列を返す。
      32              : // Player=<player>、NPC=<npc>、その他は裸のテキスト。gamelog.Markup へ書式の引数として渡す。
      33              : // 名前の色は実行時の種別で決まるため、書式文字列でなくここでタグ付けする
      34              : func NameMarkup(entity ecs.Entity, name string, world w.World) string {
      35            1 :         switch {
      36              :         case world.Components.Player.Has(entity):
      37            1 :                 return gamelog.Tag("player", name)
      38              :         case world.Components.SoloAI.Has(entity):
      39            1 :                 return gamelog.Tag("npc", name)
      40              :         default:
      41            1 :                 return name
      42              :         }
      43              : }
        

Generated by: LCOV version 2.0-1