@kradle/challenges 0.0.1
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/README.md +1 -0
- package/biome.json +39 -0
- package/dist/actions.d.ts +203 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +287 -0
- package/dist/actions.js.map +1 -0
- package/dist/api_utils.d.ts +5 -0
- package/dist/api_utils.d.ts.map +1 -0
- package/dist/api_utils.js +13 -0
- package/dist/api_utils.js.map +1 -0
- package/dist/challenge.d.ts +56 -0
- package/dist/challenge.d.ts.map +1 -0
- package/dist/challenge.js +462 -0
- package/dist/challenge.js.map +1 -0
- package/dist/commands.d.ts +38 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +135 -0
- package/dist/commands.js.map +1 -0
- package/dist/constants.d.ts +70 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +112 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/testmode.d.ts +3 -0
- package/dist/testmode.d.ts.map +1 -0
- package/dist/testmode.js +19 -0
- package/dist/testmode.js.map +1 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +22 -0
- package/dist/utils.js.map +1 -0
- package/package.json +27 -0
- package/src/actions.ts +388 -0
- package/src/api_utils.ts +10 -0
- package/src/challenge.ts +553 -0
- package/src/commands.ts +141 -0
- package/src/constants.ts +121 -0
- package/src/index.ts +4 -0
- package/src/testmode.ts +18 -0
- package/src/types.ts +136 -0
- package/src/utils.ts +22 -0
- package/tsconfig.json +38 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ChallengeBase = exports.DEFAULT_CHALLENGE_PATH = void 0;
|
|
37
|
+
exports.createChallenge = createChallenge;
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const sandstone_1 = require("sandstone");
|
|
40
|
+
const actions_1 = require("./actions");
|
|
41
|
+
const commands_1 = require("./commands");
|
|
42
|
+
const constants_1 = require("./constants");
|
|
43
|
+
const testmode_1 = require("./testmode");
|
|
44
|
+
const types_1 = require("./types");
|
|
45
|
+
const utils_1 = require("./utils");
|
|
46
|
+
exports.DEFAULT_CHALLENGE_PATH = "kradle-studio/challenges";
|
|
47
|
+
const PREVIOUS_VALUE_PREFIX = "_prev_";
|
|
48
|
+
const PREVIOUS_VALUES_GLOBAL_OBJECTIVE_NAME = "prev_glob_values";
|
|
49
|
+
const EVENT_FIRES_COUNTER_PREFIX = "_count_";
|
|
50
|
+
const EVENT_FIRES_GLOBAL_COUNTER_OBJECTIVE_NAME = "fired_ev_counter";
|
|
51
|
+
let uniqueObjectiveCounter = 0;
|
|
52
|
+
/**
|
|
53
|
+
* Adds a suffix to the objective name while ensuring it fits within the 16 character limit.
|
|
54
|
+
*/
|
|
55
|
+
function addSuffixToObjectiveName(name, suffix) {
|
|
56
|
+
const trimmedName = name.slice(0, 16 - suffix.length);
|
|
57
|
+
return `${trimmedName}${suffix}`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Makes sure the objective name is unique by appending a counter to it.
|
|
61
|
+
* This is necessary because Minecraft requires objective names to be unique,
|
|
62
|
+
* as well as to fit within the 16 character limit.
|
|
63
|
+
*
|
|
64
|
+
* This is meant to be used for mass-generated objectives (previous values, counter of fired events...)
|
|
65
|
+
*/
|
|
66
|
+
function getUniqueObjectiveName(name) {
|
|
67
|
+
uniqueObjectiveCounter++;
|
|
68
|
+
return addSuffixToObjectiveName(name, uniqueObjectiveCounter.toString());
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns an Objective instance for the given name and type.
|
|
72
|
+
* If the objective already exists, it returns the existing one.
|
|
73
|
+
* This is useful to avoid creating multiple objectives with the same name.
|
|
74
|
+
*/
|
|
75
|
+
function getOrCreateObjective(name, type) {
|
|
76
|
+
try {
|
|
77
|
+
return sandstone_1.Objective.create(name, type);
|
|
78
|
+
}
|
|
79
|
+
catch (_) {
|
|
80
|
+
return sandstone_1.Objective.get(name);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function isScoreCustomEvent(event) {
|
|
84
|
+
return "score" in event;
|
|
85
|
+
}
|
|
86
|
+
function isAdvancementCustomEvent(event) {
|
|
87
|
+
return "criteria" in event;
|
|
88
|
+
}
|
|
89
|
+
class ChallengeBase {
|
|
90
|
+
game_duration;
|
|
91
|
+
roles;
|
|
92
|
+
full_variables;
|
|
93
|
+
variablesPreviousValues;
|
|
94
|
+
_events = {};
|
|
95
|
+
/* The custom score events provided by the user, still in input type */
|
|
96
|
+
_userInputCustomEvents = [];
|
|
97
|
+
_end_condition;
|
|
98
|
+
_win_conditions;
|
|
99
|
+
name;
|
|
100
|
+
kradle_challenge_path;
|
|
101
|
+
constructor(config) {
|
|
102
|
+
this.name = config.name;
|
|
103
|
+
this.kradle_challenge_path = config.kradle_challenge_path;
|
|
104
|
+
this.game_duration = config.GAME_DURATION ?? constants_1.MAX_DURATION;
|
|
105
|
+
if (this.game_duration < 0) {
|
|
106
|
+
throw new Error("Game duration cannot be negative. Please set it to a positive value (lower than 5 minutes).");
|
|
107
|
+
}
|
|
108
|
+
if (this.game_duration > constants_1.MAX_DURATION) {
|
|
109
|
+
throw new Error(`Game duration cannot exceed ${constants_1.MAX_DURATION / 20} seconds.`);
|
|
110
|
+
}
|
|
111
|
+
this.roles = Object.fromEntries(config.roles.map((role) => [role, role]));
|
|
112
|
+
const all_variables = {
|
|
113
|
+
...constants_1.BUILTIN_VARIABLES,
|
|
114
|
+
...config.custom_variables,
|
|
115
|
+
};
|
|
116
|
+
this.full_variables = {
|
|
117
|
+
...Object.fromEntries(Object.entries(all_variables).map(([key, value]) => {
|
|
118
|
+
if ((0, types_1.isSpecificObjectiveVariable)(value)) {
|
|
119
|
+
return [
|
|
120
|
+
key,
|
|
121
|
+
{
|
|
122
|
+
type: value.type,
|
|
123
|
+
score: sandstone_1.Objective.create(key, value.objective_type)("@s"),
|
|
124
|
+
default: value.default,
|
|
125
|
+
updater: value.updater,
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
if (value.type === "global") {
|
|
130
|
+
const objective = value.hidden ? constants_1.HIDDEN_OBJECTIVE : constants_1.VISIBLE_OBJECTIVE;
|
|
131
|
+
return [
|
|
132
|
+
key,
|
|
133
|
+
{
|
|
134
|
+
type: value.type,
|
|
135
|
+
score: objective(key),
|
|
136
|
+
default: value.default,
|
|
137
|
+
updater: value.updater,
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
return [
|
|
142
|
+
key,
|
|
143
|
+
{
|
|
144
|
+
type: value.type,
|
|
145
|
+
score: sandstone_1.Objective.create(key, "dummy")("@s"),
|
|
146
|
+
default: value.default,
|
|
147
|
+
updater: value.updater,
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
})),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
get variables() {
|
|
154
|
+
return Object.fromEntries(Object.entries(this.full_variables).map(([key, value]) => {
|
|
155
|
+
return [key, value.score];
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Build a CustomScoreEvent from an _InputScoreCustomEventType.
|
|
160
|
+
* This will setup the tracking objective.
|
|
161
|
+
*
|
|
162
|
+
* @param event The input event to create the custom event from.
|
|
163
|
+
* @param suffix A suffix that will be added to the variable's debug name, ensuring its uniqueness.
|
|
164
|
+
*/
|
|
165
|
+
buildCustomScoreEvent(event, suffix) {
|
|
166
|
+
// How we store fire counters will depend whether the score is global or individual
|
|
167
|
+
const variableName = this.getVariableName(event.score);
|
|
168
|
+
const variableType = this.getVariableType(event.score);
|
|
169
|
+
const debugName = `${variableName}__${suffix}`;
|
|
170
|
+
if (variableType === "global") {
|
|
171
|
+
// For global scores, we create a single global objective.
|
|
172
|
+
const objective = getOrCreateObjective(EVENT_FIRES_GLOBAL_COUNTER_OBJECTIVE_NAME, "dummy");
|
|
173
|
+
return {
|
|
174
|
+
inputEvent: event,
|
|
175
|
+
counter: objective(debugName),
|
|
176
|
+
type: variableType,
|
|
177
|
+
debugName: debugName,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
// For individual scores, we have to create a dedicated mirror objective
|
|
181
|
+
const objective = getOrCreateObjective(getUniqueObjectiveName(EVENT_FIRES_COUNTER_PREFIX + variableName), "dummy");
|
|
182
|
+
return {
|
|
183
|
+
inputEvent: event,
|
|
184
|
+
counter: objective(event.score.target),
|
|
185
|
+
type: variableType,
|
|
186
|
+
debugName: debugName,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
addVariable(name, variable) {
|
|
190
|
+
// @ts-expect-error
|
|
191
|
+
if (this.full_variables[name]) {
|
|
192
|
+
throw new Error(`Variable with name ${name} already exists.`);
|
|
193
|
+
}
|
|
194
|
+
// @ts-expect-error
|
|
195
|
+
this.full_variables[name] = variable;
|
|
196
|
+
}
|
|
197
|
+
getPreviousValueScore(name) {
|
|
198
|
+
if (!this.variablesPreviousValues) {
|
|
199
|
+
throw new Error("Variables previous values not initialized.");
|
|
200
|
+
}
|
|
201
|
+
return this.variablesPreviousValues[name];
|
|
202
|
+
}
|
|
203
|
+
events(events) {
|
|
204
|
+
this._events = events(this.variables, this.roles);
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Returns the name of the variable based on its score.
|
|
209
|
+
*/
|
|
210
|
+
getVariableName(variable) {
|
|
211
|
+
const variableName = Object.entries(this.full_variables).find(([_name, value]) => value.score === variable);
|
|
212
|
+
if (!variableName) {
|
|
213
|
+
throw new Error(`Variable with score ${variable} not found in variables.`);
|
|
214
|
+
}
|
|
215
|
+
return variableName[0];
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Returns the type of the variable (individual/global) based on its score.
|
|
219
|
+
*/
|
|
220
|
+
getVariableType(score) {
|
|
221
|
+
const variableName = this.getVariableName(score);
|
|
222
|
+
if (!variableName) {
|
|
223
|
+
throw new Error(`Score ${score} not found in variables.`);
|
|
224
|
+
}
|
|
225
|
+
return this.full_variables[variableName].type;
|
|
226
|
+
}
|
|
227
|
+
custom_events(custom_events) {
|
|
228
|
+
const inputCustomEvents = custom_events(this.variables, this.roles);
|
|
229
|
+
// First, we translate advancement-based events directly into dedicated scores, and create the related Advancement
|
|
230
|
+
const advancementsAsScoreCustomEvents = inputCustomEvents
|
|
231
|
+
.filter(isAdvancementCustomEvent)
|
|
232
|
+
.map((event, index) => {
|
|
233
|
+
const trigger = (event.criteria?.[0].trigger ?? "").split("minecraft:").at(-1).replace(/[:/]/g, "_");
|
|
234
|
+
const name = `adv_${trigger}__${index}`;
|
|
235
|
+
const score = getOrCreateObjective(getUniqueObjectiveName(name), "dummy")("@s");
|
|
236
|
+
this.addVariable(name, {
|
|
237
|
+
score: score,
|
|
238
|
+
default: 0,
|
|
239
|
+
type: "individual",
|
|
240
|
+
updater: undefined,
|
|
241
|
+
});
|
|
242
|
+
const setMCFunction = (0, sandstone_1.MCFunction)(`custom_events_advancements/${name}`, () => {
|
|
243
|
+
// Called when the advancement is granted. This sets the score to 1 and revokes the advancement.
|
|
244
|
+
score.set(1);
|
|
245
|
+
advancement.revoke((0, sandstone_1.Selector)("@s"));
|
|
246
|
+
});
|
|
247
|
+
const advancement = (0, sandstone_1.Advancement)(name, {
|
|
248
|
+
criteria: Object.fromEntries(event.criteria.map((criterion, criterionIndex) => [`criterion_${criterionIndex}`, criterion])),
|
|
249
|
+
rewards: {
|
|
250
|
+
function: setMCFunction,
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
return {
|
|
254
|
+
actions: [
|
|
255
|
+
// First action is to reset the score to 0
|
|
256
|
+
actions_1.Actions.set({ variable: score, value: 0 }),
|
|
257
|
+
...event.actions,
|
|
258
|
+
],
|
|
259
|
+
mode: event.mode,
|
|
260
|
+
score: score,
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
this._userInputCustomEvents = [...inputCustomEvents.filter(isScoreCustomEvent), ...advancementsAsScoreCustomEvents];
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
end_condition(condition) {
|
|
267
|
+
this._end_condition = condition?.(this.variables, this.roles);
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
win_conditions(condition) {
|
|
271
|
+
this._win_conditions = condition(this.variables, this.roles);
|
|
272
|
+
this.build();
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Processes a custom score event by checking if the score has reached the target,
|
|
276
|
+
* and if so, executes the actions associated with the event.
|
|
277
|
+
*
|
|
278
|
+
* @param event - The custom event to process.
|
|
279
|
+
* @param mcFunctionReference - Optional reference to the parent MCFunction - used to give better naming to the children functions.
|
|
280
|
+
*/
|
|
281
|
+
processCustomScoreEvent(event) {
|
|
282
|
+
const { score, target, actions, mode } = event.inputEvent;
|
|
283
|
+
const { type, counter, debugName } = event;
|
|
284
|
+
const previousScore = this.getPreviousValueScore(this.getVariableName(score));
|
|
285
|
+
// If no target is specified, we assume the event fires when the score changes from its previous value
|
|
286
|
+
const scoreCondition = target
|
|
287
|
+
? sandstone_1._.and(previousScore.notEqualTo(target), score.equalTo(target))
|
|
288
|
+
: score.notEqualTo(previousScore);
|
|
289
|
+
// If the mode is "fire_once", we also check if the counter is 0.
|
|
290
|
+
const condition = mode === "repeatable" ? scoreCondition : sandstone_1._.and(scoreCondition, counter.equalTo(0));
|
|
291
|
+
if (type === "global") {
|
|
292
|
+
// For global scores, we can directly use the condition
|
|
293
|
+
(0, sandstone_1.comment)(`Processing global custom score event ${debugName}`);
|
|
294
|
+
sandstone_1._.if(condition, () => {
|
|
295
|
+
actions.forEach((action) => action());
|
|
296
|
+
counter.add(1);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
// For individual scores, we need to check each player's score
|
|
301
|
+
(0, sandstone_1.comment)(`Processing individual custom score event ${debugName}`);
|
|
302
|
+
sandstone_1.execute.as(constants_1.ALL).run((0, utils_1.getChildFunctionName)(debugName), () => {
|
|
303
|
+
sandstone_1._.if(condition, () => {
|
|
304
|
+
actions.forEach((action) => action());
|
|
305
|
+
counter.add(1);
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Builds the datapack based on the challenge configuration.
|
|
312
|
+
*/
|
|
313
|
+
build() {
|
|
314
|
+
// Initialize previous values objectives
|
|
315
|
+
// Will store the previous values of all variables
|
|
316
|
+
this.variablesPreviousValues = Object.fromEntries(Object.entries(this.full_variables).map(([name, { type, score }]) => {
|
|
317
|
+
if (type === "global") {
|
|
318
|
+
// For global variables, we create a single global objective to store previous values
|
|
319
|
+
const objective = getOrCreateObjective(PREVIOUS_VALUES_GLOBAL_OBJECTIVE_NAME, "dummy");
|
|
320
|
+
return [name, objective(`${name}__${score.target}`)];
|
|
321
|
+
}
|
|
322
|
+
// For individual variables, we create a dedicated mirror objective
|
|
323
|
+
const objective = sandstone_1.Objective.create(getUniqueObjectiveName(PREVIOUS_VALUE_PREFIX + name), "dummy");
|
|
324
|
+
return [name, objective(score.target)];
|
|
325
|
+
}));
|
|
326
|
+
// "Build" the custom events (initializes the tracking objective)
|
|
327
|
+
const customScoreEvents = [...this._userInputCustomEvents, ...(0, constants_1.BUILTIN_SCORE_EVENTS)(this.variables)].map((event, index) => this.buildCustomScoreEvent(event, index));
|
|
328
|
+
// Initialize the challenge
|
|
329
|
+
(0, sandstone_1.MCFunction)("start_challenge", () => {
|
|
330
|
+
(0, sandstone_1.comment)("1. Setup all the global variables to their default values.");
|
|
331
|
+
(0, sandstone_1.comment)(" This includes the game timer!");
|
|
332
|
+
this.variables.game_timer.set(this.game_duration);
|
|
333
|
+
for (const variable of Object.values(this.full_variables)) {
|
|
334
|
+
if (variable.type === "global" && variable.default !== undefined) {
|
|
335
|
+
variable.score.set(variable.default);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
(0, sandstone_1.tag)(constants_1.ALL).remove(constants_1.WINNER_TAG);
|
|
339
|
+
(0, sandstone_1.comment)("2. Set up test mode if it's enabled - needs to run here so the tester player is tagged");
|
|
340
|
+
if (testmode_1.test_mode_enabled) {
|
|
341
|
+
(0, testmode_1.set_up_test_mode)();
|
|
342
|
+
}
|
|
343
|
+
(0, sandstone_1.comment)("3. Process the start_challenge events");
|
|
344
|
+
this._events.start_challenge?.actions.forEach((action) => action());
|
|
345
|
+
(0, sandstone_1.comment)("4. Schedule the init_participants function to run after 1s");
|
|
346
|
+
init_participants.schedule("1s");
|
|
347
|
+
(0, sandstone_1.comment)("5. Display the game objective");
|
|
348
|
+
sandstone_1.scoreboard.objectives.setDisplay("sidebar", constants_1.VISIBLE_OBJECTIVE.name);
|
|
349
|
+
});
|
|
350
|
+
const init_participants = (0, sandstone_1.MCFunction)("init_participants", () => {
|
|
351
|
+
(0, sandstone_1.comment)("1. Setup all individual variables to their default values.");
|
|
352
|
+
for (const [name, variable] of Object.entries(this.full_variables)) {
|
|
353
|
+
const previousValue = this.getPreviousValueScore(name);
|
|
354
|
+
if (typeof previousValue === "undefined") {
|
|
355
|
+
throw new Error(`Previous value for variable ${name} not found.`);
|
|
356
|
+
}
|
|
357
|
+
if (variable.type === "individual" && variable.default !== undefined) {
|
|
358
|
+
sandstone_1.execute.as(constants_1.ALL).run((0, utils_1.getChildFunctionName)(name), () => {
|
|
359
|
+
variable.score.set(variable.default);
|
|
360
|
+
previousValue.set(variable.default);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
if (variable.type === "global" && variable.default !== undefined) {
|
|
364
|
+
variable.score.set(variable.default);
|
|
365
|
+
previousValue.set(variable.default);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
(0, sandstone_1.comment)("2. Set the events fire counters to 0");
|
|
369
|
+
for (const event of customScoreEvents) {
|
|
370
|
+
// We could make the distinction between global and individual counters,
|
|
371
|
+
// but it just works to make all players set event fires to 0
|
|
372
|
+
sandstone_1.execute.as(constants_1.ALL).run(() => {
|
|
373
|
+
event.counter.set(0);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
(0, sandstone_1.comment)("3. Process the init_participants events");
|
|
377
|
+
this._events.init_participants?.actions.forEach((action) => action());
|
|
378
|
+
(0, sandstone_1.comment)("4. Set the game state to ON");
|
|
379
|
+
this.full_variables.game_state.score.set(constants_1.GAME_STATES.ON);
|
|
380
|
+
//tellraw("@a", [`${DISPLAY_TAG}The challenge has started!`]);
|
|
381
|
+
});
|
|
382
|
+
(0, sandstone_1.MCFunction)("on_tick", () => {
|
|
383
|
+
sandstone_1._.if(this.variables.game_state.equalTo(constants_1.GAME_STATES.ON), () => {
|
|
384
|
+
(0, sandstone_1.comment)("1. Run all updaters");
|
|
385
|
+
(0, sandstone_1.MCFunction)("custom_variable_updaters", () => {
|
|
386
|
+
for (const [name, variable] of Object.entries(this.full_variables)) {
|
|
387
|
+
if (variable.updater) {
|
|
388
|
+
(0, sandstone_1.comment)(`Updating variable ${name}`);
|
|
389
|
+
if (variable.type === "individual") {
|
|
390
|
+
sandstone_1.execute
|
|
391
|
+
.as(constants_1.ALL)
|
|
392
|
+
.at("@s")
|
|
393
|
+
.run((0, utils_1.getChildFunctionName)(`update_${name}`), () => {
|
|
394
|
+
variable.updater?.(variable.score, this.variables);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
variable.updater(variable.score, this.variables);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
})();
|
|
403
|
+
(0, sandstone_1.comment)("2. Process the on_tick event");
|
|
404
|
+
this._events.on_tick?.actions.forEach((action) => action());
|
|
405
|
+
(0, sandstone_1.comment)("3. Process custom events");
|
|
406
|
+
(0, sandstone_1.MCFunction)("process_custom_events", () => {
|
|
407
|
+
// We process all custom events - this checks if the condition is reached & fire them if necessary
|
|
408
|
+
customScoreEvents.forEach((event) => {
|
|
409
|
+
this.processCustomScoreEvent(event);
|
|
410
|
+
});
|
|
411
|
+
})();
|
|
412
|
+
(0, sandstone_1.comment)("4. Set previous values for all variables");
|
|
413
|
+
sandstone_1.execute.as(constants_1.ALL).run((0, utils_1.getChildFunctionName)("set_previous_values"), () => {
|
|
414
|
+
for (const [name, variable] of Object.entries(this.full_variables)) {
|
|
415
|
+
// We could also make the distinction between global and individual variables,
|
|
416
|
+
// but again it just works to run it on all players
|
|
417
|
+
const previousValue = this.getPreviousValueScore(name);
|
|
418
|
+
previousValue.set(variable.score);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
(0, sandstone_1.comment)("5. Check end conditions");
|
|
422
|
+
const timerCondition = this.variables.game_timer.equalTo(this.game_duration);
|
|
423
|
+
const endCondition = this._end_condition ? sandstone_1._.or(this._end_condition, timerCondition) : timerCondition;
|
|
424
|
+
sandstone_1._.if(endCondition, () => {
|
|
425
|
+
//tellraw("@a", [`${DISPLAY_TAG}End condition met! Ending challenge...`]);
|
|
426
|
+
end_challenge();
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
}, {
|
|
430
|
+
runEveryTick: true,
|
|
431
|
+
});
|
|
432
|
+
const end_challenge = (0, sandstone_1.MCFunction)("end_challenge", () => {
|
|
433
|
+
(0, sandstone_1.comment)("1. Set the game state to OFF");
|
|
434
|
+
this.full_variables.game_state.score.set(constants_1.GAME_STATES.OFF);
|
|
435
|
+
(0, sandstone_1.comment)("2. Process the end_challenge events");
|
|
436
|
+
this._events.end_challenge?.actions.forEach((action) => action());
|
|
437
|
+
(0, sandstone_1.comment)("3. Announce the winners");
|
|
438
|
+
for (const [role, condition] of Object.entries(this._win_conditions || {})) {
|
|
439
|
+
sandstone_1.execute.as((0, actions_1.mapTarget)(role)).run((0, utils_1.getChildFunctionName)(`check_winner_team_${role}`), () => {
|
|
440
|
+
sandstone_1._.if(condition, () => {
|
|
441
|
+
actions_1.Actions.announce({
|
|
442
|
+
message: [(0, sandstone_1.Selector)("@s"), " has won the challenge!"],
|
|
443
|
+
})();
|
|
444
|
+
(0, sandstone_1.tag)("@s").add(constants_1.WINNER_TAG);
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
commands_1.Commands.declareWinners();
|
|
449
|
+
});
|
|
450
|
+
(0, sandstone_1.savePack)("datapack", {
|
|
451
|
+
customPath: path.join(this.kradle_challenge_path, this.name),
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
exports.ChallengeBase = ChallengeBase;
|
|
456
|
+
/**
|
|
457
|
+
* Creates a new challenge with the provided configuration.
|
|
458
|
+
*/
|
|
459
|
+
function createChallenge(config) {
|
|
460
|
+
return new ChallengeBase(config);
|
|
461
|
+
}
|
|
462
|
+
//# sourceMappingURL=challenge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"challenge.js","sourceRoot":"","sources":["../src/challenge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoiBA,0CAIC;AAxiBD,gDAAkC;AAClC,yCAcmB;AAEnB,uCAA+C;AAC/C,yCAAsC;AACtC,2CASqB;AACrB,yCAAiE;AACjE,mCAaiB;AACjB,mCAA+C;AAElC,QAAA,sBAAsB,GAAG,0BAA0B,CAAC;AAEjE,MAAM,qBAAqB,GAAG,QAAQ,CAAC;AACvC,MAAM,qCAAqC,GAAG,kBAAkB,CAAC;AAEjE,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAC7C,MAAM,yCAAyC,GAAG,kBAAkB,CAAC;AAErE,IAAI,sBAAsB,GAAG,CAAC,CAAC;AAE/B;;GAEG;AACH,SAAS,wBAAwB,CAAC,IAAY,EAAE,MAAc;IAC7D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACtD,OAAO,GAAG,WAAW,GAAG,MAAM,EA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,oBAAQ,EAAC,IAAI,CAAC,EAAE,yBAAyB,CAAC;yBACpD,CAAC,EAAE,CAAC;wBACL,IAAA,eAAG,EAAC,IAAI,CAAC,CAAC,GAAG,CAAC,sBAAU,CAAC,CAAC;oBAC3B,CAAC,CAAC,CAAC;gBACJ,CAAC,CAAC,CAAC;YACJ,CAAC;YAED,mBAAQ,CAAC,cAAc,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;QAEH,IAAA,oBAAQ,EAAC,UAAU,EAAE;YACpB,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC,IAAI,CAAC;SAC5D,CAAC,CAAC;IACJ,CAAC;CACD;AA7bD,sCA6bC;AAED;;GAEG;AACH,SAAgB,eAAe,CAC9B,MAA+C;IAE/C,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type JSONTextComponent, type Score } from "sandstone";
|
|
2
|
+
/**
|
|
3
|
+
* Commands for interacting with Kradle's Watcher.
|
|
4
|
+
*/
|
|
5
|
+
export declare const Commands: {
|
|
6
|
+
/**
|
|
7
|
+
* Raw command - sends a command to Kradle's Watcher.
|
|
8
|
+
*
|
|
9
|
+
* Arguments are passed as a JSON object.
|
|
10
|
+
* @param command The command to send.
|
|
11
|
+
* @param args The JSON Text Component arguments to send with the command.
|
|
12
|
+
*
|
|
13
|
+
* @warning
|
|
14
|
+
* The arguments must resolve to a JSON-serializable object. This cannot be verified at compile time.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* Commands.raw("start_challenge", { name: "My Challenge" });
|
|
18
|
+
* // The watcher will receive the following payload::
|
|
19
|
+
* // {"type":"kradle_command","command":"start_challenge","arguments":{"name":"My Challenge"}}
|
|
20
|
+
*
|
|
21
|
+
* Commands.raw("fetch", {url: "https://goldprice.org", "target_score": "gold_price", callback: "kradle:on_gold_price_fetched"})
|
|
22
|
+
* // The watcher will receive the following payload:
|
|
23
|
+
* // {"type":"kradle_command","command":"fetch","arguments":{"url":"https://goldprice.org","target_score":"gold_price","callback":"kradle:on_gold_price_fetched"}}
|
|
24
|
+
*/
|
|
25
|
+
raw: (command: string, args: Record<string, JSONTextComponent>) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Declare winners of the challenge to the Watcher. This will end the challenge.
|
|
28
|
+
*
|
|
29
|
+
* The `winners` argument of the payload will be a JSON list of player names.
|
|
30
|
+
* Ex: { "winners": ["player1", "player2"] }
|
|
31
|
+
*
|
|
32
|
+
* If no winners are selected, an empty array will be sent.
|
|
33
|
+
* Ex: { "winners": [] }
|
|
34
|
+
*/
|
|
35
|
+
declareWinners: () => void;
|
|
36
|
+
logVariable: (message: string, variable: Score, store: boolean) => void;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,iBAAiB,EAAE,KAAK,KAAK,EAAyC,MAAM,WAAW,CAAC;AA6CzG;;GAEG;AACH,eAAO,MAAM,QAAQ;IACpB;;;;;;;;;;;;;;;;;;OAkBG;mBACY,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC;IAgC9D;;;;;;;;OAQG;;2BAiBoB,MAAM,YAAY,KAAK,SAAS,OAAO;CAe9D,CAAC"}
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Commands = void 0;
|
|
4
|
+
const sandstone_1 = require("sandstone");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
/**
|
|
7
|
+
* Converts a Sandstone Selector to a JSON Text Component that will be displayed like a JSON array in the chat.
|
|
8
|
+
* This is used to send selectors as part of JSON messages.
|
|
9
|
+
*
|
|
10
|
+
* @warning
|
|
11
|
+
* This does NOT work with empty selectors (they will be represented as `[""]`).
|
|
12
|
+
* Make sure to check if the selector matches any entities before using this function.
|
|
13
|
+
*
|
|
14
|
+
* @param selector The selector to convert.
|
|
15
|
+
* @returns An array of JSON Text Components that will be displayed as a JSON array in the chat.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const selector = Selector("@a", { tag: "kradle_participant" });
|
|
19
|
+
* const jsonArray = selectorToJSONArray(selector);
|
|
20
|
+
* tellraw("@a", selectorToJSONArray(selector));
|
|
21
|
+
*
|
|
22
|
+
* // Everyone will see this in the chat:
|
|
23
|
+
* // ["Player1","Player2","Player3"]
|
|
24
|
+
*/
|
|
25
|
+
function selectorToJSONArray(selector) {
|
|
26
|
+
return ['["', { selector: selector.toString(), separator: '","' }, '"]'];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts a Sandstone Selector to a JSON string that will be displayed like a JSON string in the chat.
|
|
30
|
+
* If the selector matches several entities, it will display a comma-separated list of their names.
|
|
31
|
+
*
|
|
32
|
+
* @param selector The selector to convert.
|
|
33
|
+
* @returns A JSON string that will be displayed like a JSON string in the chat.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const selector = Selector("@s");
|
|
37
|
+
* const jsonString = selectorToJSONString(selector);
|
|
38
|
+
* tellraw("@a", jsonString);
|
|
39
|
+
*
|
|
40
|
+
* // Everyone will see this in the chat:
|
|
41
|
+
* // "Player1"
|
|
42
|
+
*/
|
|
43
|
+
function selectorToJSONString(selector) {
|
|
44
|
+
return ['"', { selector: selector.toString(), separator: "," }, '"'];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Commands for interacting with Kradle's Watcher.
|
|
48
|
+
*/
|
|
49
|
+
exports.Commands = {
|
|
50
|
+
/**
|
|
51
|
+
* Raw command - sends a command to Kradle's Watcher.
|
|
52
|
+
*
|
|
53
|
+
* Arguments are passed as a JSON object.
|
|
54
|
+
* @param command The command to send.
|
|
55
|
+
* @param args The JSON Text Component arguments to send with the command.
|
|
56
|
+
*
|
|
57
|
+
* @warning
|
|
58
|
+
* The arguments must resolve to a JSON-serializable object. This cannot be verified at compile time.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* Commands.raw("start_challenge", { name: "My Challenge" });
|
|
62
|
+
* // The watcher will receive the following payload::
|
|
63
|
+
* // {"type":"kradle_command","command":"start_challenge","arguments":{"name":"My Challenge"}}
|
|
64
|
+
*
|
|
65
|
+
* Commands.raw("fetch", {url: "https://goldprice.org", "target_score": "gold_price", callback: "kradle:on_gold_price_fetched"})
|
|
66
|
+
* // The watcher will receive the following payload:
|
|
67
|
+
* // {"type":"kradle_command","command":"fetch","arguments":{"url":"https://goldprice.org","target_score":"gold_price","callback":"kradle:on_gold_price_fetched"}}
|
|
68
|
+
*/
|
|
69
|
+
raw: (command, args) => {
|
|
70
|
+
const basePayload = JSON.stringify({
|
|
71
|
+
command,
|
|
72
|
+
type: "kradle_command",
|
|
73
|
+
arguments: {},
|
|
74
|
+
});
|
|
75
|
+
// We need to insert our arguments into the "arguments" field of the base payload.
|
|
76
|
+
const splitIndex = basePayload.indexOf("}");
|
|
77
|
+
const leftText = basePayload.slice(0, splitIndex);
|
|
78
|
+
const rightText = basePayload.slice(splitIndex);
|
|
79
|
+
function parseValue(value) {
|
|
80
|
+
if (typeof value === "boolean") {
|
|
81
|
+
return value.toString();
|
|
82
|
+
}
|
|
83
|
+
if (typeof value === "string") {
|
|
84
|
+
return JSON.stringify(value);
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
const argumentsPayload = Object.entries(args).flatMap(([key, value], index) => {
|
|
89
|
+
const result = [`"${key}":`, parseValue(value)];
|
|
90
|
+
if (index > 0) {
|
|
91
|
+
return [",", ...result];
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
});
|
|
95
|
+
(0, sandstone_1.tellraw)(constants_1.WATCHER, [leftText, argumentsPayload, rightText]);
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Declare winners of the challenge to the Watcher. This will end the challenge.
|
|
99
|
+
*
|
|
100
|
+
* The `winners` argument of the payload will be a JSON list of player names.
|
|
101
|
+
* Ex: { "winners": ["player1", "player2"] }
|
|
102
|
+
*
|
|
103
|
+
* If no winners are selected, an empty array will be sent.
|
|
104
|
+
* Ex: { "winners": [] }
|
|
105
|
+
*/
|
|
106
|
+
declareWinners: () => {
|
|
107
|
+
const selector = (0, sandstone_1.Selector)("@a", { tag: constants_1.WINNER_TAG });
|
|
108
|
+
// If no winners are selected, we send them as a JSON array.
|
|
109
|
+
sandstone_1._.if(selector, () => {
|
|
110
|
+
exports.Commands.raw("declare_winners", {
|
|
111
|
+
winners: selectorToJSONArray(selector),
|
|
112
|
+
});
|
|
113
|
+
}).else(() => {
|
|
114
|
+
// Else, we send an empty array.
|
|
115
|
+
exports.Commands.raw("declare_winners", {
|
|
116
|
+
winners: "[]",
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
logVariable: (message, variable, store) => {
|
|
121
|
+
const objectiveName = variable.objective.name;
|
|
122
|
+
const variableName = variable.target.toString();
|
|
123
|
+
return exports.Commands.raw("log_variable", {
|
|
124
|
+
message,
|
|
125
|
+
store,
|
|
126
|
+
variable: JSON.stringify({
|
|
127
|
+
objective: objectiveName,
|
|
128
|
+
selector: variableName,
|
|
129
|
+
}),
|
|
130
|
+
value: variable,
|
|
131
|
+
targets: selectorToJSONString((0, sandstone_1.Selector)(variableName)),
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=commands.js.map
|