Files
maplecontest/tools/monster/monster-model.test.mjs
gahusb 3b678e35d1 fix(monster): 맵 인스턴스 origin.entry_id를 modelId와 일치시켜 MissingModel 해소
메이커가 엔티티의 원본 모델을 origin.entry_id로 해석하는데, entry_id를
enemyId("junior_bugi")로 넣어 model://monster-junior_bugi(실제 EntryKey)와
불일치 → [LEA-3028] MissingModel로 전 몬스터 미표시. entry_id를
modelEntryId(=modelId="monster-<id>")로 수정. 메이커 인게임 검증: 전투에서
전 종 정상 렌더(stump=1110101도 나무토막 확인).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011xhLoQbJvQYL65kBtDNDTy
2026-07-03 01:18:06 +09:00

61 lines
3.2 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { buildMonsterModel, buildMonsterInstance, modelEntryId } from './lib/monster-model.mjs';
const skeleton = JSON.parse(readFileSync('Global/ChaseMonster.model', 'utf8'));
const enemy = {
name: '슬라임', maxHp: 45, intents: [],
appearance: { sheet: { stand: 'AAAA', hit: 'BBBB', die: 'CCCC' }, box: { x: 0.63, y: 0.58 }, off: { x: 0.045, y: 0.29 } },
};
test('modelEntryId: monster- 접두', () => {
assert.equal(modelEntryId('slime'), 'monster-slime');
});
test('buildMonsterModel: EntryKey/Id/Name 파생', () => {
const m = buildMonsterModel('slime', enemy, skeleton);
assert.equal(m.EntryKey, 'model://monster-slime');
assert.equal(m.ContentProto.Json.Id, 'monster-slime');
assert.equal(m.ContentProto.Json.Name, 'slime');
});
test('buildMonsterModel: 외형·EnemyId 베이크 + AI-free + 컴포넌트 확장', () => {
const j = buildMonsterModel('slime', enemy, skeleton).ContentProto.Json;
assert.ok(j.Components.includes('script.CombatMonster'));
assert.ok(j.Components.includes('MOD.Core.DamageSkinSettingComponent'));
assert.ok(!j.Components.some((c) => c.includes('AIWander') || c.includes('AIChase')));
const val = (t, n) => j.Values.find((v) => v.TargetType === t && v.Name === n)?.Value;
assert.equal(val('MOD.Core.SpriteRendererComponent', 'SpriteRUID'), 'AAAA');
assert.deepEqual(val('MOD.Core.StateAnimationComponent', 'ActionSheet'), enemy.appearance.sheet);
assert.equal(val('script.CombatMonster', 'EnemyId'), 'slime');
assert.equal(val('MOD.Core.MovementComponent', 'InputSpeed'), 0);
assert.equal(val('MOD.Core.HitComponent', 'BoxSize').x, 0.63);
});
test('buildMonsterModel: 원본 skeleton 비변형(순수 함수)', () => {
const before = JSON.stringify(skeleton);
buildMonsterModel('slime', enemy, skeleton);
assert.equal(JSON.stringify(skeleton), before);
});
test('buildMonsterInstance: 모델 연결·컴포넌트 값', () => {
const e = buildMonsterInstance({ enemyId: 'slime', enemy, name: 'slime', guid: '00000bb9-0000-4000-8000-000000000bb9', mapTag: '03', x: 3.4, group: 'elite' });
assert.equal(e.jsonString.modelId, 'monster-slime');
assert.equal(e.jsonString.origin.entry_id, 'monster-slime');
assert.equal(e.jsonString.origin.root_entity_id, e.id);
assert.equal(e.path, '/maps/map03/slime');
const comp = (t) => e.jsonString['@components'].find((c) => c['@type'] === t);
assert.equal(comp('script.CombatMonster').EnemyId, 'slime');
assert.equal(comp('script.CombatMonster').Group, 'elite');
assert.equal(comp('MOD.Core.TransformComponent').Position.x, 3.4);
assert.equal(comp('MOD.Core.SpriteRendererComponent').SpriteRUID, 'AAAA');
assert.deepEqual(comp('MOD.Core.StateAnimationComponent').ActionSheet, enemy.appearance.sheet);
assert.equal(comp('MOD.Core.MovementComponent').Enable, false);
assert.equal(e.componentNames, e.jsonString['@components'].map((c) => c['@type']).join(','));
});
test('buildMonsterInstance: appearance 없는 적은 에러(fail-fast)', () => {
assert.throws(() => buildMonsterInstance({ enemyId: 'x', enemy: { name: 'x' }, name: 'x', guid: 'g', mapTag: '01', x: 1, group: 'combat' }), /appearance/);
});