Skip to content

Commit 877e795

Browse files
committed
copy to/from project
1 parent 9d4510d commit 877e795

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
lines changed

TODO

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ definition([
1919
many(art()),
2020
])
2121

22+
// fix file references when copying
2223
// art ffset save message / input size
2324
// autozoom based on sprite size for sprites tab
2425

@@ -72,12 +73,8 @@ copy / paste mappings
7273
time travel for undo/redo
7374
import palette from spritesheet https://yarnpkg.com/en/package/node-vibrant
7475
==
75-
use a repo url
76-
change sprite scroll speed
7776
drawing mode fill !
7877
S - scroll to sprite
79-
s3k sonic mapping definition / conversion tools
80-
create new file | newFactory={(path)=>{}}
8178
04:43:53 <%Lil-G> i mean so when you do "delete unused tiles" it doesn't delete the tiles the other object uses
8279
backdrop-filter
8380
Support MainMemory's macros formats

app/components/file/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { observer } from 'mobx-react';
33
import { FileObject } from './file-object';
44
import { workspace } from '#store/workspace';
55
import { Button } from '#ui';
6-
import { selectTab } from '#components/layout/model';
76

87
export const File = observer(() => {
98
return (
@@ -14,10 +13,7 @@ export const File = observer(() => {
1413
<Button
1514
color="blue"
1615
large
17-
onClick={() => {
18-
workspace.project.copyFrom(workspace.file);
19-
selectTab('Project');
20-
}}
16+
onClick={workspace.fileToProject}
2117
>
2218
copy to project
2319
</Button>

app/components/project/object-menu.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { remote } from 'electron';
22
import { toJS } from 'mobx';
33
import { uuid } from '#util/uuid';
4-
import { selectTab } from '#components/layout/model';
54
import { workspace } from '#store/workspace';
65
const { getCurrentWindow, Menu, MenuItem } = remote;
76

@@ -16,10 +15,7 @@ export default function(node) {
1615
if (!node.isDirectory) {
1716
menu.append(new MenuItem({
1817
label: 'copy to file menu',
19-
click: () => {
20-
Object.assign(workspace.file, toJS(node.ref));
21-
selectTab('File');
22-
},
18+
click: () => workspace.projectToFile(node.ref),
2319
}));
2420
}
2521
menu.append(new MenuItem({

app/store/objectdef.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,16 @@ export class ObjectDef {
2323
// turned into generic observables in project menu
2424
// dont add methods and shit because they wont work
2525
}
26+
27+
export function editPaths(obj, lambda) {
28+
for (name in obj) {
29+
if (name === 'path') {
30+
obj[name] = lambda(obj[name]);
31+
} else {
32+
const item = obj[name];
33+
if (typeof item === 'object' && item !== null) {
34+
editPaths(item, lambda);
35+
}
36+
}
37+
}
38+
}

app/store/project.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,4 @@ export class Project {
8989
obj.uuid = uuid();
9090
this.objects.unshift(obj);
9191
};
92-
93-
@action copyFrom = (obj) => {
94-
const clone = toJS(obj);
95-
clone.name = 'file object';
96-
clone.uuid = uuid();
97-
this.node = clone.uuid;
98-
this.objects.unshift(clone);
99-
};
10092
}

app/store/workspace.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { observable, computed, action, autorun } from 'mobx';
1+
import { observable, toJS, action } from 'mobx';
22
import { storage } from './storage';
33
import { Project } from './project';
4-
import { ObjectDef } from './objectdef';
4+
import { ObjectDef, editPaths } from './objectdef';
5+
import { uuid } from '#util/uuid';
6+
import { selectTab } from '#components/layout/model';
57
import path from 'path';
68

79
const fileState = new ObjectDef();
@@ -33,6 +35,25 @@ class Workspace {
3335
@action absolutePath = (filepath) => {
3436
return path.resolve(path.dirname(this.projectPath), filepath);
3537
};
38+
39+
@action fileToProject = () => {
40+
if (this.project) {
41+
const clone = toJS(this.file);
42+
editPaths(clone, this.relativePath);
43+
clone.name = 'file object';
44+
clone.uuid = uuid();
45+
this.project.node = clone.uuid;
46+
this.project.objects.unshift(clone);
47+
selectTab('Project');
48+
}
49+
};
50+
51+
@action projectToFile = (node) => {
52+
const clone = toJS(node);
53+
editPaths(clone, this.absolutePath);
54+
Object.assign(this.file, clone);
55+
selectTab('File');
56+
};
3657
}
3758

3859
const workspace = new Workspace();

0 commit comments

Comments
 (0)