Support first-run selection and optional tutorials
Save the selected country, starting crew, and unlocks when the client submits its first-run selection. Use the stock unlock and crew formats. Enable the existing option to skip the basic tutorial. The client reached the hangar. Tutorial verification is pending.
This commit is contained in:
1 parent
c3c5f583ad
commit
6ed498e4d0
8 files changed
+227
-10
No files matched your search
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Crews in the profile, as in Gaijin's config/default_user.blk:
|
||||
*
|
||||
* crews{
|
||||
* c0{
|
||||
* country:t="country_usa"
|
||||
* aircrafts{ trained:t="bf2c_1" trained:t="p-26a_34_m2" current:t="bf2c_1" }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* "trained" lists the vehicles the crew is trained for (repeated), "current" is the vehicle
|
||||
* in its slot.
|
||||
*/
|
||||
import { ensureBlock, setParam, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const CREWS = 'crews';
|
||||
const VEHICLES = 'aircrafts';
|
||||
const TRAINED = 'trained';
|
||||
const CURRENT = 'current';
|
||||
|
||||
export function crewOf(profile: BlkBlock, crewId: number): BlkBlock | undefined {
|
||||
return profile.blocks.find((block) => block.name === CREWS)?.blocks.find((crew) => crew.name === `c${crewId}`);
|
||||
}
|
||||
|
||||
/** Train the crew for the vehicle (if it is not yet) and put the vehicle in its slot. */
|
||||
export function putVehicleInCrew(crew: BlkBlock, vehicle: string): void {
|
||||
const vehicles = ensureBlock(crew, VEHICLES);
|
||||
const trained = vehicles.params.some((param) => param.name === TRAINED && param.value.type === 'string' && param.value.value === vehicle);
|
||||
if (!trained) vehicles.params.push({ name: TRAINED, value: { type: 'string', value: vehicle } });
|
||||
setParam(vehicles, CURRENT, { type: 'string', value: vehicle });
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Earned unlocks in the profile.
|
||||
*
|
||||
* unlocks{
|
||||
* unlock{ item:t="country_usa" cachedIndex:i=-1 expired:b=no earned:b=yes }
|
||||
* }
|
||||
*
|
||||
* The client's profile reader (aces.exe 2.61.0.37 0x919060, from 0x91bad2) walks the
|
||||
* sub-blocks of "unlocks" named "unlock" and reads each one's parameters in this order,
|
||||
* matching every position by name:
|
||||
* item:t the unlock's id from config/unlocks.blk; must come first
|
||||
* ("TROPHY: Bad DataBlock for unlock - NO id param" otherwise)
|
||||
* cachedIndex:i optional; the unlock's position in the client's table, only a
|
||||
* lookup hint: a negative value makes the client look it up by name
|
||||
* (0x91c052)
|
||||
* expired:b optional
|
||||
* removeTimeMinutes:i optional
|
||||
* earned:b only "earned:b=yes" marks the unlock earned (0x91c289..0x91c2b7
|
||||
* sets the flag that the script function is_unlocked, 0x179eae0,
|
||||
* reads); without it the unlock is registered but not earned
|
||||
* The client's own profile writer (0x91cd6f..) emits the same head: item, cachedIndex,
|
||||
* expired, then removeTimeMinutes when set, then earned.
|
||||
*/
|
||||
import { ensureBlock, findParam, type BlkBlock, type BlkParam } from '@wto/blk';
|
||||
|
||||
const UNLOCKS = 'unlocks';
|
||||
const UNLOCK = 'unlock';
|
||||
const ITEM = 'item';
|
||||
|
||||
/** Record the unlock as earned, rewriting an existing entry for it. */
|
||||
export function addUnlock(profile: BlkBlock, name: string): void {
|
||||
const unlocks = ensureBlock(profile, UNLOCKS);
|
||||
const existing = unlocks.blocks.find((unlock) => unlockName(unlock) === name);
|
||||
if (existing) existing.params = earnedUnlockParams(name);
|
||||
else unlocks.blocks.push({ name: UNLOCK, params: earnedUnlockParams(name), blocks: [] });
|
||||
}
|
||||
|
||||
function earnedUnlockParams(name: string): BlkParam[] {
|
||||
return [
|
||||
{ name: ITEM, value: { type: 'string', value: name } },
|
||||
{ name: 'cachedIndex', value: { type: 'int', value: -1 } },
|
||||
{ name: 'expired', value: { type: 'bool', value: false } },
|
||||
{ name: 'earned', value: { type: 'bool', value: true } },
|
||||
];
|
||||
}
|
||||
|
||||
function unlockName(unlock: BlkBlock): string | undefined {
|
||||
if (unlock.name !== UNLOCK) return undefined;
|
||||
const item = findParam(unlock, ITEM)?.value;
|
||||
return item?.type === 'string' ? item.value : undefined;
|
||||
}
|
||||
Reference in new issue
Block a user