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

            Line data    Source code
       1              : package query
       2              : 
       3              : import (
       4              :         gc "github.com/kijimaD/ruins/internal/components"
       5              :         "github.com/kijimaD/ruins/internal/consts"
       6              :         "github.com/kijimaD/ruins/internal/rawschema"
       7              :         w "github.com/kijimaD/ruins/internal/world"
       8              :         "github.com/mlange-42/ark/ecs"
       9              : )
      10              : 
      11              : // ItemDisassemblyYield は item を分解したときに戻る素材の id と個数を返す。分解できなければ ok は false
      12              : func ItemDisassemblyYield(world w.World, item ecs.Entity) (id string, count int, ok bool) {
      13            1 :         if !world.ECS.Alive(item) || !world.Components.RawID.Has(item) || !world.Components.Material.Has(item) || !world.Components.Weight.Has(item) {
      14            0 :                 return "", 0, false
      15            0 :         }
      16            1 :         return disassemblyYield(world,
      17            1 :                 world.Components.RawID.Get(item).ID,
      18            1 :                 world.Components.Material.Get(item).Kind,
      19            1 :                 world.Components.Weight.Get(item).Milligram,
      20            1 :                 world.Components.Deployable.Has(item),
      21            1 :         )
      22              : }
      23              : 
      24              : // SpecDisassemblyYield は生成前のアイテムの spec を分解したときに戻る素材の id と個数を返す。分解できなければ ok は false
      25              : func SpecDisassemblyYield(world w.World, spec gc.EntitySpec) (id string, count int, ok bool) {
      26            1 :         if spec.RawID == nil || spec.Material == nil || spec.Weight == nil {
      27            0 :                 return "", 0, false
      28            0 :         }
      29            1 :         return disassemblyYield(world, spec.RawID.ID, spec.Material.Kind, spec.Weight.Milligram, spec.Deployable != nil)
      30              : }
      31              : 
      32              : // disassemblyYield は装着する設備を除き、材質と重さから戻る素材を導く
      33              : func disassemblyYield(world w.World, id string, material rawschema.Material, weight consts.Milligram, deployable bool) (string, int, bool) {
      34            1 :         if deployable {
      35            1 :                 return "", 0, false
      36            1 :         }
      37            1 :         return world.Resources.MaterialDefs.DisassemblyOf(id, material, weight)
      38              : }
        

Generated by: LCOV version 2.0-1