feat: module hot swapping

This commit is contained in:
TrèsAbhi committed 2024-01-01 14:48:46 -06:00
1 parent a1c80c3d27
commit d4e16048e9
5 files changed
+58 -27

No files matched your search

Binary file not shown.
+24 -16
View File
@@ -117,6 +117,7 @@ interface VehicleDefinitions {
pumpGunMode?: boolean; pumpGunMode?: boolean;
pumpGunReloadTimes?: string; pumpGunReloadTimes?: string;
clip?: { count: number; rate: number }; clip?: { count: number; rate: number };
models: { undamaged: string };
}; };
}; };
}; };
@@ -218,7 +219,9 @@ if (allTargets || targets?.includes('definitions')) {
const tankTurrets = Object.keys(tankDefinition.root.turrets0).map( const tankTurrets = Object.keys(tankDefinition.root.turrets0).map(
(turretKey) => { (turretKey) => {
const turret = tankDefinition.root.turrets0[turretKey]; const turret = tankDefinition.root.turrets0[turretKey];
console.log(parse(turret.models.undamaged).name); const turretModel = Number(
parse(turret.models.undamaged).name.split('_')[1],
);
const turretId = toUniqueId(nation, turretList.root.ids[turretKey]); const turretId = toUniqueId(nation, turretList.root.ids[turretKey]);
const turretYaw = ( const turretYaw = (
typeof turret.yawLimits === 'string' typeof turret.yawLimits === 'string'
@@ -247,6 +250,9 @@ if (allTargets || targets?.includes('definitions')) {
) )
.split(' ') .split(' ')
.map(Number) as [number, number]; .map(Number) as [number, number];
const gunModel = Number(
parse(turretGunEntry.models.undamaged).name.split('_')[1],
);
const gunName = const gunName =
strings[gun.userString] ?? gunKey.replaceAll('_', ' '); strings[gun.userString] ?? gunKey.replaceAll('_', ' ');
const gunType = const gunType =
@@ -298,6 +304,7 @@ if (allTargets || targets?.includes('definitions')) {
reload: gunReload, reload: gunReload,
count: gunClipCount, count: gunClipCount,
interClip: gunInterClip, interClip: gunInterClip,
model: gunModel,
} as GunDefinition; } as GunDefinition;
}); });
@@ -310,8 +317,9 @@ if (allTargets || targets?.includes('definitions')) {
.replace(/^(Turret ([0-9] )?)+/, ''), .replace(/^(Turret ([0-9] )?)+/, ''),
tier: turret.level as Tier, tier: turret.level as Tier,
yaw: -turretYaw[0] + turretYaw[1] === 360 ? undefined : turretYaw, yaw: -turretYaw[0] + turretYaw[1] === 360 ? undefined : turretYaw,
gunOrigin,
guns: turretGuns, guns: turretGuns,
gunOrigin,
model: turretModel,
} satisfies TurretDefinition; } satisfies TurretDefinition;
}, },
); );
@@ -347,20 +355,20 @@ if (allTargets || targets?.includes('definitions')) {
); );
console.log('Committing tank definitions...'); console.log('Committing tank definitions...');
// await commitMultipleFiles( await commitMultipleFiles(
// 'tresabhi', 'tresabhi',
// 'blitzkrieg-assets', 'blitzkrieg-assets',
// 'main', 'main',
// 'definitions', 'definitions',
// [ [
// { {
// content: JSON.stringify(tankDefinitions), content: JSON.stringify(tankDefinitions),
// encoding: 'utf-8', encoding: 'utf-8',
// path: 'definitions/tanks.json', path: 'definitions/tanks.json',
// }, },
// ], ],
// true, true,
// ); );
} }
if ( if (
+30 -3
View File
@@ -27,7 +27,7 @@ import { go } from 'fuzzysort';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import Link from 'next/link'; import Link from 'next/link';
import { use, useEffect, useRef, useState } from 'react'; import { use, useEffect, useRef, useState } from 'react';
import { Group } from 'three'; import { Group, Mesh } from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'; import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { Flag } from '../../../../components/Flag'; import { Flag } from '../../../../components/Flag';
import { ModuleButtons } from '../../../../components/ModuleButton'; import { ModuleButtons } from '../../../../components/ModuleButton';
@@ -130,8 +130,35 @@ export default function Page({ params }: { params: { id: string } }) {
/> />
</EffectComposer> </EffectComposer>
<group ref={model}> <group ref={model} rotation={[-Math.PI / 2, 0, 0]}>
<primitive object={gltf.scene} /> {Object.entries(gltf.nodes).map(([name, node]) => (
<mesh
visible={
name === 'hull' ||
name.startsWith('chassis_track_') ||
name.startsWith('chassis_wheel_') ||
(name.startsWith('turret_') &&
name ===
`turret_${turret.model
.toString()
.padStart(2, '0')}`) ||
(name.startsWith('gun_') &&
name ===
`gun_${gun.model.toString().padStart(2, '0')}`) ||
name ===
`gun_${gun.model.toString().padStart(2, '0')}_mask`
}
name={name}
key={node.id}
castShadow
receiveShadow
geometry={(node as Mesh).geometry}
material={(node as Mesh).material}
position={node.position}
rotation={node.rotation}
scale={node.scale}
/>
))}
</group> </group>
</Canvas> </Canvas>
</div> </div>
+1 -7
View File
@@ -323,13 +323,7 @@ export async function extractModel(
}); });
} }
// rotate 90 degrees on the x axis parseHierarchies(sc2['#hierarchy'], scene);
const rootNode = document
.createNode('root')
.setRotation([Math.cos(Math.PI / 4), 0, 0, -Math.sin(Math.PI / 4)]);
scene.addChild(rootNode);
parseHierarchies(sc2['#hierarchy'], rootNode);
return document; return document;
} }
+3 -1
View File
@@ -27,8 +27,9 @@ export interface TurretDefinition {
name: string; name: string;
tier: Tier; tier: Tier;
yaw?: [number, number]; yaw?: [number, number];
gunOrigin: Vector3Tuple;
guns: GunDefinition[]; guns: GunDefinition[];
gunOrigin: Vector3Tuple;
model: number;
} }
export type GunDefinition = GunDefinitionBase & export type GunDefinition = GunDefinitionBase &
(GunDefinitionRegular | GunDefinitionAutoLoader | GunDefinitionAutoReloader); (GunDefinitionRegular | GunDefinitionAutoLoader | GunDefinitionAutoReloader);
@@ -38,6 +39,7 @@ interface GunDefinitionBase {
tier: Tier; tier: Tier;
pitch: [number, number]; pitch: [number, number];
shells: ShellDefinition[]; shells: ShellDefinition[];
model: number;
} }
interface GunDefinitionRegular { interface GunDefinitionRegular {
type: 'regular'; type: 'regular';