UNPKG

@gmetrixr/rjson

Version:
37 lines (36 loc) 1.54 kB
import { r, rtp, RT, en } from "../../../r"; /** * Remove rules when events and then actions for collider mesh element */ class Migration { execute(projectJson) { const pJson = projectJson; const projectF = r.record(pJson); const scenes = projectF.getRecords(RT.scene); for (const scene of scenes) { const sceneF = r.scene(scene); const colliderMeshElements = sceneF.getAllDeepChildrenIdsWithFilter(RT.element, (el) => el.props.element_type === en.ElementType.collider_mesh); if (colliderMeshElements.length > 0) { const rules = sceneF.getRecords(RT.rule); for (const rule of rules) { const ruleF = r.record(rule); const whenEvents = ruleF.getRecords(RT.when_event); for (const we of whenEvents) { if (colliderMeshElements.includes(we.props.co_id)) { ruleF.deleteRecord(RT.when_event, we.id); } } const thenActions = ruleF.getRecords(RT.then_action); for (const ta of thenActions) { if (colliderMeshElements.includes(ta.props.co_id)) { ruleF.deleteRecord(RT.then_action, ta.id); } } } } } projectF.set(rtp.project.version, 148); } } const migration = new Migration(); export default migration;