fixed bugs

This commit is contained in:
IDONTSUDO 2024-09-26 18:41:51 +03:00
parent 5eb588a709
commit 50d239a4eb
5 changed files with 48 additions and 17 deletions

View file

@ -39,6 +39,7 @@
"ws": "^8.17.0", "ws": "^8.17.0",
"xml-formatter": "^3.6.2" "xml-formatter": "^3.6.2"
}, },
"overrides": { "overrides": {
"typescript": "^5.0.2" "typescript": "^5.0.2"
}, },
@ -75,4 +76,4 @@
"@types/three": "^0.158.3", "@types/three": "^0.158.3",
"@types/uuid": "^9.0.2" "@types/uuid": "^9.0.2"
} }
} }

View file

@ -66,7 +66,8 @@ declare global {
overrideValue(key: K, value: OptionalProperties<V>): void; overrideValue(key: K, value: OptionalProperties<V>): void;
keysToJson(): string; keysToJson(): string;
toArray(): V[]; toArray(): V[];
getPredicateValue(callBack: (value: V) => boolean): K[]; toArrayEntries(): { key: K; value: V }[];
getPredicateKey(callBack: (value: V) => boolean): K[];
incrementValue(key: K): void; incrementValue(key: K): void;
} }
interface Boolean { interface Boolean {

View file

@ -35,13 +35,23 @@ export const MapExtensions = () => {
return JSON.stringify(result); return JSON.stringify(result);
}; };
} }
if (Map.prototype.toArrayEntries === undefined) {
Map.prototype.toArrayEntries = function () {
const result = [];
for (const el of this.entries()) {
result.push({ key: el[0], value: el[1] });
}
return result;
};
}
if (Map.prototype.toArray === undefined) { if (Map.prototype.toArray === undefined) {
Map.prototype.toArray = function () { Map.prototype.toArray = function () {
return Array.from(this.values()); return Array.from(this.values());
}; };
} }
if (Map.prototype.getPredicateValue === undefined) {
Map.prototype.getPredicateValue = function (callBack) { if (Map.prototype.getPredicateKey === undefined) {
Map.prototype.getPredicateKey = function (callBack) {
const result: any[] = []; const result: any[] = [];
this.forEach((el, key) => { this.forEach((el, key) => {
const callBackExecute = callBack(el); const callBackExecute = callBack(el);

View file

@ -5,6 +5,7 @@ import { Result } from "../../../core/helper/result";
import { AreaPlugin } from "rete-area-plugin"; import { AreaPlugin } from "rete-area-plugin";
import { Skills } from "../../../core/model/skill_model"; import { Skills } from "../../../core/model/skill_model";
import xmlFormat from "xml-formatter"; import xmlFormat from "xml-formatter";
import { Position } from "rete-react-plugin";
export interface BtDrawDragAndDropView { export interface BtDrawDragAndDropView {
x: number; x: number;
@ -25,6 +26,7 @@ export interface IUpdateEvent {
export class NodeRerenderObserver extends TypedEvent<IUpdateEvent> {} export class NodeRerenderObserver extends TypedEvent<IUpdateEvent> {}
export class ReteForceUpdateObserver extends TypedEvent<any> {} export class ReteForceUpdateObserver extends TypedEvent<any> {}
export class BehaviorTreeBuilderModel { export class BehaviorTreeBuilderModel {
public static nodeView: Map<string, Position> = new Map();
public static btRootTag: string = '<root BTCPP_format="4"><BehaviorTree ID="Main">${bt}</BehaviorTree></root>'; public static btRootTag: string = '<root BTCPP_format="4"><BehaviorTree ID="Main">${bt}</BehaviorTree></root>';
public static result = ""; public static result = "";
@ -35,10 +37,11 @@ export class BehaviorTreeBuilderModel {
): Result<string, string> { ): Result<string, string> {
try { try {
this.result = ""; this.result = "";
area.nodeViews.toArrayEntries().forEach((el) => this.nodeView.set(el.key, el.value.position));
this.getFirstSequence(editor).map((sortedSequence) => { this.getFirstSequence(editor).map((sortedSequence) => {
const firstNodeId = sortedSequence.getKeyFromValueIsExists(1) as string; const firstNodeId = sortedSequence.getKeyFromValueIsExists(1) as string;
this.findSequence(firstNodeId, editor, sortedSequence, 2); this.findSequence(firstNodeId, editor, sortedSequence, 2);
// sortedSequence.toArrayEntries().forEach((el) => console.log(el));
this.result += `<${this.getNodeLabelAtId(editor, firstNodeId, skills)}>`; this.result += `<${this.getNodeLabelAtId(editor, firstNodeId, skills)}>`;
this.toXML(sortedSequence as Map<string, number>, editor, area, firstNodeId, skills); this.toXML(sortedSequence as Map<string, number>, editor, area, firstNodeId, skills);
this.result += `</${this.getNodeLabelAtId(editor, firstNodeId, skills)}>`; this.result += `</${this.getNodeLabelAtId(editor, firstNodeId, skills)}>`;
@ -87,13 +90,19 @@ export class BehaviorTreeBuilderModel {
activeElementId = "", activeElementId = "",
skills?: Skills skills?: Skills
) { ) {
const sources: string[] = [];
editor.getConnections().forEach((el) => { editor.getConnections().forEach((el) => {
if (el.source === activeElementId) { if (el.source === activeElementId) {
this.result += `<${this.getNodeLabelAtId(editor, el.target, skills)}>`; sources.push(el.target);
this.toXML(sortedSequence, editor, area, el.target, skills);
this.result += `</${this.getNodeLabelAtId(editor, el.target)}>`;
} }
}); });
sources
.sort((a, b) => (this.nodeView.get(a)!.y > this.nodeView.get(b)!.y ? 1 : -1))
.forEach((el) => {
this.result += `<${this.getNodeLabelAtId(editor, el, skills)}>`;
this.toXML(sortedSequence, editor, area, el, skills);
this.result += `</${this.getNodeLabelAtId(editor, el)}>`;
});
} }
public static findSequence( public static findSequence(
@ -102,19 +111,28 @@ export class BehaviorTreeBuilderModel {
result: Map<string, boolean | number>, result: Map<string, boolean | number>,
lvl: number lvl: number
): Map<string, number> | undefined { ): Map<string, number> | undefined {
const connections: string[] = []; const allConnections: { id: string; target: string }[] = [];
editor.getConnections().forEach((el) => { editor.getConnections().forEach((el) => {
if (el.source === nodeId) { if (el.source === nodeId) {
connections.push(el.target); allConnections.push({ id: el.id, target: el.target });
} }
}); });
if (connections.isEmpty()) return result as Map<string, number>; const connectionsSort = allConnections.sort((a, b) => {
let lv = lvl; if (this.nodeView.get(a.target)!.y > this.nodeView.get(b.target)!.y) {
connections.forEach((el) => { return 1;
result.set(el, lvl); }
this.findSequence(el, editor, result, (lv += 1)); return -1;
});
if (connectionsSort.isEmpty()) return result as Map<string, number>;
let cashedLvl = lvl;
connectionsSort.forEach((el) => {
result.set(el.target, lvl);
this.findSequence(el.target, editor, result, (cashedLvl += 1));
}); });
} }
public static getFirstSequence(editor: NodeEditor<Schemes>): Result<undefined, Map<string, boolean | number>> { public static getFirstSequence(editor: NodeEditor<Schemes>): Result<undefined, Map<string, boolean | number>> {
@ -126,7 +144,6 @@ export class BehaviorTreeBuilderModel {
editor.getConnections().forEach((el) => { editor.getConnections().forEach((el) => {
node.set(el.target, false); node.set(el.target, false);
}); });
const key = node.getKeyFromValueIsExists(1); const key = node.getKeyFromValueIsExists(1);
if (key === undefined) { if (key === undefined) {
return Result.error(undefined); return Result.error(undefined);

View file

@ -208,12 +208,12 @@ export class BehaviorTreeBuilderStore extends UiDrawerFormState<BehaviorTreeView
) )
).fold( ).fold(
(xml) => { (xml) => {
console.log(xml);
this.behaviorTreeModel.skills = this.filledOutTemplates; this.behaviorTreeModel.skills = this.filledOutTemplates;
this.behaviorTreeModel.scene = NodeBehaviorTree.fromReteScene( this.behaviorTreeModel.scene = NodeBehaviorTree.fromReteScene(
this.editor as NodeEditor<Schemes>, this.editor as NodeEditor<Schemes>,
this.areaPlugin as AreaPlugin<Schemes, AreaExtra> this.areaPlugin as AreaPlugin<Schemes, AreaExtra>
); );
this.behaviorTreeModel.xml = xml; this.behaviorTreeModel.xml = xml;
this.behaviorTreeModel.project = this.activeProject; this.behaviorTreeModel.project = this.activeProject;
this.messageHttp(this.behaviorTreeBuilderHttpRepository.editBt(this.behaviorTreeModel), { this.messageHttp(this.behaviorTreeBuilderHttpRepository.editBt(this.behaviorTreeModel), {
@ -274,10 +274,12 @@ export class BehaviorTreeBuilderStore extends UiDrawerFormState<BehaviorTreeView
} }
result.push(paramClone); result.push(paramClone);
}); });
this.filledOutTemplates.topicsStack.push(...model.topicsOut);
action.param = result; action.param = result;
return action; return action;
}); });
this.filledOutTemplates.updateSkill(model); this.filledOutTemplates.updateSkill(model);
console.log(this.filledOutTemplates.topicsStack)
this.editDrawer(DrawerState.editThreadBehaviorTree, false); this.editDrawer(DrawerState.editThreadBehaviorTree, false);
}, },
() => console.log("UNKNOWN SID: " + this.selectedSid) () => console.log("UNKNOWN SID: " + this.selectedSid)