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

Осипова Елизавета #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 225 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const Card = function () {
taskQueue.continueWith(continuation);
};


// Изменяет урон, наносимый картой при атаке карт противника.
// Можно переопределить в наследниках.
// Позволяет определять способности, которые меняют наносимый урон при атаке карт противника.
Expand Down
63 changes: 29 additions & 34 deletions src/TaskQueue.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
const TaskQueue = function() {
function TaskQueue() {
function runNextTask(taskQueue) {
if (taskQueue.running || taskQueue.tasks.length === 0) {
return;
}
taskQueue.running = true;
const task = taskQueue.tasks.shift();

if (task.runAndContinue) {
setTimeout(() => {
task.runAndContinue(() => {
task.dispose && task.dispose();
taskQueue.running = false;

setTimeout(() => {
runNextTask(taskQueue);
});
});
}, 0);
} else {
runNextTask(taskQueue);
}
}

export default class TaskQueue {
constructor() {
this.tasks = [];
this.running = false;
}

TaskQueue.prototype.push = function(run, dispose, duration) {
push(run, dispose, duration) {
if (duration === undefined || duration === null) {
this.tasks.push({runAndContinue: run, dispose});
} else {
Expand All @@ -19,37 +42,9 @@ const TaskQueue = function() {
});
}
runNextTask(this);
};
}

TaskQueue.prototype.continueWith = function(action) {
continueWith(action) {
this.push(action, null, 0);
};

function runNextTask(taskQueue) {
if (taskQueue.running || taskQueue.tasks.length === 0) {
return;
}
taskQueue.running = true;
const task = taskQueue.tasks.shift();

if (task.runAndContinue) {
setTimeout(() => {
task.runAndContinue(() => {
task.dispose && task.dispose();
taskQueue.running = false;

setTimeout(() => {
runNextTask(taskQueue);
});
});
}, 0);
}
else {
runNextTask(taskQueue);
}
}

return TaskQueue;
}();

export default TaskQueue;
}
Binary file added src/images/brewer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/doggo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/duck.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/lads.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/noname.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/pseudo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/ratata.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/rogue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/trasher.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading