@occultus/task-api 0.22.0 → 0.23.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/api/Task.ts +17 -16
- package/src/api/TaskCenter.ts +14 -7
- package/src/api/TaskGroup.ts +40 -31
- package/tsconfig.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@occultus/task-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0-alpha",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"author": "CTN Studios",
|
|
25
25
|
"type": "module",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@occultus/toolkit": "0.23.2",
|
|
28
27
|
"@occultus/format-api": "0.21.0",
|
|
29
|
-
"@occultus/
|
|
28
|
+
"@occultus/toolkit": "0.23.5",
|
|
29
|
+
"@occultus/condition-api": "0.22.1",
|
|
30
30
|
"@occultus/text-api": "0.23.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@minecraft/server": "^2.4.0",
|
|
34
34
|
"@minecraft/server-ui": "^2.0.0",
|
|
35
|
-
"@occultus/core": "
|
|
35
|
+
"@occultus/core": "1.1.0-rc.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"typedoc": "^0.28.16"
|
package/src/api/Task.ts
CHANGED
|
@@ -8,8 +8,9 @@ import { ActionFormData } from "@minecraft/server-ui";
|
|
|
8
8
|
import { TaskUtils } from "../utils/TaskUtils";
|
|
9
9
|
import { LockedScreen } from "../ui/LockedScreen";
|
|
10
10
|
import { TaskServer } from "./TaskServer";
|
|
11
|
+
import { FormLike } from "@occultus/core";
|
|
11
12
|
|
|
12
|
-
export class Task {
|
|
13
|
+
export class Task extends FormLike {
|
|
13
14
|
/**
|
|
14
15
|
* @param id 任务的唯一标识符
|
|
15
16
|
* @param name 任务名称
|
|
@@ -21,13 +22,15 @@ export class Task {
|
|
|
21
22
|
public name: TextProvider,
|
|
22
23
|
public description: TextProvider,
|
|
23
24
|
public options: TaskOptions
|
|
24
|
-
) {
|
|
25
|
+
) {
|
|
26
|
+
super();
|
|
27
|
+
}
|
|
25
28
|
/**
|
|
26
29
|
* 向玩家展示任务
|
|
27
30
|
* @param player 要展示任务的玩家
|
|
28
31
|
* @param backTo 关闭任务 UI 后返回的界面
|
|
29
32
|
*/
|
|
30
|
-
display(player: Player, backTo
|
|
33
|
+
display(player: Player, backTo: FormLike[]) {
|
|
31
34
|
if (this.getStatus(player) === TaskStatus.Locked) {
|
|
32
35
|
this.lockedDisplay(player, backTo);
|
|
33
36
|
return;
|
|
@@ -45,17 +48,16 @@ export class Task {
|
|
|
45
48
|
}
|
|
46
49
|
form.show(player).then((result) => {
|
|
47
50
|
if (result.selection === 1) {
|
|
48
|
-
if (this.getStatus(player) === TaskStatus.Done)
|
|
51
|
+
if (this.getStatus(player) === TaskStatus.Done)
|
|
52
|
+
return this.quit(player, backTo);
|
|
49
53
|
if (this.checkConditions(player)) {
|
|
50
54
|
this.complete(player);
|
|
51
|
-
return;
|
|
55
|
+
return this.quit(player, backTo);
|
|
52
56
|
}
|
|
53
57
|
player.sendMessage(TaskUtils.generateFailMessage(this, player));
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (backTo) {
|
|
57
|
-
backTo.display(player);
|
|
58
|
+
return this.quit(player, backTo);
|
|
58
59
|
}
|
|
60
|
+
this.quit(player, backTo);
|
|
59
61
|
});
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
@@ -75,17 +77,16 @@ export class Task {
|
|
|
75
77
|
return true;
|
|
76
78
|
return false;
|
|
77
79
|
}
|
|
78
|
-
protected lockedDisplay(
|
|
79
|
-
player: Player,
|
|
80
|
-
backTo?: Task | TaskCenter | TaskGroup
|
|
81
|
-
) {
|
|
80
|
+
protected lockedDisplay(player: Player, backTo: FormLike[]) {
|
|
82
81
|
const screen = LockedScreen.create(this, player);
|
|
83
82
|
screen.show(player).then((response) => {
|
|
84
|
-
if (this.options.previousTask === "none")
|
|
83
|
+
if (this.options.previousTask === "none")
|
|
84
|
+
return this.quit(player, backTo);
|
|
85
85
|
if (response.selection === 1) {
|
|
86
|
-
this.options.previousTask
|
|
86
|
+
const previous = this.options.previousTask;
|
|
87
|
+
this.jumpTo(player, previous, backTo);
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
+
this.quit(player, backTo);
|
|
89
90
|
});
|
|
90
91
|
}
|
|
91
92
|
/**
|
package/src/api/TaskCenter.ts
CHANGED
|
@@ -3,28 +3,35 @@ import { TextProvider } from "@occultus/text-api";
|
|
|
3
3
|
import { TaskCenterOptions } from "../interface/TaskCenterOptions";
|
|
4
4
|
import { TaskListScreen } from "../ui/TaskListScreen";
|
|
5
5
|
import { TaskUtils } from "../utils/TaskUtils";
|
|
6
|
+
import { FormLike } from "@occultus/core";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* 表示任务中心的类,即所谓「任务书/任务面板」
|
|
9
10
|
*/
|
|
10
|
-
export class TaskCenter {
|
|
11
|
+
export class TaskCenter extends FormLike {
|
|
11
12
|
constructor(
|
|
12
13
|
readonly id: string,
|
|
13
14
|
public name: TextProvider,
|
|
14
15
|
public description: TextProvider,
|
|
15
16
|
public options: TaskCenterOptions
|
|
16
|
-
) {
|
|
17
|
+
) {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
17
20
|
/**
|
|
18
21
|
* 向玩家展示任务中心
|
|
19
22
|
* @param player 要展示的玩家
|
|
20
23
|
*/
|
|
21
|
-
display(player: Player) {
|
|
24
|
+
display(player: Player, backTo: FormLike[]) {
|
|
22
25
|
const { screen, tasks } = TaskListScreen.create(this, player);
|
|
23
26
|
screen.show(player).then((response) => {
|
|
24
|
-
if (response.canceled) return;
|
|
25
|
-
if (response.selection === undefined) return;
|
|
26
|
-
tasks[response.selection]
|
|
27
|
-
|
|
27
|
+
if (response.canceled) return this.quit(player, backTo);
|
|
28
|
+
if (response.selection === undefined) return this.quit(player, backTo);
|
|
29
|
+
this.jumpTo(player, tasks[response.selection], backTo);
|
|
30
|
+
return this.quit(player, backTo);
|
|
31
|
+
}).catch(err=>{
|
|
32
|
+
console.error(err);
|
|
33
|
+
this.quit(player, backTo);
|
|
34
|
+
})
|
|
28
35
|
}
|
|
29
36
|
addTrigger(itemComponent?: string, command?: CustomCommand) {
|
|
30
37
|
if (itemComponent) TaskUtils.registryComponent(itemComponent, this);
|
package/src/api/TaskGroup.ts
CHANGED
|
@@ -6,42 +6,52 @@ import { Task } from "./Task";
|
|
|
6
6
|
import { TaskCenter } from "./TaskCenter";
|
|
7
7
|
import { LockedScreen } from "../ui/LockedScreen";
|
|
8
8
|
import { TaskListScreen } from "../ui/TaskListScreen";
|
|
9
|
+
import { FormLike } from "@occultus/core";
|
|
9
10
|
|
|
10
|
-
export class TaskGroup {
|
|
11
|
+
export class TaskGroup extends FormLike {
|
|
11
12
|
constructor(
|
|
12
13
|
readonly id: string,
|
|
13
14
|
public name: TextProvider,
|
|
14
15
|
public description: TextProvider,
|
|
15
16
|
public options: TaskGroupOptions
|
|
16
|
-
) {
|
|
17
|
-
|
|
17
|
+
) {
|
|
18
|
+
super();
|
|
19
|
+
}
|
|
20
|
+
display(player: Player, backTo: FormLike[]) {
|
|
18
21
|
if (this.getStatus(player) === TaskStatus.Locked) {
|
|
19
|
-
this.lockedDisplay(player);
|
|
22
|
+
this.lockedDisplay(player, backTo);
|
|
20
23
|
return;
|
|
21
24
|
}
|
|
22
25
|
const { screen, tasks } = TaskListScreen.create(this, player);
|
|
23
|
-
screen
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return backTo?.display(player);
|
|
29
|
-
}
|
|
30
|
-
if (response.selection === 0) {
|
|
31
|
-
if (this.hasOwnedAward(player)) {
|
|
32
|
-
// 你已经领取过该奖励!
|
|
33
|
-
player.onScreenDisplay.setActionBar({
|
|
34
|
-
translate: "ui.taskGroup.award.owned"
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
26
|
+
screen
|
|
27
|
+
.show(player)
|
|
28
|
+
.then((response) => {
|
|
29
|
+
if (response.canceled) {
|
|
30
|
+
return this.quit(player, backTo);
|
|
37
31
|
}
|
|
38
|
-
if (
|
|
39
|
-
this.
|
|
32
|
+
if (response.selection === undefined) {
|
|
33
|
+
return this.quit(player, backTo);
|
|
40
34
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
if (response.selection === 0) {
|
|
36
|
+
if (this.hasOwnedAward(player)) {
|
|
37
|
+
// 你已经领取过该奖励!
|
|
38
|
+
player.onScreenDisplay.setActionBar({
|
|
39
|
+
translate: "ui.taskGroup.award.owned"
|
|
40
|
+
});
|
|
41
|
+
return this.quit(player, backTo);
|
|
42
|
+
}
|
|
43
|
+
if (this.getStatus(player) === TaskStatus.Done) {
|
|
44
|
+
this.giveAward(player);
|
|
45
|
+
}
|
|
46
|
+
return this.quit(player, backTo);
|
|
47
|
+
}
|
|
48
|
+
const selected = tasks[response.selection - 1];
|
|
49
|
+
this.jumpTo(player, selected, backTo);
|
|
50
|
+
})
|
|
51
|
+
.catch((err) => {
|
|
52
|
+
console.log(err);
|
|
53
|
+
this.quit(player, backTo);
|
|
54
|
+
});
|
|
45
55
|
}
|
|
46
56
|
isVisible(player: Player): boolean {
|
|
47
57
|
if (this.isAvailable(player)) return true;
|
|
@@ -74,17 +84,16 @@ export class TaskGroup {
|
|
|
74
84
|
ownAward(player: Player) {
|
|
75
85
|
player.addTag(`taskGroup.${this.id}.award`);
|
|
76
86
|
}
|
|
77
|
-
protected lockedDisplay(
|
|
78
|
-
player: Player,
|
|
79
|
-
backTo?: Task | TaskCenter | TaskGroup
|
|
80
|
-
) {
|
|
87
|
+
protected lockedDisplay(player: Player, backTo: FormLike[]) {
|
|
81
88
|
const screen = LockedScreen.create(this, player);
|
|
82
89
|
screen.show(player).then((response) => {
|
|
83
|
-
if (this.options.previousTask === "none")
|
|
90
|
+
if (this.options.previousTask === "none")
|
|
91
|
+
return this.quit(player, backTo);
|
|
84
92
|
if (response.selection === 1) {
|
|
85
|
-
this.options.previousTask
|
|
93
|
+
const previous = this.options.previousTask;
|
|
94
|
+
this.jumpTo(player, previous, backTo);
|
|
86
95
|
}
|
|
87
|
-
|
|
96
|
+
this.quit(player, backTo);
|
|
88
97
|
});
|
|
89
98
|
}
|
|
90
99
|
protected giveAward(player: Player) {
|