Skip to content

Commit

Permalink
Fix sharing links
Browse files Browse the repository at this point in the history
  • Loading branch information
lewish committed Feb 21, 2024
1 parent fcf3598 commit 8556a26
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
58 changes: 29 additions & 29 deletions client/store/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,41 @@ import { RenderLayer } from "#asciiflow/client/render_layer";
* and provides methods to modify the current state.
*/
export class CanvasStore {
public readonly drawingId: DrawingId = DrawingId.local("");
constructor(drawingId: DrawingId) {
this.drawingId = drawingId;
public readonly persistentCommitted: Persistent<Layer>;
public readonly undoLayers: Persistent<Layer[]>;
public readonly redoLayers: Persistent<Layer[]>;
private _zoom: Persistent<number>;
private _offset: Persistent<IVector>;

constructor(public readonly drawingId: DrawingId) {
this.persistentCommitted = Persistent.custom(
this.persistentKey("committed-layer"),
this.drawingId.shareSpec
? new DrawingStringifier().deserialize(this.drawingId.shareSpec).layer
: new Layer(),
Layer
);
this.undoLayers = Persistent.custom(
this.persistentKey("undo-layers"),
[],
new ArrayStringifier(Layer)
);
this.redoLayers = Persistent.custom(
this.persistentKey("redo-layers"),
[],
new ArrayStringifier(Layer)
);
this._zoom = Persistent.json(this.persistentKey("zoom"), 1);
this._offset = Persistent.json<IVector>(this.persistentKey("offset"), {
x: (constants.MAX_GRID_WIDTH * constants.CHAR_PIXELS_H) / 2,
y: (constants.MAX_GRID_HEIGHT * constants.CHAR_PIXELS_V) / 2,
})
}

public persistentKey(...values: string[]) {
return Persistent.key("drawing", this.drawingId.persistentKey, ...values);
}

private _zoom = Persistent.json(this.persistentKey("zoom"), 1);

public get zoom() {
return this._zoom.get();
}
Expand All @@ -34,11 +58,6 @@ export class CanvasStore {
this._zoom.set(value);
}

private _offset = Persistent.json<IVector>(this.persistentKey("offset"), {
x: (constants.MAX_GRID_WIDTH * constants.CHAR_PIXELS_H) / 2,
y: (constants.MAX_GRID_HEIGHT * constants.CHAR_PIXELS_V) / 2,
});

public get offset() {
return new Vector(this._offset.get().x, this._offset.get().y);
}
Expand All @@ -50,13 +69,6 @@ export class CanvasStore {
});
}

@observable accessor persistentCommitted = Persistent.custom(
this.persistentKey("committed-layer"),
this.drawingId.shareSpec
? new DrawingStringifier().deserialize(this.drawingId.shareSpec).layer
: new Layer(),
Layer
);
@observable accessor scratch = new Layer();

@observable accessor selection: Box;
Expand All @@ -80,18 +92,6 @@ export class CanvasStore {
});
}

@observable accessor undoLayers = Persistent.custom(
this.persistentKey("undo-layers"),
[],
new ArrayStringifier(Layer)
);

@observable accessor redoLayers = Persistent.custom(
this.persistentKey("redo-layers"),
[],
new ArrayStringifier(Layer)
);

@action.bound setSelection(box: Box) {
this.selection = box;
}
Expand Down
10 changes: 6 additions & 4 deletions client/text_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export function layerToText(layer: ILayerView, box?: Box) {
.forEach(([key, value]) => {
lineArrays[key.y - box.topLeft().y][key.x - box.topLeft().x] = value;
});
return lineArrays
.map((lineValues) => lineValues.reduce((acc, curr) => acc + curr, ""))
.map((line) => line.replace(/\s+$/, ""))
.join("\n");
return (
lineArrays
.map((lineValues) => lineValues.reduce((acc, curr) => acc + curr, ""))
.map((line) => line.replace(/\s+$/, ""))
.join("\n")
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"sourceMap": true,
"skipLibCheck": true,
"jsx": "react",
"lib": ["es2017", "dom"],
"lib": ["es2021", "dom"],
"esModuleInterop": true,
"declaration": true,
"strictPropertyInitialization": false
Expand Down

0 comments on commit 8556a26

Please sign in to comment.