Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature: add duplicate item #49

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nomorepanic
Copy link

Hello, I added a duplicate item button.

However, I can't find my way around generating a new item. How I am supposed to generate a new id for it?

@markmanx
Copy link
Owner

Hi @nomorepanic . Thanks for looking into this. At the moment you have to do two things to duplicate an item: 1) create a new modelItem and 2) create a new viewItem that references the modelItem. Concept-wise, this is not a great part of the codebase atm because it's a 1:1 relationship.

The idea was to eventually have 1:many relationship, where a modelItem would be a node template, and you could instantiate the template multiple times. This will be coming soon hopefully, so heads up, this will make the action of duplicating work very differently. It will work more like creating linked instances of the template (i.e. update one, update them all). In any case your code could still be useful if someone wanted an actual duplicate action.

See the following relevant snippet for how to place an icon.

mouseup: ({ uiState, scene }) => {
if (uiState.mode.type !== 'PLACE_ICON') return;
if (uiState.mode.id !== null) {
const modelItemId = generateId();
scene.createModelItem({
id: modelItemId,
name: 'Untitled',
icon: uiState.mode.id
});
scene.createViewItem({
...VIEW_ITEM_DEFAULTS,
id: modelItemId,
tile: uiState.mouse.position.tile
});
}
uiState.actions.setMode(
produce(uiState.mode, (draft) => {
draft.id = null;
})
);
}

@nomorepanic nomorepanic force-pushed the feature/duplicate-item branch from 9005631 to 6bd40f0 Compare October 3, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants