feat: add new functions
This commit is contained in:
@@ -113,4 +113,48 @@ function shuffleCore(region: Region, rng: RNG){
|
||||
draft.position = posI;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function moveToRegion(part: Entity<Part>, targetRegion: Entity<Region>, position?: number[]) {
|
||||
const sourceRegion = part.value.region;
|
||||
batch(() => {
|
||||
sourceRegion.produce(draft => {
|
||||
draft.children = draft.children.filter(c => c.id !== part.id);
|
||||
});
|
||||
targetRegion.produce(draft => {
|
||||
draft.children.push(part);
|
||||
});
|
||||
part.produce(draft => {
|
||||
draft.region = targetRegion;
|
||||
if (position) draft.position = position;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function moveToRegionAll(parts: Entity<Part>[], targetRegion: Entity<Region>, positions?: number[][]) {
|
||||
batch(() => {
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const part = parts[i];
|
||||
const sourceRegion = part.value.region;
|
||||
sourceRegion.produce(draft => {
|
||||
draft.children = draft.children.filter(c => c.id !== part.id);
|
||||
});
|
||||
targetRegion.produce(draft => {
|
||||
draft.children.push(part);
|
||||
});
|
||||
part.produce(draft => {
|
||||
draft.region = targetRegion;
|
||||
if (positions && positions[i]) draft.position = positions[i];
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function removeFromRegion(part: Entity<Part>) {
|
||||
const region = part.value.region;
|
||||
batch(() => {
|
||||
region.produce(draft => {
|
||||
draft.children = draft.children.filter(c => c.id !== part.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ export type { Part } from './core/part';
|
||||
export { flip, flipTo, roll } from './core/part';
|
||||
|
||||
export type { Region, RegionAxis } from './core/region';
|
||||
export { applyAlign, shuffle, RegionEntity } from './core/region';
|
||||
export { applyAlign, shuffle, RegionEntity, moveToRegion, moveToRegionAll, removeFromRegion } from './core/region';
|
||||
|
||||
// Utils
|
||||
export type { Command, CommandSchema, CommandParamSchema, CommandOptionSchema, CommandFlagSchema } from './utils/command';
|
||||
|
||||
Reference in New Issue
Block a user