LCOV - code coverage report
Current view: top level - systems - area_entry.go Coverage Total Hit
Test: coverage.lcov Lines: 90.5 % 21 19
Test Date: 2026-11-19 00:25:22 Functions: - 0 0

            Line data    Source code
       1              : package systems
       2              : 
       3              : import (
       4              :         "github.com/kijimaD/ruins/internal/consts"
       5              :         "github.com/kijimaD/ruins/internal/overworld"
       6              :         w "github.com/kijimaD/ruins/internal/world"
       7              :         "github.com/kijimaD/ruins/internal/world/lifecycle"
       8              :         "github.com/kijimaD/ruins/internal/world/query"
       9              : )
      10              : 
      11              : // AreaEntrySystem は地上でプレイヤーが別の区域に入ったら、区域の名前をスプラッシュで出す。
      12              : // 前回の観測から1ターンずつ続いているときだけ比べるので、開始・ロード・ダンジョンからの帰還の直後は出さない
      13              : type AreaEntrySystem struct {
      14              :         last     overworld.AreaKey
      15              :         lastTurn consts.Turn
      16              :         observed bool
      17              : }
      18              : 
      19              : // String はシステム名を返す
      20              : // w.Updater interfaceを実装
      21              : func (sys AreaEntrySystem) String() string {
      22            1 :         return "AreaEntrySystem"
      23            1 : }
      24              : 
      25              : // Update はプレイヤーのエリアを前回と比べ、別のエリアに入ったらスプラッシュを出す
      26              : // w.Updater interfaceを実装
      27              : func (sys *AreaEntrySystem) Update(world w.World) error {
      28            1 :         area, ok := overworld.PlayerArea(world)
      29            1 :         if !ok {
      30            1 :                 return nil
      31            1 :         }
      32            1 :         if sys.observe(area, query.GetGameTime(world).TotalTurns) {
      33            0 :                 lifecycle.SpawnSplashText(world, query.T(world, area.Name))
      34            0 :         }
      35            1 :         return nil
      36              : }
      37              : 
      38              : // observe はターン turn のエリアを記憶し、直前の区域と別の区域に入ったかを返す。区域でない場所に
      39              : // 出ても直前の区域は忘れないので、区域の境目を行き来しても続けて出さない。system は world より長く
      40              : // 生きてロードをまたぐので、前回の観測から続いていなければ、前のプレイや別の場所の区域と比べない
      41              : func (sys *AreaEntrySystem) observe(area overworld.Area, turn consts.Turn) bool {
      42            1 :         continuous := sys.observed && turn == sys.lastTurn+1
      43            1 :         if !continuous {
      44            1 :                 sys.last = overworld.AreaKey{}
      45            1 :         }
      46            1 :         district := area.Key != overworld.AreaKey{}
      47            1 :         entered := continuous && district && area.Key != sys.last
      48            1 :         if district {
      49            1 :                 sys.last = area.Key
      50            1 :         }
      51            1 :         sys.lastTurn, sys.observed = turn, true
      52            1 :         return entered
      53              : }
        

Generated by: LCOV version 2.0-1