Add task moving
This commit is contained in:
parent
eadd68f708
commit
a0cd916528
@ -21,6 +21,8 @@ export enum Actions {
|
|||||||
SaveVillageSettings = 'save_village_settings',
|
SaveVillageSettings = 'save_village_settings',
|
||||||
ToggleVillageReceiveMode = 'toggle_village_receive_mode',
|
ToggleVillageReceiveMode = 'toggle_village_receive_mode',
|
||||||
RemoveVillageTask = 'remove_village_task',
|
RemoveVillageTask = 'remove_village_task',
|
||||||
|
UpVillageTask = 'up_village_task',
|
||||||
|
DownVillageTask = 'down_village_task',
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createStore(villageFactory: VillageFactory) {
|
export function createStore(villageFactory: VillageFactory) {
|
||||||
@ -108,6 +110,14 @@ export function createStore(villageFactory: VillageFactory) {
|
|||||||
const controller = villageFactory.createController(villageId);
|
const controller = villageFactory.createController(villageId);
|
||||||
controller.removeTask(taskId);
|
controller.removeTask(taskId);
|
||||||
},
|
},
|
||||||
|
[Actions.UpVillageTask]({}, { villageId, taskId }) {
|
||||||
|
const controller = villageFactory.createController(villageId);
|
||||||
|
controller.upTask(taskId);
|
||||||
|
},
|
||||||
|
[Actions.DownVillageTask]({}, { villageId, taskId }) {
|
||||||
|
const controller = villageFactory.createController(villageId);
|
||||||
|
controller.downTask(taskId);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -26,8 +26,12 @@ export default {
|
|||||||
props: ['villageId', 'tasks'],
|
props: ['villageId', 'tasks'],
|
||||||
computed: {},
|
computed: {},
|
||||||
methods: {
|
methods: {
|
||||||
upTask(taskId) {},
|
upTask(taskId) {
|
||||||
downTask(taskId) {},
|
this.$store.dispatch(Actions.UpVillageTask, { villageId: this.villageId, taskId });
|
||||||
|
},
|
||||||
|
downTask(taskId) {
|
||||||
|
this.$store.dispatch(Actions.DownVillageTask, { villageId: this.villageId, taskId });
|
||||||
|
},
|
||||||
removeTask(taskId) {
|
removeTask(taskId) {
|
||||||
this.$store.dispatch(Actions.RemoveVillageTask, { villageId: this.villageId, taskId });
|
this.$store.dispatch(Actions.RemoveVillageTask, { villageId: this.villageId, taskId });
|
||||||
},
|
},
|
||||||
|
@ -45,6 +45,14 @@ export class VillageController {
|
|||||||
this.taskCollection.removeTask(taskId);
|
this.taskCollection.removeTask(taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upTask(taskId: TaskId) {
|
||||||
|
this.taskCollection.upTask(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
downTask(taskId: TaskId) {
|
||||||
|
this.taskCollection.downTask(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
postponeTask(taskId: TaskId, seconds: number) {
|
postponeTask(taskId: TaskId, seconds: number) {
|
||||||
this.taskCollection.postponeTask(taskId, seconds);
|
this.taskCollection.postponeTask(taskId, seconds);
|
||||||
}
|
}
|
||||||
|
@ -206,10 +206,7 @@ function getReadyForProductionTask(
|
|||||||
queues: VillageProductionQueueStateDict,
|
queues: VillageProductionQueueStateDict,
|
||||||
maxResourcesForTask: Resources
|
maxResourcesForTask: Resources
|
||||||
): Task | undefined {
|
): Task | undefined {
|
||||||
const nowTs = timestamp();
|
const firstReadyGroup = Object.values(queues).find(group => group.isWaiting);
|
||||||
const firstReadyGroup = Object.values(queues).find(
|
|
||||||
group => group.currentTaskFinishTimestamp <= nowTs && group.tasks.length !== 0
|
|
||||||
);
|
|
||||||
if (!firstReadyGroup) {
|
if (!firstReadyGroup) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,28 @@ export class VillageTaskCollection {
|
|||||||
this.removeTasks(t => t.id === taskId);
|
this.removeTasks(t => t.id === taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upTask(taskId: TaskId): void {
|
||||||
|
const tasks = this.storage.getTasks();
|
||||||
|
const index = tasks.findIndex(t => t.id === taskId);
|
||||||
|
if (index < 0 || index === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const movedTask = tasks.splice(index, 1)[0];
|
||||||
|
tasks.splice(index - 1, 0, movedTask);
|
||||||
|
this.storage.storeTaskList(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
downTask(taskId: TaskId) {
|
||||||
|
const tasks = this.storage.getTasks();
|
||||||
|
const index = tasks.findIndex(t => t.id === taskId);
|
||||||
|
if (index < 0 || index === tasks.length - 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const movedTask = tasks.splice(index, 1)[0];
|
||||||
|
tasks.splice(index + 1, 0, movedTask);
|
||||||
|
this.storage.storeTaskList(tasks);
|
||||||
|
}
|
||||||
|
|
||||||
postponeTask(taskId: TaskId, seconds: number) {
|
postponeTask(taskId: TaskId, seconds: number) {
|
||||||
const modifyTime = withTime(timestamp() + seconds);
|
const modifyTime = withTime(timestamp() + seconds);
|
||||||
this.modifyTasks(task => task.id === taskId, modifyTime);
|
this.modifyTasks(task => task.id === taskId, modifyTime);
|
||||||
|
Loading…
Reference in New Issue
Block a user