All files / utils clothingMaterials.ts

96.55% Statements 28/29
86.66% Branches 26/30
100% Functions 4/4
95.65% Lines 22/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228                                              1x                                                                                                                                                                                                                     4x                                     6x   6x                                     7x   7x                                           11x 2x 1x         9x 1x       8x 2x 1x       6x 2x 1x       4x 3x 2x 1x       1x    
/**
 * Clothing Material Utilities
 *
 * **Korean**: 의류 재료 유틸리티 (Clothing Material Utilities)
 *
 * Provides material presets and utility functions for clothing materials
 * following Korean cyberpunk aesthetic principles.
 *
 * @module utils/clothingMaterials
 * @category Utilities
 * @korean 의류재료유틸리티
 */
 
import type { MaterialPreset } from "@/types/clothing";
 
/**
 * Material presets for different clothing types
 *
 * These presets define realistic material properties based on
 * real-world fabric and material characteristics.
 *
 * @korean 재료프리셋
 */
export const CLOTHING_MATERIAL_PRESETS: Record<string, MaterialPreset> = {
  // Natural fabrics
  cotton: {
    metalness: 0.0,
    roughness: 0.9,
    emissiveIntensity: 0.0,
  },
  silk: {
    metalness: 0.1,
    roughness: 0.3,
    emissiveIntensity: 0.0,
  },
  wool: {
    metalness: 0.0,
    roughness: 0.95,
    emissiveIntensity: 0.0,
  },
  
  // Synthetic fabrics
  nylon: {
    metalness: 0.2,
    roughness: 0.4,
    emissiveIntensity: 0.0,
  },
  polyester: {
    metalness: 0.15,
    roughness: 0.5,
    emissiveIntensity: 0.0,
  },
  spandex: {
    metalness: 0.3,
    roughness: 0.3,
    emissiveIntensity: 0.0,
  },
  
  // Leather types
  leather: {
    metalness: 0.3,
    roughness: 0.7,
    emissiveIntensity: 0.0,
  },
  leatherPolished: {
    metalness: 0.5,
    roughness: 0.4,
    emissiveIntensity: 0.0,
  },
  leatherDistressed: {
    metalness: 0.2,
    roughness: 0.85,
    emissiveIntensity: 0.0,
  },
  
  // Tactical/Military
  tacticalFabric: {
    metalness: 0.2,
    roughness: 0.7,
    emissiveIntensity: 0.0,
  },
  kevlar: {
    metalness: 0.4,
    roughness: 0.6,
    emissiveIntensity: 0.0,
  },
  
  // Cyberpunk materials
  cyberSynthetic: {
    metalness: 0.6,
    roughness: 0.3,
    emissiveIntensity: 0.2,
  },
  neoprene: {
    metalness: 0.5,
    roughness: 0.4,
    emissiveIntensity: 0.1,
  },
  holographic: {
    metalness: 0.9,
    roughness: 0.1,
    emissiveIntensity: 0.5,
  },
  
  // Metal accents
  steel: {
    metalness: 0.9,
    roughness: 0.3,
    emissiveIntensity: 0.0,
  },
  chrome: {
    metalness: 1.0,
    roughness: 0.1,
    emissiveIntensity: 0.0,
  },
  brushedMetal: {
    metalness: 0.8,
    roughness: 0.5,
    emissiveIntensity: 0.0,
  },
};
 
/**
 * Get material preset by name
 *
 * @param presetName - Name of the material preset
 * @returns Material preset configuration
 * @korean 재료프리셋가져오기
 */
export function getMaterialPreset(presetName: string): MaterialPreset {
  return CLOTHING_MATERIAL_PRESETS[presetName] ?? CLOTHING_MATERIAL_PRESETS.cotton;
}
 
/**
 * Blend two material presets
 *
 * Useful for creating hybrid materials (e.g., leather with metallic accents)
 *
 * @param preset1 - First material preset
 * @param preset2 - Second material preset
 * @param blend - Blend factor (0 = all preset1, 1 = all preset2)
 * @returns Blended material preset
 * @korean 재료프리셋혼합
 */
export function blendMaterialPresets(
  preset1: MaterialPreset,
  preset2: MaterialPreset,
  blend: number
): MaterialPreset {
  const t = Math.max(0, Math.min(1, blend)); // Clamp to [0, 1]
  
  return {
    metalness: preset1.metalness * (1 - t) + preset2.metalness * t,
    roughness: preset1.roughness * (1 - t) + preset2.roughness * t,
    emissiveIntensity: (preset1.emissiveIntensity ?? 0) * (1 - t) + 
                       (preset2.emissiveIntensity ?? 0) * t,
  };
}
 
/**
 * Adjust material preset for wear and tear
 *
 * Simulates material degradation over time or from combat damage
 *
 * @param preset - Base material preset
 * @param wearLevel - Wear amount (0 = new, 1 = heavily worn)
 * @returns Adjusted material preset
 * @korean 재료마모조정
 */
export function applyWear(preset: MaterialPreset, wearLevel: number): MaterialPreset {
  const wear = Math.max(0, Math.min(1, wearLevel));
  
  return {
    metalness: preset.metalness * (1 - wear * 0.3), // Metal loses shine
    roughness: Math.min(1, preset.roughness + wear * 0.3), // Surface gets rougher
    emissiveIntensity: (preset.emissiveIntensity ?? 0) * (1 - wear * 0.5), // Glow fades
  };
}
 
/**
 * Get material preset for archetype-specific style
 *
 * Returns appropriate material based on archetype philosophy
 *
 * @param archetype - Player archetype
 * @param clothingType - Type of clothing item
 * @returns Recommended material preset
 * @korean 원형재료프리셋
 */
export function getArchetypeMaterialStyle(
  archetype: string,
  clothingType: string
): MaterialPreset {
  // Musa (Traditional Warrior) - Natural fabrics
  if (archetype === "MUSA") {
    if (clothingType === "torso") return CLOTHING_MATERIAL_PRESETS.cotton;
    Eif (clothingType === "belt") return CLOTHING_MATERIAL_PRESETS.silk;
    return CLOTHING_MATERIAL_PRESETS.tacticalFabric;
  }
  
  // Amsalja (Shadow Assassin) - High-tech synthetics
  if (archetype === "AMSALJA") {
    return CLOTHING_MATERIAL_PRESETS.cyberSynthetic;
  }
  
  // Hacker (Cyber Warrior) - Casual tech wear
  if (archetype === "HACKER") {
    if (clothingType === "gloves") return CLOTHING_MATERIAL_PRESETS.holographic;
    return CLOTHING_MATERIAL_PRESETS.neoprene;
  }
  
  // Jeongbo (Intelligence Operative) - Professional tactical
  if (archetype === "JEONGBO_YOWON") {
    if (clothingType === "vest") return CLOTHING_MATERIAL_PRESETS.kevlar;
    return CLOTHING_MATERIAL_PRESETS.tacticalFabric;
  }
  
  // Jojik (Street Fighter) - Heavy leather
  if (archetype === "JOJIK_POKRYEOKBAE") {
    if (clothingType === "torso") return CLOTHING_MATERIAL_PRESETS.leatherDistressed;
    if (clothingType === "belt") return CLOTHING_MATERIAL_PRESETS.steel;
    return CLOTHING_MATERIAL_PRESETS.leather;
  }
  
  // Default
  return CLOTHING_MATERIAL_PRESETS.cotton;
}