mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: the thing
This commit is contained in:
1 parent
e60bbc03d2
commit
b856268ee0
9 files changed
+63
-107
No files matched your search
@@ -47,6 +47,7 @@ export * from './createDefaultProvisions';
|
||||
export * from './metaSortTank';
|
||||
export * from './romanize';
|
||||
export * from './tank';
|
||||
export * from './tankArmor';
|
||||
export * from './tanks';
|
||||
export * from './tanksFull';
|
||||
export * from './youtubers';
|
||||
@@ -0,0 +1,7 @@
|
||||
import { fetchPB } from '../protobuf';
|
||||
import { TankArmor } from '../protos';
|
||||
import { asset } from './asset';
|
||||
|
||||
export function fetchTankArmor(id: string) {
|
||||
return fetchPB(asset(`tanks/${id}/armor.pb`), TankArmor);
|
||||
}
|
||||
@@ -3,10 +3,8 @@ syntax = "proto2";
|
||||
package blitzkit;
|
||||
|
||||
message TankArmor {
|
||||
// tank id
|
||||
required string id = 1;
|
||||
// key can only ever be "chassis", "hull", "turret", or "gun"
|
||||
map<string, PenetrationGroup> groups = 4;
|
||||
map<string, PenetrationGroup> groups = 1;
|
||||
}
|
||||
|
||||
message PenetrationGroup {
|
||||
|
||||
@@ -10,8 +10,6 @@ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
||||
export const protobufPackage = "blitzkit";
|
||||
|
||||
export interface TankArmor {
|
||||
/** tank id */
|
||||
id: string;
|
||||
/** key can only ever be "chassis", "hull", "turret", or "gun" */
|
||||
groups: { [key: string]: PenetrationGroup };
|
||||
}
|
||||
@@ -42,16 +40,13 @@ export interface ArmorPlate {
|
||||
}
|
||||
|
||||
function createBaseTankArmor(): TankArmor {
|
||||
return { id: "", groups: {} };
|
||||
return { groups: {} };
|
||||
}
|
||||
|
||||
export const TankArmor: MessageFns<TankArmor> = {
|
||||
encode(message: TankArmor, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
||||
if (message.id !== "") {
|
||||
writer.uint32(10).string(message.id);
|
||||
}
|
||||
Object.entries(message.groups).forEach(([key, value]) => {
|
||||
TankArmor_GroupsEntry.encode({ key: key as any, value }, writer.uint32(34).fork()).join();
|
||||
TankArmor_GroupsEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join();
|
||||
});
|
||||
return writer;
|
||||
},
|
||||
@@ -68,17 +63,9 @@ export const TankArmor: MessageFns<TankArmor> = {
|
||||
break;
|
||||
}
|
||||
|
||||
message.id = reader.string();
|
||||
continue;
|
||||
}
|
||||
case 4: {
|
||||
if (tag !== 34) {
|
||||
break;
|
||||
}
|
||||
|
||||
const entry4 = TankArmor_GroupsEntry.decode(reader, reader.uint32());
|
||||
if (entry4.value !== undefined) {
|
||||
message.groups[entry4.key] = entry4.value;
|
||||
const entry1 = TankArmor_GroupsEntry.decode(reader, reader.uint32());
|
||||
if (entry1.value !== undefined) {
|
||||
message.groups[entry1.key] = entry1.value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -93,7 +80,6 @@ export const TankArmor: MessageFns<TankArmor> = {
|
||||
|
||||
fromJSON(object: any): TankArmor {
|
||||
return {
|
||||
id: globalThis.String(assertSet("TankArmor.id", object.id)),
|
||||
groups: isObject(object.groups)
|
||||
? Object.entries(object.groups).reduce<{ [key: string]: PenetrationGroup }>((acc, [key, value]) => {
|
||||
acc[key] = PenetrationGroup.fromJSON(value);
|
||||
@@ -105,9 +91,6 @@ export const TankArmor: MessageFns<TankArmor> = {
|
||||
|
||||
toJSON(message: TankArmor): unknown {
|
||||
const obj: any = {};
|
||||
if (message.id !== "") {
|
||||
obj.id = message.id;
|
||||
}
|
||||
if (message.groups) {
|
||||
const entries = Object.entries(message.groups);
|
||||
if (entries.length > 0) {
|
||||
@@ -125,7 +108,6 @@ export const TankArmor: MessageFns<TankArmor> = {
|
||||
},
|
||||
fromPartial<I extends Exact<DeepPartial<TankArmor>, I>>(object: I): TankArmor {
|
||||
const message = createBaseTankArmor();
|
||||
message.id = object.id ?? "";
|
||||
message.groups = Object.entries(object.groups ?? {}).reduce<{ [key: string]: PenetrationGroup }>(
|
||||
(acc, [key, value]) => {
|
||||
if (value !== undefined) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { asset, type Tank } from '@blitzkit/core';
|
||||
import { asset, TankArmor, type Tank } from '@blitzkit/core';
|
||||
import { useLoader } from '@react-three/fiber';
|
||||
import { Material, MeshBasicMaterial } from 'three';
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
||||
@@ -7,10 +7,11 @@ import { jsxTree } from '../core/blitzkit/jsxTree';
|
||||
|
||||
interface ArmorGroupProps {
|
||||
tank: Tank;
|
||||
armor: TankArmor;
|
||||
group: string;
|
||||
}
|
||||
|
||||
export function ArmorGroup({ tank, group }: ArmorGroupProps) {
|
||||
export function ArmorGroup({ tank, armor, group }: ArmorGroupProps) {
|
||||
const gltf = useLoader(
|
||||
GLTFLoader,
|
||||
asset(`/tanks/${tank.id}/collision/hull.glb`),
|
||||
@@ -31,7 +32,7 @@ export function ArmorGroup({ tank, group }: ArmorGroupProps) {
|
||||
event.stopPropagation();
|
||||
|
||||
const armorName = mesh.material.name;
|
||||
const penetrationGroup = tank.penetration_groups[group];
|
||||
const penetrationGroup = armor.groups[group];
|
||||
const thickness = penetrationGroup.armors[armorName];
|
||||
|
||||
console.log(tank.id, armorName, penetrationGroup, thickness);
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
import { Tank } from '@blitzkit/core';
|
||||
import { Tank, TankArmor } from '@blitzkit/core';
|
||||
import { Box } from '@radix-ui/themes';
|
||||
import { OrbitControls } from '@react-three/drei';
|
||||
import { Canvas } from '@react-three/fiber';
|
||||
import { ArmorGroup } from '../../../../components/ArmorGroup';
|
||||
import { PageWrapper } from '../../../../components/PageWrapper';
|
||||
|
||||
interface PageProps {
|
||||
tank: Tank;
|
||||
armor: TankArmor;
|
||||
}
|
||||
|
||||
export function Page({ tank }: PageProps) {
|
||||
export function Page({ tank, armor }: PageProps) {
|
||||
return (
|
||||
<Canvas
|
||||
style={{
|
||||
width: 640,
|
||||
height: 640,
|
||||
}}
|
||||
>
|
||||
<OrbitControls />
|
||||
<ArmorGroup group="hull" tank={tank} />
|
||||
</Canvas>
|
||||
<PageWrapper p="0" maxWidth="unset">
|
||||
<Box height="100%" width="100%" flexGrow="1" position="relative">
|
||||
<Box position="absolute" top="0" left="0" width="100%" height="100%">
|
||||
<Canvas>
|
||||
<OrbitControls />
|
||||
<ArmorGroup group="hull" tank={tank} armor={armor} />
|
||||
</Canvas>
|
||||
</Box>
|
||||
</Box>
|
||||
</PageWrapper>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
import { fetchTank } from '@blitzkit/core';
|
||||
import { fetchTank, fetchTankArmor } from '@blitzkit/core';
|
||||
import type { GetStaticPaths } from 'astro';
|
||||
import { awaitableTanksFull } from '../../../../core/awaitables/tanksFull';
|
||||
import BaseLayout from '../../../../layouts/BaseLayout.astro';
|
||||
@@ -22,8 +22,9 @@ export const getStaticPaths = (async () => {
|
||||
|
||||
const { id } = Astro.props;
|
||||
const tank = await fetchTank(id);
|
||||
const armor = await fetchTankArmor(id);
|
||||
---
|
||||
|
||||
<BaseLayout>
|
||||
<Page {tank} client:load />
|
||||
<Page {tank} {armor} client:load />
|
||||
</BaseLayout>
|
||||
@@ -0,0 +1,16 @@
|
||||
import { fetchTankArmor } from '@blitzkit/core';
|
||||
import type { APIRoute } from 'astro';
|
||||
|
||||
export { getStaticPaths } from './meta.json';
|
||||
|
||||
/**
|
||||
* Returns the thicknesses and types of all armor plates on a tank chunked into
|
||||
* groups.
|
||||
*
|
||||
* @param id The tank id.
|
||||
* @returns JSON.
|
||||
*/
|
||||
export const GET: APIRoute<{}, { id: string }> = async ({ params }) => {
|
||||
const tank = await fetchTankArmor(params.id);
|
||||
return Response.json(tank);
|
||||
};
|
||||
@@ -25,18 +25,18 @@ namespace Blitzkit {
|
||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||
string.Concat(
|
||||
"CilwYWNrYWdlcy9jb3JlL3NyYy9wcm90b3MvdGFua19hcm1vci5wcm90bxII",
|
||||
"YmxpdHpraXQikwEKCVRhbmtBcm1vchIKCgJpZBgBIAIoCRIvCgZncm91cHMY",
|
||||
"BCADKAsyHy5ibGl0emtpdC5UYW5rQXJtb3IuR3JvdXBzRW50cnkaSQoLR3Jv",
|
||||
"dXBzRW50cnkSCwoDa2V5GAEgASgJEikKBXZhbHVlGAIgASgLMhouYmxpdHpr",
|
||||
"aXQuUGVuZXRyYXRpb25Hcm91cDoCOAEijwEKEFBlbmV0cmF0aW9uR3JvdXAS",
|
||||
"NgoGYXJtb3JzGAEgAygLMiYuYmxpdHpraXQuUGVuZXRyYXRpb25Hcm91cC5B",
|
||||
"cm1vcnNFbnRyeRpDCgtBcm1vcnNFbnRyeRILCgNrZXkYASABKAkSIwoFdmFs",
|
||||
"dWUYAiABKAsyFC5ibGl0emtpdC5Bcm1vclBsYXRlOgI4ASItCgpBcm1vclBs",
|
||||
"YXRlEhEKCXRoaWNrbmVzcxgBIAIoAhIMCgR0eXBlGAIgAigJ"));
|
||||
"YmxpdHpraXQihwEKCVRhbmtBcm1vchIvCgZncm91cHMYASADKAsyHy5ibGl0",
|
||||
"emtpdC5UYW5rQXJtb3IuR3JvdXBzRW50cnkaSQoLR3JvdXBzRW50cnkSCwoD",
|
||||
"a2V5GAEgASgJEikKBXZhbHVlGAIgASgLMhouYmxpdHpraXQuUGVuZXRyYXRp",
|
||||
"b25Hcm91cDoCOAEijwEKEFBlbmV0cmF0aW9uR3JvdXASNgoGYXJtb3JzGAEg",
|
||||
"AygLMiYuYmxpdHpraXQuUGVuZXRyYXRpb25Hcm91cC5Bcm1vcnNFbnRyeRpD",
|
||||
"CgtBcm1vcnNFbnRyeRILCgNrZXkYASABKAkSIwoFdmFsdWUYAiABKAsyFC5i",
|
||||
"bGl0emtpdC5Bcm1vclBsYXRlOgI4ASItCgpBcm1vclBsYXRlEhEKCXRoaWNr",
|
||||
"bmVzcxgBIAIoAhIMCgR0eXBlGAIgAigJ"));
|
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||
new pbr::FileDescriptor[] { },
|
||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Blitzkit.TankArmor), global::Blitzkit.TankArmor.Parser, new[]{ "Id", "Groups" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { null, }),
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Blitzkit.TankArmor), global::Blitzkit.TankArmor.Parser, new[]{ "Groups" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { null, }),
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Blitzkit.PenetrationGroup), global::Blitzkit.PenetrationGroup.Parser, new[]{ "Armors" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { null, }),
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Blitzkit.ArmorPlate), global::Blitzkit.ArmorPlate.Parser, new[]{ "Thickness", "Type" }, null, null, null, null)
|
||||
}));
|
||||
@@ -80,7 +80,6 @@ namespace Blitzkit {
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public TankArmor(TankArmor other) : this() {
|
||||
id_ = other.id_;
|
||||
groups_ = other.groups_.Clone();
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
@@ -91,39 +90,10 @@ namespace Blitzkit {
|
||||
return new TankArmor(this);
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "id" field.</summary>
|
||||
public const int IdFieldNumber = 1;
|
||||
private readonly static string IdDefaultValue = "";
|
||||
|
||||
private string id_;
|
||||
/// <summary>
|
||||
/// tank id
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string Id {
|
||||
get { return id_ ?? IdDefaultValue; }
|
||||
set {
|
||||
id_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
/// <summary>Gets whether the "id" field is set</summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool HasId {
|
||||
get { return id_ != null; }
|
||||
}
|
||||
/// <summary>Clears the value of the "id" field</summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void ClearId() {
|
||||
id_ = null;
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "groups" field.</summary>
|
||||
public const int GroupsFieldNumber = 4;
|
||||
public const int GroupsFieldNumber = 1;
|
||||
private static readonly pbc::MapField<string, global::Blitzkit.PenetrationGroup>.Codec _map_groups_codec
|
||||
= new pbc::MapField<string, global::Blitzkit.PenetrationGroup>.Codec(pb::FieldCodec.ForString(10, ""), pb::FieldCodec.ForMessage(18, global::Blitzkit.PenetrationGroup.Parser), 34);
|
||||
= new pbc::MapField<string, global::Blitzkit.PenetrationGroup>.Codec(pb::FieldCodec.ForString(10, ""), pb::FieldCodec.ForMessage(18, global::Blitzkit.PenetrationGroup.Parser), 10);
|
||||
private readonly pbc::MapField<string, global::Blitzkit.PenetrationGroup> groups_ = new pbc::MapField<string, global::Blitzkit.PenetrationGroup>();
|
||||
/// <summary>
|
||||
/// key can only ever be "chassis", "hull", "turret", or "gun"
|
||||
@@ -149,7 +119,6 @@ namespace Blitzkit {
|
||||
if (ReferenceEquals(other, this)) {
|
||||
return true;
|
||||
}
|
||||
if (Id != other.Id) return false;
|
||||
if (!Groups.Equals(other.Groups)) return false;
|
||||
return Equals(_unknownFields, other._unknownFields);
|
||||
}
|
||||
@@ -158,7 +127,6 @@ namespace Blitzkit {
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override int GetHashCode() {
|
||||
int hash = 1;
|
||||
if (HasId) hash ^= Id.GetHashCode();
|
||||
hash ^= Groups.GetHashCode();
|
||||
if (_unknownFields != null) {
|
||||
hash ^= _unknownFields.GetHashCode();
|
||||
@@ -178,10 +146,6 @@ namespace Blitzkit {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
output.WriteRawMessage(this);
|
||||
#else
|
||||
if (HasId) {
|
||||
output.WriteRawTag(10);
|
||||
output.WriteString(Id);
|
||||
}
|
||||
groups_.WriteTo(output, _map_groups_codec);
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(output);
|
||||
@@ -193,10 +157,6 @@ namespace Blitzkit {
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
||||
if (HasId) {
|
||||
output.WriteRawTag(10);
|
||||
output.WriteString(Id);
|
||||
}
|
||||
groups_.WriteTo(ref output, _map_groups_codec);
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(ref output);
|
||||
@@ -208,9 +168,6 @@ namespace Blitzkit {
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public int CalculateSize() {
|
||||
int size = 0;
|
||||
if (HasId) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Id);
|
||||
}
|
||||
size += groups_.CalculateSize(_map_groups_codec);
|
||||
if (_unknownFields != null) {
|
||||
size += _unknownFields.CalculateSize();
|
||||
@@ -224,9 +181,6 @@ namespace Blitzkit {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
if (other.HasId) {
|
||||
Id = other.Id;
|
||||
}
|
||||
groups_.MergeFrom(other.groups_);
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||
}
|
||||
@@ -248,10 +202,6 @@ namespace Blitzkit {
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||
break;
|
||||
case 10: {
|
||||
Id = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 34: {
|
||||
groups_.AddEntriesFrom(input, _map_groups_codec);
|
||||
break;
|
||||
}
|
||||
@@ -275,10 +225,6 @@ namespace Blitzkit {
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
||||
break;
|
||||
case 10: {
|
||||
Id = input.ReadString();
|
||||
break;
|
||||
}
|
||||
case 34: {
|
||||
groups_.AddEntriesFrom(ref input, _map_groups_codec);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user