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

            Line data    Source code
       1              : package mapplanner
       2              : 
       3              : import (
       4              :         "slices"
       5              : 
       6              :         gc "github.com/kijimaD/ruins/internal/components"
       7              :         "github.com/kijimaD/ruins/internal/consts"
       8              :         "github.com/kijimaD/ruins/internal/maptemplate"
       9              :         "github.com/kijimaD/ruins/internal/rawschema"
      10              : )
      11              : 
      12              : // Snapshot はマップ生成の各フェーズ完了時点でのMetaPlanの状態を保存する
      13              : type Snapshot struct {
      14              :         Label        string
      15              :         Tiles        []rawschema.Tile
      16              :         Environments []gc.TileEnvironment
      17              :         Rooms        []gc.Rect
      18              :         Corridors    [][]gc.TileIdx
      19              :         NPCs         []NPCSpec
      20              :         Items        []ItemSpec
      21              :         Props        []PropsSpec
      22              :         Doors        []DoorSpec
      23              :         NextPortals  []consts.Coord[consts.Tile]
      24              :         SpawnPoints  []maptemplate.SpawnPoint
      25              : }
      26              : 
      27              : // takeSnapshot はRecordingが有効な場合にMetaPlanの現在の状態をスナップショットとして保存する
      28              : func (b *PlannerChain) takeSnapshot(label string) {
      29            1 :         if !b.Recording {
      30            1 :                 return
      31            1 :         }
      32            1 :         d := &b.PlanData
      33            1 :         b.Snapshots = append(b.Snapshots, Snapshot{
      34            1 :                 Label:        label,
      35            1 :                 Tiles:        slices.Clone(d.Tiles),
      36            1 :                 Environments: slices.Clone(d.Environments),
      37            1 :                 Rooms:        slices.Clone(d.Rooms),
      38            1 :                 Corridors:    deepCloneCorridors(d.Corridors),
      39            1 :                 NPCs:         slices.Clone(d.NPCs),
      40            1 :                 Items:        slices.Clone(d.Items),
      41            1 :                 Props:        slices.Clone(d.Props),
      42            1 :                 Doors:        slices.Clone(d.Doors),
      43            1 :                 NextPortals:  slices.Clone(d.NextPortals),
      44            1 :                 SpawnPoints:  slices.Clone(d.SpawnPoints),
      45            1 :         })
      46              : }
      47              : 
      48              : // deepCloneCorridors は二次元スライスを深くコピーする。
      49              : // slices.Cloneは外側のスライスのみコピーし内側は参照を共有するため、スナップショット間の干渉を防ぐ
      50              : func deepCloneCorridors(src [][]gc.TileIdx) [][]gc.TileIdx {
      51            1 :         dst := make([][]gc.TileIdx, len(src))
      52            1 :         for i, c := range src {
      53            1 :                 dst[i] = slices.Clone(c)
      54            1 :         }
      55            1 :         return dst
      56              : }
        

Generated by: LCOV version 2.0-1