buildMonsterModel(.model 골격 복제·외형/EnemyId 베이크·AI-free) + buildMonsterInstance(맵 엔티티) + modelEntryId. fs 접근 없는 순수 함수. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xhLoQbJvQYL65kBtDNDTy
61 lines
3.2 KiB
JavaScript
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, '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/);
|
|
});
|