Skip to content

Commit

Permalink
Adding entity properties to summarization
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanV2 committed Apr 19, 2023
1 parent 32cce22 commit ceafd89
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Lib/Internal/BehaviorPack/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ export interface EntityDescription extends ScriptContainer {
/** */
identifier: string;
/** */
is_spawnable?: true;
is_spawnable?: boolean;
/** */
is_summonable?: true;
is_summonable?: boolean;
/** */
is_experimental: boolean;
/** */
properties?: Record<string, any>;
}

/** */
Expand Down
3 changes: 3 additions & 0 deletions src/Lib/Project/BehaviorPack/Entity/Entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DefinedUsing, Molang } from "bc-minecraft-molang";
import { Types } from "bc-minecraft-bedrock-types";
import { AnimationCarrier, MolangCarrier } from "../../../Types";
import { EntityProperty } from './Properties';

/** */
export interface Entity extends Types.BaseObject,
Expand All @@ -17,4 +18,6 @@ export interface Entity extends Types.BaseObject,
families: string[];
/** */
animations: DefinedUsing<string>;
/** */
properties: EntityProperty[];
}
12 changes: 11 additions & 1 deletion src/Lib/Project/BehaviorPack/Entity/Process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TextDocument } from "../../../Types/TextDocument";
import { Entity } from "./Entity";
import { Documentation } from "../../../Types/Documentation";
import { EntityComponentContainer } from "../../../Internal/BehaviorPack/Entity";
import { ComponentContainer } from "bc-minecraft-bedrock-types/lib/src/Minecraft/Components";

/**
*
Expand All @@ -33,6 +34,7 @@ export function Process(doc: TextDocument): Entity | undefined {
families: [],
groups: [],
molang: Molang.MolangSet.harvest(container),
properties: [],
};

if (container.component_groups) {
Expand All @@ -42,19 +44,27 @@ export function Process(doc: TextDocument): Entity | undefined {
});
}
if (container.events) SMap.forEach(container.events, (event, name) => out.events.push(name));

//Animations
if (container.description.animations) {
SMap.forEach(container.description.animations, (anim, name) => {
out.animations.defined.push(name);
out.animations.using.push(anim);
});
}

if (container.description.properties) {
for (const [name, value] of Object.entries(container.description.properties)) {
out.properties.push({ name, ...value });
}
}

getFamilies(container.components, out.families);

return out;
}

function getFamilies(components: EntityComponentContainer, receiver: string[]) {
function getFamilies(components: ComponentContainer, receiver: string[]) {
const families = components["minecraft:type_family"];

if (type_family.is(families)) {
Expand Down
65 changes: 65 additions & 0 deletions src/Lib/Project/BehaviorPack/Entity/Properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export interface EntityBoolProperty {
default: boolean;
name: string;
type: "bool";
}

export namespace EntityBoolProperty {
export function is(value: any): value is EntityBoolProperty {
if (typeof value !== "object") return false;
if (value.type !== "bool") return false;

return true;
}
}

export interface EntityFloatProperty {
default: number;
name: string;
range: [number, number];
type: "float";
}

export namespace EntityFloatProperty {
export function is(value: any): value is EntityFloatProperty {
if (typeof value !== "object") return false;
if (value.type !== "float") return false;

return true;
}
}

export interface EntityIntProperty {
default: number;
name: string;
range: [number, number];
type: "int";
}

export namespace EntityIntProperty {
export function is(value: any): value is EntityIntProperty {
if (typeof value !== "object") return false;
if (value.type !== "int") return false;

return true;
}
}

export interface EntityEnumProperty {
client_sync: boolean;
default: string;
name: string;
type: "enum";
values: string[];
}

export namespace EntityEnumProperty {
export function is(value: any): value is EntityEnumProperty {
if (typeof value !== "object") return false;
if (value.type !== "enum") return false;

return true;
}
}

export type EntityProperty = EntityBoolProperty | EntityFloatProperty | EntityIntProperty | EntityEnumProperty;

0 comments on commit ceafd89

Please sign in to comment.