Merge pull request 'feat(monster): 적 종별 모델(프리팹) + 스테이지 로스터 배치' (#107) from feature/monster-models into main
This commit was merged in pull request #107.
This commit is contained in:
@@ -1,108 +1,55 @@
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { buildMonsterInstance } from '../monster/lib/monster-model.mjs';
|
||||
|
||||
// map02~11에 노드 타입별 몬스터 그룹(combat3/elite2/boss1)을 맵별 테마로 자동 구성.
|
||||
// 기존 몬스터 엔티티를 전부 제거하고 첫 몬스터를 템플릿으로 6마리 재생성(결정론).
|
||||
const MAP_NUMBERS = [1, 2, 3, 4, 5];
|
||||
const COMBAT_POOL = ['orange_mushroom', 'green_mushroom', 'pig', 'blue_mushroom', 'red_snail', 'stump'];
|
||||
const ELITE_POOL = ['mushmom', 'modified_snail'];
|
||||
const BOSS_POOL = ['king_slime', 'slime_boss'];
|
||||
// map01: StS2식 일반 5종 + 엘리트 1 + 보스 1(보스 노드용, 화면 우측 포메이션).
|
||||
// 그 외 맵: 일반 3 + 엘리트 2 + 보스 1. 전투 시 BuildMonsters가 노드 타입별로 1~3마리 랜덤 추첨.
|
||||
const LAYOUT_MAP01 = [
|
||||
{ group: 'combat', x: 2.6 }, { group: 'combat', x: 3.6 }, { group: 'combat', x: 4.6 },
|
||||
{ group: 'combat', x: 5.6 }, { group: 'combat', x: 6.6 },
|
||||
{ group: 'elite', x: 4.6 },
|
||||
{ group: 'boss', x: 4.6 },
|
||||
];
|
||||
const LAYOUT_DEFAULT = [
|
||||
{ group: 'combat', x: 2.3 }, { group: 'combat', x: 3.8 }, { group: 'combat', x: 5.2 },
|
||||
{ group: 'elite', x: 3.0 }, { group: 'elite', x: 5.0 },
|
||||
{ group: 'boss', x: 4.0 },
|
||||
];
|
||||
const layoutFor = (nn) => (nn === 1 ? LAYOUT_MAP01 : LAYOUT_DEFAULT);
|
||||
const MONSTER_VARIANTS = [
|
||||
{ sprite: '96e955c1bf27415e84f96deea200a8f1', stand: '96e955c1bf27415e84f96deea200a8f1', hit: 'aec9504d5dc24aceb5646b79d30abad4', die: '65a2bfb039614f2e9e4ccc354340153d' },
|
||||
{ sprite: 'f86992ba9c41487c8480fcb893fcbda6', stand: 'f86992ba9c41487c8480fcb893fcbda6', hit: 'd305b942b1704c8084548108ff3b7a6b', die: '5a563e5fd98c4132b61057dc6bb8aaf2' },
|
||||
{ sprite: 'a2204a21d88942b281d2cac6053ffbaa', stand: 'a2204a21d88942b281d2cac6053ffbaa', hit: 'afc08936b8a64b26bc3dd8c03ead1f26', die: 'fc1c6d9ba9bc413ab53b6dbfae3ac45b' },
|
||||
{ sprite: 'd8f014043ce8418f96700c2b6c9ebf6c', stand: 'd8f014043ce8418f96700c2b6c9ebf6c', hit: 'c3cf643b618346c7bfa6574187b396f9', die: 'a88d9b3d60f941e4890dc89a6ccaa8ee' },
|
||||
{ sprite: '17b55730c26f4fd6b8fcfa288da388de', stand: '17b55730c26f4fd6b8fcfa288da388de', hit: 'eac48e84a9fc4580a4018de5cf52ddb3', die: '51c2f4b59a2c413db26035aa57002fc8' },
|
||||
{ sprite: '48c10437ae8344a9b2a1d3f36185728f', stand: '48c10437ae8344a9b2a1d3f36185728f', hit: '9044063647854f5e9128efcf80e909be', die: 'f414577d18c94cc387c275df4abdbc3b' },
|
||||
{ sprite: '4ca39dbfa1c6492283ba8bd352d12b0a', stand: '4ca39dbfa1c6492283ba8bd352d12b0a', hit: '7ac78511036e4ebe988b97c35fc275d1', die: '740f3f2b2e7a4b71bec5eac84e8539f9' },
|
||||
{ sprite: 'ed3908e24d694bb786023fc1ed073489', stand: 'ed3908e24d694bb786023fc1ed073489', hit: '4763c9bebc9245998c9c499b6316aa9f', die: 'b168793b92a844a3a3a6f4ce647a14d2' },
|
||||
{ sprite: '3109357701ae41a4bcc7543f52f1f4c3', stand: '3109357701ae41a4bcc7543f52f1f4c3', hit: 'ce0269079e884545b5bb6ea075e2a67f', die: 'a5e65650e00e47878cac1be7a5b999a0' },
|
||||
];
|
||||
// map01~05에 data/encounters.json 로스터대로 종별 모델 인스턴스를 배치(결정론).
|
||||
// 기존 몬스터 엔티티 전부 제거 후 로스터 전체를 그룹별 x 균등 분포로 재생성.
|
||||
// 준비도 가드: 로스터에 appearance 미보유 적이 있는 맵은 재생성을 건너뛴다(기존 맵 보존).
|
||||
const enemies = JSON.parse(readFileSync('data/enemies.json', 'utf8')).enemies;
|
||||
const encounters = JSON.parse(readFileSync('data/encounters.json', 'utf8'));
|
||||
const X_RANGE = { combat: [2.3, 6.6], elite: [3.0, 5.6], boss: [4.6, 4.6] };
|
||||
|
||||
function rng(seed) { let s = seed >>> 0; return () => { s = (s * 1664525 + 1013904223) >>> 0; return s / 4294967296; }; }
|
||||
const isMonster = (e) => typeof e.componentNames === 'string' && e.componentNames.includes('script.Monster');
|
||||
function encGuid(nn, idx) {
|
||||
const n = (nn * 1000 + 500 + idx) >>> 0;
|
||||
const h8 = n.toString(16).padStart(8, '0');
|
||||
const h12 = n.toString(16).padStart(12, '0');
|
||||
return `${h8}-0000-4000-8000-${h12}`;
|
||||
return `${n.toString(16).padStart(8, '0')}-0000-4000-8000-${n.toString(16).padStart(12, '0')}`;
|
||||
}
|
||||
const isMonster = (e) => typeof e.componentNames === 'string' && e.componentNames.includes('script.Monster');
|
||||
const compOf = (e, t) => e.jsonString['@components'].find((c) => c['@type'] === t);
|
||||
|
||||
function pick(rand, pool) { return pool[Math.floor(rand() * pool.length)]; }
|
||||
function pickN(rand, pool, n) {
|
||||
const a = pool.slice();
|
||||
const out = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (a.length === 0) a.push(...pool);
|
||||
out.push(a.splice(Math.floor(rand() * a.length), 1)[0]);
|
||||
}
|
||||
return out;
|
||||
function slotX(group, i, count) {
|
||||
const [lo, hi] = X_RANGE[group];
|
||||
return count <= 1 ? (lo + hi) / 2 : lo + (i * (hi - lo)) / (count - 1);
|
||||
}
|
||||
|
||||
function patchMap(nn) {
|
||||
const tag = String(nn).padStart(2, '0');
|
||||
const file = `map/map${tag}.map`;
|
||||
const roster = encounters[`map${tag}`];
|
||||
if (!roster) throw new Error(`[gen-map-encounters] encounters.json에 map${tag} 없음`);
|
||||
const rosterIds = ['combat', 'elite', 'boss'].flatMap((g) => roster[g] || []);
|
||||
for (const id of rosterIds) {
|
||||
if (!enemies[id]) throw new Error(`[gen-map-encounters] map${tag} 로스터에 없는 적: ${id}`);
|
||||
}
|
||||
// 준비도 가드: appearance 미보유 적이 하나라도 있으면 이 맵은 보존(스킵)
|
||||
const missing = rosterIds.filter((id) => !enemies[id].appearance);
|
||||
if (missing.length) return `map${tag}(SKIP: appearance 없음 ${[...new Set(missing)].join('/')})`;
|
||||
|
||||
const map = JSON.parse(readFileSync(file, 'utf8'));
|
||||
const ents = map.ContentProto.Entities;
|
||||
const monsters = ents.filter(isMonster);
|
||||
if (monsters.length === 0) throw new Error(`[gen-map-encounters] ${file} 몬스터 템플릿 없음`);
|
||||
const template = monsters[0];
|
||||
map.ContentProto.Entities = ents.filter((e) => !isMonster(e));
|
||||
const rand = rng(nn * 7919 + 17);
|
||||
const layout = layoutFor(nn);
|
||||
const nCombat = layout.filter((s) => s.group === 'combat').length;
|
||||
const nElite = layout.filter((s) => s.group === 'elite').length;
|
||||
const combatIds = pickN(rand, COMBAT_POOL, nCombat);
|
||||
const eliteIds = pickN(rand, ELITE_POOL, nElite);
|
||||
const bossId = pick(rand, BOSS_POOL);
|
||||
const variants = pickN(rand, MONSTER_VARIANTS, layout.length);
|
||||
let ci = 0, ei = 0;
|
||||
layout.forEach((slot, idx) => {
|
||||
const m = JSON.parse(JSON.stringify(template));
|
||||
const enemyId = slot.group === 'combat' ? combatIds[ci++] : slot.group === 'elite' ? eliteIds[ei++] : bossId;
|
||||
const name = `${slot.group}_${idx + 1}`;
|
||||
m.id = encGuid(nn, idx);
|
||||
m.path = `/maps/map${tag}/${name}`;
|
||||
m.jsonString.path = m.path;
|
||||
m.jsonString.name = name;
|
||||
const o = m.jsonString.origin;
|
||||
if (o) { if (o.root_entity_id) o.root_entity_id = m.id; if (o.sub_entity_id) o.sub_entity_id = m.id; }
|
||||
const tr = compOf(m, 'MOD.Core.TransformComponent');
|
||||
if (tr && tr.Position) tr.Position.x = slot.x;
|
||||
const v = variants[idx];
|
||||
const sp = compOf(m, 'MOD.Core.SpriteRendererComponent');
|
||||
if (sp) sp.SpriteRUID = v.stand;
|
||||
const sa = compOf(m, 'MOD.Core.StateAnimationComponent');
|
||||
if (sa) sa.ActionSheet = { stand: v.stand, hit: v.hit, die: v.die };
|
||||
let cm = compOf(m, 'script.CombatMonster');
|
||||
if (!cm) {
|
||||
cm = { '@type': 'script.CombatMonster', Enable: true };
|
||||
m.jsonString['@components'].push(cm);
|
||||
const names = (m.componentNames || '').split(',').filter((s) => s && s !== 'script.CombatMonster');
|
||||
names.push('script.CombatMonster');
|
||||
m.componentNames = names.join(',');
|
||||
}
|
||||
cm.EnemyId = enemyId;
|
||||
cm.Group = slot.group;
|
||||
map.ContentProto.Entities.push(m);
|
||||
});
|
||||
map.ContentProto.Entities = map.ContentProto.Entities.filter((e) => !isMonster(e));
|
||||
const nameCount = {};
|
||||
let idx = 0;
|
||||
for (const group of ['combat', 'elite', 'boss']) {
|
||||
const ids = roster[group] || [];
|
||||
ids.forEach((enemyId, i) => {
|
||||
nameCount[enemyId] = (nameCount[enemyId] || 0) + 1;
|
||||
const name = nameCount[enemyId] > 1 ? `${enemyId}_${nameCount[enemyId]}` : enemyId;
|
||||
map.ContentProto.Entities.push(buildMonsterInstance({
|
||||
enemyId, enemy: enemies[enemyId], name, guid: encGuid(nn, idx), mapTag: tag, x: slotX(group, i, ids.length), group,
|
||||
}));
|
||||
idx += 1;
|
||||
});
|
||||
}
|
||||
writeFileSync(file, JSON.stringify(map, null, 2), 'utf8');
|
||||
return `map${tag}(${combatIds.join('/')}|${eliteIds.join('/')}|${bossId})`;
|
||||
const counts = ['combat', 'elite', 'boss'].map((g) => `${g}${(roster[g] || []).length}`).join('/');
|
||||
return `map${tag}(${counts})`;
|
||||
}
|
||||
|
||||
const made = MAP_NUMBERS.map(patchMap);
|
||||
const made = [1, 2, 3, 4, 5].map(patchMap);
|
||||
console.log('Encounters:', made.join(', '));
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { writeFileSync } from 'node:fs';
|
||||
|
||||
// 맵 몬스터에 적 타입(EnemyId)을 부여하고, BeginPlay 시 /common 컨트롤러에 자기등록하는 마커.
|
||||
// 카드 전투 시 컨트롤러가 등록 목록으로 인카운터를 구성한다.
|
||||
const MAP_NUMBERS = Array.from({ length: 5 }, (_, i) => i + 1); // map01~05
|
||||
const NAME_TO_ENEMY = { '주황버섯': 'orange_mushroom', '파란버섯': 'blue_mushroom' };
|
||||
const DEFAULT_ENEMY = 'orange_mushroom';
|
||||
// 카드 전투용 자기등록 마커 codeblock(CombatMonster) 생성.
|
||||
// BeginPlay 시 /common 컨트롤러에 자기등록해 인카운터를 구성한다.
|
||||
// 맵 부착 값(EnemyId/Group)은 gen-map-encounters.mjs가 인스턴스에 직접 기록한다.
|
||||
|
||||
function prop(Type, Name, DefaultValue = 'nil') {
|
||||
return { Type, DefaultValue, SyncDirection: 0, Attributes: [], Name };
|
||||
@@ -49,39 +47,5 @@ eventId = _TimerService:SetTimerRepeat(reg, 0.1)`),
|
||||
writeFileSync('RootDesk/MyDesk/CombatMonster.codeblock', JSON.stringify(cb, null, 2) + '\n', 'utf8');
|
||||
}
|
||||
|
||||
const isMonster = (e) => typeof e.componentNames === 'string' && e.componentNames.includes('script.Monster');
|
||||
|
||||
function patchMap(nn) {
|
||||
const tag = String(nn).padStart(2, '0');
|
||||
const file = `map/map${tag}.map`;
|
||||
const map = JSON.parse(readFileSync(file, 'utf8'));
|
||||
let added = 0, kept = 0;
|
||||
for (const e of map.ContentProto.Entities.filter(isMonster)) {
|
||||
const comps = e.jsonString && e.jsonString['@components'];
|
||||
if (!Array.isArray(comps)) {
|
||||
console.warn(`[gen-combat-monster] entity "${(e.jsonString && e.jsonString.name) || e.path}" has no @components — skipped`);
|
||||
continue;
|
||||
}
|
||||
const name = (e.jsonString && e.jsonString.name) || '';
|
||||
const existing = comps.find((c) => c['@type'] === 'script.CombatMonster');
|
||||
if (existing) {
|
||||
// 사용자가 메이커에서 설정한 값 보존 — 누락된 키만 기본값 채움
|
||||
if (existing.Enable === undefined) existing.Enable = true;
|
||||
if (existing.EnemyId == null) existing.EnemyId = NAME_TO_ENEMY[name] || DEFAULT_ENEMY;
|
||||
if (existing.Group == null) existing.Group = 'combat';
|
||||
kept++;
|
||||
} else {
|
||||
comps.push({ '@type': 'script.CombatMonster', Enable: true, EnemyId: NAME_TO_ENEMY[name] || DEFAULT_ENEMY, Group: 'combat' });
|
||||
added++;
|
||||
}
|
||||
const names = (e.componentNames || '').split(',').filter((s) => s && s !== 'script.CombatMonster');
|
||||
names.push('script.CombatMonster');
|
||||
e.componentNames = names.join(',');
|
||||
}
|
||||
writeFileSync(file, JSON.stringify(map, null, 2), 'utf8');
|
||||
return `map${tag}(+${added}/keep${kept})`;
|
||||
}
|
||||
|
||||
writeCodeblock();
|
||||
const patched = MAP_NUMBERS.map(patchMap);
|
||||
console.log('CombatMonster codeblock written; patched maps:', patched.join(', '));
|
||||
console.log('CombatMonster codeblock written.');
|
||||
|
||||
29
tools/monster/gen-monster-models.mjs
Normal file
29
tools/monster/gen-monster-models.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
|
||||
import { buildMonsterModel, modelEntryId } from './lib/monster-model.mjs';
|
||||
|
||||
// 적 18종 각각의 전용 모델(.model) emit. 단일 소스: data/enemies.json(appearance) + ChaseMonster.model(골격).
|
||||
const OUT_DIR = 'RootDesk/MyDesk/Models/Monsters';
|
||||
const enemies = JSON.parse(readFileSync('data/enemies.json', 'utf8')).enemies;
|
||||
const skeleton = JSON.parse(readFileSync('Global/ChaseMonster.model', 'utf8'));
|
||||
|
||||
// EntryKey 충돌 가드 (LEA-3015 예방): 기존 .model들의 EntryKey 수집 (경로별)
|
||||
const existing = []; // { key, path }
|
||||
for (const dir of ['Global', OUT_DIR]) {
|
||||
for (const f of readdirSync(dir).filter((n) => n.endsWith('.model'))) {
|
||||
const path = `${dir}/${f}`;
|
||||
existing.push({ key: JSON.parse(readFileSync(path, 'utf8')).EntryKey, path });
|
||||
}
|
||||
}
|
||||
|
||||
const written = [];
|
||||
const skipped = [];
|
||||
for (const [enemyId, enemy] of Object.entries(enemies)) {
|
||||
if (!enemy.appearance) { skipped.push(enemyId); continue; }
|
||||
const file = buildMonsterModel(enemyId, enemy, skeleton);
|
||||
const outPath = `${OUT_DIR}/${enemyId}.model`;
|
||||
const clash = existing.find((e) => e.key === file.EntryKey && e.path !== outPath);
|
||||
if (clash) throw new Error(`[gen-monster-models] EntryKey 충돌: ${file.EntryKey} (기존 ${clash.path})`);
|
||||
writeFileSync(outPath, JSON.stringify(file, null, 2) + '\n', 'utf8');
|
||||
written.push(enemyId);
|
||||
}
|
||||
console.log(`[gen-monster-models] ${written.length}종 emit${skipped.length ? ` / appearance 없음 스킵: ${skipped.join(', ')}` : ''}`);
|
||||
78
tools/monster/lib/monster-model.mjs
Normal file
78
tools/monster/lib/monster-model.mjs
Normal file
@@ -0,0 +1,78 @@
|
||||
// 몬스터 종별 모델(.model)과 맵 인스턴스 엔티티의 공용 빌더.
|
||||
// 단일 소스: data/enemies.json의 appearance. fs 접근 없음(호출자가 skeleton 주입) — 테스트 용이.
|
||||
const STR_TYPE = 'System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089';
|
||||
const SINGLE_TYPE = 'System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089';
|
||||
const VEC2_TYPE = 'MOD.Core.MODVector2, MOD.Core, Version=26.5.0.0, Culture=neutral, PublicKeyToken=null';
|
||||
const DICT_TYPE = 'MOD.Core.MODSyncDictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], MOD.Core, Version=26.5.0.0, Culture=neutral, PublicKeyToken=null';
|
||||
const native = (type) => ({ $type: 'MODNativeType', type });
|
||||
const vec2 = (v) => ({ $type: 'MOD.Core.MODVector2, MOD.Core', x: v.x, y: v.y });
|
||||
const DAMAGE_SKIN_ID = '02c22d93421b4038b3c413b3e40b57ec';
|
||||
|
||||
export function modelEntryId(enemyId) {
|
||||
return `monster-${enemyId}`;
|
||||
}
|
||||
|
||||
function requireAppearance(enemyId, enemy) {
|
||||
if (!enemy?.appearance?.sheet?.stand) throw new Error(`[monster-model] ${enemyId}: appearance.sheet.stand 없음 — data/enemies.json 확인`);
|
||||
return enemy.appearance;
|
||||
}
|
||||
|
||||
// .model 파일 전체 객체 생성 — ChaseMonster.model(skeleton)을 골격으로 복제·확장.
|
||||
export function buildMonsterModel(enemyId, enemy, skeletonJson) {
|
||||
const app = requireAppearance(enemyId, enemy);
|
||||
const file = JSON.parse(JSON.stringify(skeletonJson)); // 순수성: 입력 비변형
|
||||
const json = file.ContentProto.Json;
|
||||
file.EntryKey = `model://${modelEntryId(enemyId)}`;
|
||||
json.Id = modelEntryId(enemyId);
|
||||
json.Name = enemyId;
|
||||
json.Components = json.Components
|
||||
.filter((c) => !c.includes('AIWander') && !c.includes('AIChase'))
|
||||
.concat(['MOD.Core.DamageSkinSettingComponent', 'script.CombatMonster']);
|
||||
const setValue = (TargetType, Name, typeStr, Value) => {
|
||||
json.Values = json.Values.filter((v) => !(v.TargetType === TargetType && v.Name === Name));
|
||||
json.Values.push({ TargetType, Name, ValueType: native(typeStr), Value });
|
||||
};
|
||||
setValue('MOD.Core.SpriteRendererComponent', 'SpriteRUID', STR_TYPE, app.sheet.stand);
|
||||
setValue('MOD.Core.SpriteRendererComponent', 'SortingLayer', STR_TYPE, 'MapLayer0');
|
||||
setValue('MOD.Core.StateAnimationComponent', 'ActionSheet', DICT_TYPE, { ...app.sheet }); // 메이커 미해석 시 이 줄만 제거(런타임은 인스턴스 값 사용)
|
||||
setValue('MOD.Core.HitComponent', 'BoxSize', VEC2_TYPE, vec2(app.box));
|
||||
setValue('MOD.Core.HitComponent', 'ColliderOffset', VEC2_TYPE, vec2(app.off));
|
||||
setValue('MOD.Core.MovementComponent', 'InputSpeed', SINGLE_TYPE, 0);
|
||||
setValue('script.CombatMonster', 'EnemyId', STR_TYPE, enemyId); // 편의 베이크 — 실패해도 무해(인스턴스가 정본)
|
||||
return file;
|
||||
}
|
||||
|
||||
// 맵 인스턴스 엔티티 — 현행 맵 몬스터 인스턴스 골격(map01 실측)과 동일 형태.
|
||||
export function buildMonsterInstance({ enemyId, enemy, name, guid, mapTag, x, group }) {
|
||||
const app = requireAppearance(enemyId, enemy);
|
||||
const components = [
|
||||
{ '@type': 'MOD.Core.TransformComponent', Position: { x, y: 0.03499998, z: 999.999 }, QuaternionRotation: { x: 0, y: 0, z: 0, w: 1 }, Scale: { x: 1, y: 1, z: 1 }, Enable: true },
|
||||
{ '@type': 'MOD.Core.StateAnimationComponent', ActionSheet: { ...app.sheet }, Enable: true },
|
||||
{ '@type': 'MOD.Core.SpriteRendererComponent', ActionSheet: {}, EndFrameIndex: 0, RenderSetting: 1, SortingLayer: 'MapLayer0', SpriteRUID: app.sheet.stand, StartFrameIndex: 0, Enable: true },
|
||||
{ '@type': 'MOD.Core.RigidbodyComponent', MoveVelocity: { x: 0, y: 0 }, RealMoveVelocity: { x: 0, y: 0 }, Enable: true },
|
||||
{ '@type': 'MOD.Core.MovementComponent', InputSpeed: 0, JumpForce: 6, Enable: false },
|
||||
{ '@type': 'MOD.Core.StateComponent', IsLegacy: false, Enable: true },
|
||||
{ '@type': 'MOD.Core.HitComponent', BoxSize: { x: app.box.x, y: app.box.y }, ColliderOffset: { x: app.off.x, y: app.off.y }, IsLegacy: false, Enable: true },
|
||||
{ '@type': 'MOD.Core.DamageSkinSpawnerComponent', Enable: true },
|
||||
{ '@type': 'script.Monster', Enable: true, IsDead: false },
|
||||
{ '@type': 'script.MonsterAttack', Enable: true, SpriteSize: { x: 0, y: 0 }, PositionOffset: { x: 0, y: 0 } },
|
||||
{ '@type': 'MOD.Core.KinematicbodyComponent', MoveVelocity: { x: 0, y: 0 }, Enable: true },
|
||||
{ '@type': 'MOD.Core.SideviewbodyComponent', MoveVelocity: { x: 0, y: 0 }, Enable: true },
|
||||
{ '@type': 'MOD.Core.DamageSkinSettingComponent', DamageSkinId: { DataId: DAMAGE_SKIN_ID }, Enable: true },
|
||||
{ '@type': 'script.CombatMonster', Enable: true, EnemyId: enemyId, Group: group },
|
||||
];
|
||||
const path = `/maps/map${mapTag}/${name}`;
|
||||
return {
|
||||
id: guid,
|
||||
path,
|
||||
componentNames: components.map((c) => c['@type']).join(','),
|
||||
jsonString: {
|
||||
name, path, nameEditable: true, enable: true, visible: true, localize: false,
|
||||
displayOrder: 4, pathConstraints: '///', revision: 2,
|
||||
origin: { type: 'Model', entry_id: modelEntryId(enemyId), sub_entity_id: null, root_entity_id: guid, replaced_model_id: null },
|
||||
modelId: modelEntryId(enemyId),
|
||||
'@components': components,
|
||||
'@version': 1,
|
||||
},
|
||||
};
|
||||
}
|
||||
60
tools/monster/monster-model.test.mjs
Normal file
60
tools/monster/monster-model.test.mjs
Normal file
@@ -0,0 +1,60 @@
|
||||
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/);
|
||||
});
|
||||
Reference in New Issue
Block a user