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",
"xml-formatter": "^3.6.2"
},
"overrides": {
"typescript": "^5.0.2"
},
@ -75,4 +76,4 @@
"@types/three": "^0.158.3",
"@types/uuid": "^9.0.2"
}
}
}

View file

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

View file

@ -35,13 +35,23 @@ export const MapExtensions = () => {
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) {
Map.prototype.toArray = function () {
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[] = [];
this.forEach((el, key) => {
const callBackExecute = callBack(el);

View file

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

View file

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