Skip to content

Commit

Permalink
fixing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
meisZWFLZ committed Mar 6, 2023
1 parent 6b49559 commit dec4eb5
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 13 deletions.
1 change: 0 additions & 1 deletion exampleFiles/SPINUPfield.pawdraw

This file was deleted.

1 change: 1 addition & 0 deletions exampleFiles/SPINUPfield.vauto
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"position":{"x":69,"y":98,"heading":-101,"marginOfError":8.981606814793919},"actions":[0,1,3,2,4]},{"position":{"x":72,"y":72,"heading":0,"marginOfError":6}},{"position":{"x":83,"y":101,"heading":0,"marginOfError":20.256234283143364}},{"position":{"x":134,"y":58,"heading":97,"marginOfError":9.326487700546172},"actions":[0]}]
2 changes: 1 addition & 1 deletion media/SpinUpField.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"displayName": "Paw Draw",
"selector": [
{
"filenamePattern": "*.pawdraw"
"filenamePattern": "*.vauto"
}
]
}
Expand Down
1 change: 0 additions & 1 deletion src/webview/eventList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { EventEmitter } from "events";
export enum LIST_ACTION_TYPE {
APPEND,
INSERT,
Expand Down
15 changes: 13 additions & 2 deletions src/webview/listManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class ListManager {
/** checks if index is in bounds, if not, it will return it in bounds using modulo*/
public _fixIndexWrap(index: number = this.index): number {
return (index =
(index < 0 ? this.list.length - 1 : 0) + (index % this.list.length));
(index < 0 ? this.list.length : 0) + (index % this.list.length));
}
/** checks if index is in bounds, if not, it will return it in bounds by shifting the number in bounds*/
public _fixIndexShift(index: number = this.index): number {
Expand Down Expand Up @@ -252,7 +252,18 @@ export default class ListManager {
this.appendNode(this.newNode);
}
public insertNewNodeAfterCur() {
this.insertAfterCurNode(this.newNode);
this.insertAfterCurNode(
structuredClone({
actions: this.newNode.actions,
position: {
...this.getCurNode().position,
marginOfError:
this.getCurError() < 1
? this.newNode.position.marginOfError
: this.getCurError(),
},
})
);
}
public get index(): number {
return this._index;
Expand Down
36 changes: 29 additions & 7 deletions src/webview/nodeList.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
import EventList, { ListAction } from "./eventList.js";
// import Message from "../common/message.js";
import { Node } from "../common/node.js";
import { Node as MyNode } from "../common/node.js";
import { HasMarginOfError, Position } from "../common/coordinates";

export default class NodeList extends EventList<Node> {
private startList: Node[];
public constructor(arr: Node[] = []) {
export default class NodeList extends EventList<MyNode> {
private startList: MyNode[];
public constructor(arr: MyNode[] = []) {
super(arr);
this.startList = structuredClone(arr);
}

public toJSON(): Node[] {
public toJSON(): MyNode[] {
// console.log(this)

return super.get({ all: true });
return super.get({ all: true }).map((node: MyNode) => {
return {
position: Object.fromEntries(
Object.entries(node.position).sort(([k1], [k2]) => {
function getVal(key: string): number {
switch (key as "x" | "y" | "heading" | "marginOfError") {
case "x":
return 4;
case "y":
return 3;
case "heading":
return 2;
case "marginOfError":
return 1;
}
}
return getVal(k2) - getVal(k1);
})
) as Position & HasMarginOfError,
actions: node.actions,
};
});
}

public update(content?: Node[], edits?: ListAction<Node>[]) {
public update(content?: MyNode[], edits?: ListAction<MyNode>[]) {
// console.log("edits", edits, "arr", this.startList);
if (content) {
this.setList(content);
Expand Down

0 comments on commit dec4eb5

Please sign in to comment.