repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
biomes-game
github_2023
ill-inc
typescript
cleanSchema
async function cleanSchema() { await scriptInit(); const firestore = getFirestoreInstance(); const storage = new Store(firestore); const db = createBdb(storage); const queue = new WorkQueue(); for (const collection of await firestore.listCollections()) { await queue.add(handleCollection(firestore, qu...
// Delete anything in Firestore that doesn't conform to our schema.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/scripts/node/clean_schema.ts#L78-L91
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
go
async function go() { await bootstrapGlobalSecrets("biomes-discord-bot-token"); bootstrapGlobalConfig(); const storage = await createStorageBackend("firestore"); const db = createBdb(storage); const bot = await DiscordBotImpl.login(db); console.log(await bot.checkForServerPresence("333974257979621379")); }
// Discord bot: https://discord.com/developers/applications/1044657561107968061/information
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/scripts/node/discord_bot.ts#L9-L17
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
main
async function main(rawId?: string) { await scriptInit(); const id = safeParseBiomesId(rawId) ?? (await determineEmployeeUserId()); log.info("Scanning chat content for user", { id }); const api = new RedisChatApi( 0 as unknown as WorldApi, await connectToRedis("chat") ); await api.healthy(); co...
// kubectl port-forward redis-other-0 9000:6379
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/scripts/node/dump_chats.ts#L13-L48
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
backfillDb
async function backfillDb() { await scriptInit(); const storage = await createStorageBackend("firestore"); const db = createBdb(storage); const allUsers = (await db.collection("users").get()).docs; await Promise.all( allUsers.map((user) => user.ref.update({ disabled: false, }) ) ...
// This marks all users as enabled.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/scripts/node/enable_all_users.ts#L5-L19
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
applyShardFix
const applyShardFix = ( terrain: Terrain | ReadonlyTerrain, shardId: ShardId ): boolean => { let changes = false; const shardOccupanies = shardToOccupancies.get(shardId); const occupancyAt = (shardPos: Vec3) => { const occupancy = shardOccupanies.find(([pos]) => isEqual(pos, shardPos)); ...
// If ReadonlyTerrain is passed, returns boolean whether fix is required; otherwise, applies fix.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/scripts/node/fix_occupancy.ts#L84-L176
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
testAndMaybeFix
const testAndMaybeFix = ( shardPos: ReadonlyVec3, currentOccupancy: BiomesId | undefined, neededOccupancy: BiomesId | undefined, info: { entityId: BiomesId | undefined; version: number | undefined } ) => { if (!currentOccupancy && !!neededOccupancy) { occupancyIsNoneButShouldBe...
// Test and maybe fix occupancy discrepancy.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/scripts/node/fix_occupancy.ts#L96-L136
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
main
async function main() { var rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false, }); const sourceMapCache = new SourceMapCache(); let outputQueue = Promise.resolve(); for await (const line of rl) { const mappedLine = applySourceMapToLine(line, sourc...
// Use this script to deobfuscate a given stack trace.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/scripts/node/source_map.ts#L13-L33
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
getBiscuitForEntity
function getBiscuitForEntity(entity: PatchableEntity) { if (entity.npcMetadata()) { return anItem(entity.npcMetadata()!.type_id); } else if (entity.placeableComponent()) { return anItem(entity.placeableComponent()!.item_id); } return undefined; }
// Syncs the ACL settings from Bikkie into the instantiated
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/scripts/node/sync_protection_params.ts#L11-L18
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
applyFix
function applyFix(voxeloo: VoxelooModule, entity: PatchableEntity): boolean { if (!entity.shardDiff() || !entity.shardSeed() || !entity.shardPlacer()) { return false; } const terrain = new Terrain(voxeloo, entity); try { return usingAll([new voxeloo.SparseBlock_U32()], (diff) => { loadBlockWrappe...
// Iterates through all world voxels and checks to see if any diffs can be
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/scripts/node/shards/clean_terrain_diffs.ts#L17-L64
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
filenameSafeString
function filenameSafeString(s: string): string { const INVALID_CHARACTERS_RE = /[^a-z0-9\-]/gi; return s.replaceAll(INVALID_CHARACTERS_RE, "_").toLowerCase(); }
// Convert a string into a filename-safe string, by replacing invalid
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/benchmarks/root_hooks.ts#L7-L11
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
fullyQualifiedTestName
function fullyQualifiedTestName(test: Mocha.Test) { const fullyQualifiedTitle: string[] = [test.title]; let currentAncestorSuite = test.parent; while (currentAncestorSuite && !currentAncestorSuite.root) { fullyQualifiedTitle.push(currentAncestorSuite.title); currentAncestorSuite = currentAncestorSuite.pa...
// Follow the ancestor links up the test suites to fully qualify the test's
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/benchmarks/root_hooks.ts#L15-L25
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
loadModel
function loadModel(cursor: Cursor) { const nodes: ReturnType<typeof loadNode>[] = []; const nodeCount = cursor.popNumber(); for (let i = 0; i < nodeCount; i += 1) { nodes.push(loadNode(cursor)); } return { nodes }; }
// TODO: Replace the parsing code below with a zod-like schema.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/cayley/graphics/models.ts#L31-L38
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
getCamera
const getCamera = () => camera;
// Show bounding box for debugging
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/components/ThreeObjectPreview.tsx#L147-L147
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
treeToList
function treeToList<T>( node: d3.HierarchyPointNode<T> ): d3.HierarchyPointNode<T>[] { return [node, ...(node.children?.flatMap(treeToList) ?? [])]; }
// D3 hierarchy tree to list for react flow nodes
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/components/admin/quests/QuestGraph.tsx#L42-L46
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
ChallengeStinger
const ChallengeStinger: React.FunctionComponent<{ stinger: ChallengeStingerBundle; onAnimationComplete: () => unknown; }> = ({ stinger, onAnimationComplete }) => { const [showStinger, setShowStinger] = useState(true); const { audioManager } = useClientContext(); useEffect(() => { document.body.classList...
/* To test: /admin test notify challenge_unlock /admin test notify challenge_complete */
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/components/challenges/ChallengeStingers.tsx#L18-L184
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
nameByDiff
const nameByDiff = (baseRecipe: Item, recipe: Item) => { const inputs = getRecipeInput(baseRecipe); const altInputs = getRecipeInput(recipe); const missing = altInputs && inputs ? [...altInputs.values()].filter((e) => !inputs.has(itemPk(e.item))) : []; return missing.length > 0 ...
// Map into {name, recipe} by labeling with any inputs not found in this one
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/components/inventory/crafting/helpers.ts#L141-L151
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
fixVolume
function fixVolume(volume: number) { const rounded = round(volume, 4); return isFinite(rounded) ? rounded : 0; }
// JS keeps compaining about non-finite numbers if we set volume...
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/context_managers/audio_manager.ts#L40-L43
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
ConsumableSyncBuffer.doLoadChanges
private async doLoadChanges( mode: "bootstrap" | "sync" = "sync" ): Promise<Change[]> { const ids = new Set<BiomesId>(); const changes: Change[] = []; for (const syncChange of this.changes) { if (typeof syncChange === "number") { ids.add(syncChange); } else { changes.push(s...
// Handle any bootstrap changes
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/context_managers/client_io.ts#L163-L203
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
SyncBuffer.flush
flush(): ConsumableSyncBuffer { const ret = new ConsumableSyncBuffer( this.oobFetcher, this.changes, this.deliveries ); this.changes = []; this.deliveries = []; return ret; }
// Export a copy of this buffer.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/context_managers/client_io.ts#L235-L244
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
rebindListener
const rebindListener = () => { this.bind(bindingsForStorage()); };
// Rebind every time local storage values change
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/context_managers/input.ts#L495-L497
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AllocationSnapshot.adjustAllocation
adjustAllocation( ptr: number, sizeDelta: number, stackTrace: string | undefined ) { if (!ptr) { return; } const alloc = this.allocationsByPtr.get(ptr); if (!alloc) { this.addAllocation(ptr, sizeDelta, stackTrace); return; } this.removeAllocation(ptr); allo...
// size delta.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/context_managers/wasm_memory_tracing.ts#L123-L145
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
onMalloc
const onMalloc = (ptr: number, size: number) => { this.currentState.addAllocation(ptr, size, getStackTrace()); };
// Install our allocation hooks.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/context_managers/wasm_memory_tracing.ts#L218-L220
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
MarchHelper.terrainCastCameraEnvironmentRay
terrainCastCameraEnvironmentRay( deps: ShardDeps, maxDistance: number, fn: CastFn ) { const ray = MarchHelper.getCameraRayParams(deps, maxDistance); terrainMarch( this.voxeloo, deps, ray.cameraPos, ray.dir, ray.castDist, (hit) => { if (ray.validHitPos(hi...
// Intersects with only the terrain.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/helpers/march.ts#L84-L102
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
Ray.hitWithinRange
hitWithinRange(position: THREE.Vector3): boolean { if (this.maxTravelDistance === undefined) { return true; } const distance = this.source.distanceTo(position); return distance <= this.maxTravelDistance; }
// Check if a position is close enough to be a valid hit.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/helpers/ray.ts#L13-L20
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
Ray.fromPoints
static fromPoints(from: THREE.Vector3, to: THREE.Vector3): Ray { const direction = to.clone().sub(from).normalize(); return new Ray(from, direction); }
// Ray traveling from {from} to {to}.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/helpers/ray.ts#L23-L26
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
centeredOnBlock
function centeredOnBlock( center: ReadonlyVec3, blockPos: ReadonlyVec3 ): boolean { if (blockPos === undefined || center === undefined) { return false; } return equals(floor(center), blockPos); }
/// Checks if {center} is within the bounds of a voxel at {blockPos}.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/interact/helpers.ts#L1141-L1150
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AttackDestroyDelegateItemSpec.handleDestroyInfoChangeInteraction
private handleDestroyInfoChangeInteraction( destroyInfo: DestroyInfo | undefined ) { const localPlayer = this.deps.resources.get("/scene/local_player"); localPlayer.destroyInfo = destroyInfo; const secondsSinceEpoch = this.deps.resources.get("/clock").time; if ((!destroyInfo || destroyInfo.finish...
/* * For interaction with fallback item script helpers */
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/interact/item_types/attack_destroy_delegate_item_spec.ts#L417-L498
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
DestroyerItemSpec.constructor
constructor( readonly deps: AttackDestroyDelegateDeps, readonly primarySpec?: AttackDestroyDelegateSpec ) { super(deps, { onPrimaryDown: (itemInfo: ClickableItemInfo) => { if (!primarySpec?.onPrimaryDown?.(itemInfo)) { this.onSecondaryDown(itemInfo); } return true; ...
// which has the side effect of making destroy actions primary
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/interact/items/destroyer.ts#L12-L36
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
ShapeItemSpec.performShape
private performShape(shapeRequest: ShapeRequest): boolean { if ( shapeTerrain( this.deps, shapeRequest.pos, shapeRequest.shape, shapeRequest.itemRef ) ) { const player = this.deps.resources.get("/scene/local_player").player; player.eagerEmote(this.deps.eve...
// Carry of the shape request. Returns true if successful and false otherwise.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/interact/items/shape.ts#L82-L96
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
ShaperItemSpec.performShape
private performShape({ pos, isomorphism, player, itemRef, }: ShapeRequest): boolean { if (this.deps.actionThrottler.shouldThrottle("shape")) { return false; } // Lookup the shard entity information. const shardId = voxelShard(...pos); const entity = this.deps.resources.get("...
// Carry of the shape request. Returns true if successful and false otherwise.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/interact/items/shaper.ts#L112-L155
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
SampleWindow.min
min() { return Math.min(...this.windowSamples.slice(0, this.#count)); }
// Returns the low-water-mark in the window.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/renderers/performance_profiler.ts#L63-L65
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
PlayersRenderer.updatePlayerThree
updatePlayerThree( player: Player, mesh: LoadedPlayerMesh, dt: number, camera: Camera, localPlayer?: LocalPlayer ) { // Animations const { three, animationSystemState } = mesh; const clock = this.resources.get("/clock"); three.scale.setScalar(player.scale); const scenePlayer = ...
// localPlayer is only defined if this player is the local player.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/renderers/players.ts#L88-L205
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
RenderPass.checkConnections
checkConnections(toScreen: boolean = false) { // Check if we have all inputs wired up correctly if (!this.hasRequiredInputs()) { return false; } if (!toScreen) for (const output of this.outputChannels()) { if (!this.outputs.has(output)) { return false; } } ...
// Checks
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/renderers/passes/pass.ts#L76-L88
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
RenderPass.generateBuffers
generateBuffers(_renderToScreen: boolean) {}
// TODO: generateBuffers can re-use textures from previous passes of a channel
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/renderers/passes/pass.ts#L91-L91
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
CSS3DRenderer.constructor
constructor( private containerElement: HTMLElement, private cameraElement: HTMLElement ) { this.#cache = { camera: { fov: 0, style: "" }, objects: new WeakMap(), }; this.containerElement.style.overflow = "hidden"; this.cameraElement.style.transformStyle = "preserve-3d"; this....
// ...
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/renderers/three_ext/css3d.ts#L105-L118
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
buildGhostMesh
const buildGhostMesh = ( data: GroupSubMesh, baseOpacity: number, highLightedOpacity: number ) => { const bufferGeo = groupGeometryToBufferGeometry(data); const translucentMaterial = makeHighlightedTranslucentMaterial({ useMap: true, map: makeColorMap(data.textureData(), ...data.textur...
// Need these to use custom shaders that change opacity based on where we are looking.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/resources/blueprints.ts#L155-L170
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
addFaces
const addFaces = ( faces: [Vec3, number][], color: number, opacity: number ) => { for (const [pos, isomorphism] of faces) { const transformId = isomorphism & 0x3f; const [permute, reflect] = getPermuteReflect(transformId); let faceBoxGeometry: THREE.BoxGeometry | undefined; con...
// Create meshes for the highlighted faces
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/resources/blueprints.ts#L280-L322
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
getPerformanceTargets
function getPerformanceTargets( direction: "increase" | "reduce", renderIntervalMs: number ): PerformanceTargets { const fps = 1000 / renderIntervalMs; for (const constraints of PERFORMANCE_TARGETS) { const biasedTargets = biasTargets(direction, constraints); if (fps < biasedTargets.ceilingFps) { ...
// Based on our current framerate, find out what quality settings we'll aim
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/resources/dynamic_settings_updater.ts#L62-L74
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
biasTargets
function biasTargets( direction: "increase" | "reduce", constraints: (typeof PERFORMANCE_TARGETS)[number] ) { return { ceilingFps: constraints.ceilingFps[direction], cpuBudgetMs: constraints.cpuBudgetMs[direction], gpuBudgetMs: constraints.gpuBudgetMs[direction], renderScale: constraints.renderSca...
// Adjust the constraints such that there's wiggle room between when we increase
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/resources/dynamic_settings_updater.ts#L78-L89
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
GroupPlacementPreview.placementTensorTakeOwnership
placementTensorTakeOwnership() { ok(this.groupPlacementTensor.tensor); ok(this.groupPlacementTensor.box); const box = groupTensorBox(this.groupPlacementTensor.tensor); const rotation = orientationToRotation(this.orientation); const rotatedTensor = rotateGroupTensor( this.context.voxeloo, ...
// You are taking ownership
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/resources/group_placement.ts#L97-L120
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
ParticleSystemMaterials.constructor
private constructor( public material: RawShaderMaterial, public geometry: BufferGeometry, public systemDynamics: ParticleSystemDynamics ) {}
// Construct using static creators below
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/resources/particles.ts#L99-L103
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
ParticleSystemMaterials.createBlockMaterials
static createBlockMaterials( systemDynamics: ParticleSystemDynamics, blockTextures: BlockTextures | GlassTextures, textureMap: number[] ) { return new ParticleSystemMaterials( makeParticlesMaterial({ ...this.emptyTextureParams(), displayRenderMode: ParticleDisplayMode.BLOCK, ...
// Creation functions
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/resources/particles.ts#L119-L138
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
purkinjeShift
function purkinjeShift(c: Vec3, amount = 0.1) { const m = [0.63721, 0.39242, 1.6064]; const K = 45.0; const S = 10.0; const k3 = 0.6; const k5 = 0.2; const k6 = 0.29; const rw = 0.139; const p = 0.6189; const lmsr = rgbToLmsr(c); const g = [1.0, 1.0, 1.0].map( (_, i) => 1.0 / Math.s...
// purkinje shift from:
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/resources/sky.ts#L60-L98
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
CameraScript.doFarPlaneFadeInTransition
doFarPlaneFadeInTransition() { const target = this.resources.get( "/settings/graphics/dynamic" ).drawDistance; this.smoothDrawDistance = makeFarPlaneTransition(); this.smoothDrawDistance.target(target); }
// smoothly fades in from near to far.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/scripts/camera.ts#L164-L170
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
MinigamesScript.constructor
constructor( private readonly deps: ClientContextSubset< | "resources" | "userId" | "clientMods" | ClientContextKeysFor<ClientMod["makeClientScript"]> > ) {}
// For hot reload
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/scripts/minigames.ts#L18-L25
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
makeCube
const makeCube = (x: number, y: number, z: number, w: number) => [ 0, 0, 0, x, 0, 0, x, 0, w, x, 0, w, 0, 0, w, 0, 0, 0, x, 0, z-w, x, 0, z, 0, 0, z, 0, 0, z, 0, 0, z-w, x, 0, z-w, w, 0, z-w, 0, 0, z-w, 0, 0, w, 0, 0, w, ...
// prettier-ignore
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/WireframeBoxGeometry.ts#L21-L171
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AnimationSystem.constructor
constructor(public readonly animations: A, public readonly layers: L) { this.animationNames = Array.from( Object.keys(animations) ) as StringKeyOf<A>[]; this.layerNames = Array.from(Object.keys(layers)) as LayerName<this>[]; }
// instantiate animation state associated with a given mesh.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/animation_system.ts#L60-L65
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AnimationSystem.durationFromState
durationFromState(state: AnimationSystemState<this>) { // Pull the action duration from the action. We don't care which layer // we pull the action from. const anyLayerName = (Object.keys(state.actions) as LayerName<this>[])[0]; const layerActions = state.actions[anyLayerName]; return (x: Animation...
// which is the main way this is expected to be done outside of unit tests.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/animation_system.ts#L88-L101
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AnimationSystem.newAccumulatedActions
newAccumulatedActions( clockTime: number, duration: (a: AnimationName<this>) => number, oneShotTransitionTrim?: number ) { return { layers: Object.fromEntries( this.layerNames.map((x) => [x, {}]) ) as LayerWeights<this>, animations: Object.fromEntries( this.animationN...
// animation state to adjust the set of currently playing animations.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/animation_system.ts#L106-L122
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AnimationSystem.accumulateAction
accumulateAction( action: AnimationAction<this> | undefined, accum: AccumulatedActions<this> ) { if (!action) { return; } // Set the animation state if the animation is active, and track if any // animation is active or not. let anyAnimationsApplied = false; (Object.keys(action....
// applied, leaving the layers that they affect open.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/animation_system.ts#L128-L182
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AnimationSystem.resolveIdleWeights
resolveIdleWeights(accum: AccumulatedActions<this>): void { (Object.keys(accum.layers) as LayerName<this>[]).forEach((x) => { const layer = accum.layers[x]; if ( !layer.idleWeights || !layer.desiredWeights || layer.desiredWeights["idle"] === 0 ) { return; } ...
// animations.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/animation_system.ts#L187-L212
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AnimationSystem.applySingleActionToState
applySingleActionToState( action: AnimationAction<this>, state: AnimationSystemState<this> ) { const accum = this.newAccumulatedActions(0, this.durationFromState(state)); this.accumulateAction(action, accum); this.applyAccumulatedActionsToState(accum, state); }
// for some corner cases like inventory select preview.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/animation_system.ts#L216-L223
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AnimationSystem.applyAccumulatedActionsToState
applyAccumulatedActionsToState( accum: AccumulatedActions<this>, state: AnimationSystemState<this>, weightSmoothingDt?: number ) { this.resolveIdleWeights(accum); // First, update the set of smoothed current weights for each animation by // layer. ( Object.entries(state.layerWeights...
// will actually start and stop animations.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/animation_system.ts#L228-L341
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
AnimationSystem.newState
newState<T extends Partial<Record<AnimationName<this>, number>>>( meshScene: THREE.Object3D, animations: THREE.AnimationClip[], animationTimingTweaks?: T ): AnimationSystemState<this> { const mixer = new THREE.AnimationMixer(meshScene); const clipByName = ( name: string, additive: boo...
// gltf instance and creates and associates animation data with it.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/animation_system.ts#L346-L429
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
splitWalkRunTransition
function splitWalkRunTransition(speed: number, runSpeed: number) { const SPEED_TRANSITION_RADIUS = runSpeed / 12; const alpha = Math.min( 1, Math.max( 0, (speed - (runSpeed - SPEED_TRANSITION_RADIUS)) / (SPEED_TRANSITION_RADIUS * 2) ) ); return [(1 - alpha) * speed, alpha * spee...
// Given the provided speed, determines how to split the animation weights
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/animations.ts#L47-L59
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
isPromise
function isPromise<T, S>(obj: PromiseLike<T> | S): obj is PromiseLike<T> { return ( !!obj && (typeof obj === "object" || typeof obj === "function") && typeof (obj as any).then === "function" ); }
// To reduce deps, copy this here
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/retargetable_proxy.ts#L2-L8
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
TimelineMatcher.match
match(label: string, worldTime: number, worldNow: number): number { let mapping = this.tickMap.get(label); if (!mapping || mapping.worldTime < worldTime) { const secondsSinceEvent = worldNow - worldTime; // If the time difference is small (less than a second), snap the start // time to the cur...
// that.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/timeline_matcher.ts#L16-L34
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
TimelineMatcher.query
query(label: string): number | undefined { return this.tickMap.get(label)?.animationTime; }
// isn't set.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/game/util/timeline_matcher.ts#L38-L40
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
toggleApproval
const toggleApproval = async (bundleId: BiomesId) => { const bundle = bundlesById.get(bundleId); if (bundle === undefined) { return; } await jsonPost<UpdateCuratedPhotoResponse, UpdateCuratedPhotoRequest>( `/api/social/update_curated_post`, { postId: bundleId, approved:...
// Change the approval status of a photo.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/client/util/social_manager_hooks.ts#L560-L582
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
makeTree
function makeTree( leaf: keyof typeof floraIDs, log: keyof typeof blockIDs, height: number ) { return merge([ write(leaf, [ [1, height, 1], [4, height + 5, 4], ]), write(leaf, [ [1, height + 1, 0], [4, height + 4, 5], ]), write(leaf, [ [0, height + 1, 1], ...
// Define a scene consistenting of a tree.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/galois/js/assets/scenes.ts#L58-L85
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
resize
const resize = () => { const size = context.renderer.getSize(new THREE.Vector2()); const [w, h] = elementSize(canvas.parentNode as HTMLElement); if (w != size.width || h != size.height) { renderer.setSize(w, h, false); camera.aspect = w / h; camera.updateProjectionMatrix(); ...
// Update viewport and projection matrix when the canvas is resized.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/galois/js/components/Scene.tsx#L182-L190
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
addToByFirst
function addToByFirst(node: TreeNode<T>) { if (Array.isArray(node[1])) { let existing = byFirst.get(node[0]); if (existing == undefined) { existing = []; } byFirst.set(node[0], [...existing, ...node[1]]); } else { leaves.set(node[0], node[1]); } }
// Helper function to populate byFirst and leaves.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/galois/js/editor/view/trie_split.ts#L15-L25
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
contentTreeToAntdTree
function contentTreeToAntdTree( contentTree: TreeNode<ContentPage>[], prefix = "" ): [DataNode[], Map<string, ContentPage>] { let keyMap = new Map<string, ContentPage>(); const antdTree = contentTree.map((n) => { const fullKey = prefix === "" ? n[0] : `${prefix}/${n[0]}`; const antdNode: DataNode = { ...
// Converts our abstract "editor assets tree" into a Ant Design tree ready
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/galois/js/editor/view/components/ContentSelector.tsx#L13-L36
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
run
function run() { void getNonPublishedAssetPaths().then((nonPublishedAssetPaths) => { if (nonPublishedAssetPaths.length == 0) { console.log( "All assets referenced by asset_versions.json are published." ); process.exit(0); } else { console.error( "The following asset pat...
// Check that all asset data that we ex
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/galois/js/publish/scripts/check_assets_published.ts#L5-L27
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
doECSEdit
async function doECSEdit(request: AdminECSEditRequest): Promise<boolean> { const { edit } = request; const fieldName = edit.kind === "update" ? edit.path[0] : edit.field; const editKind = edit.kind.toUpperCase(); if (fieldName === undefined) { return false; } if (!confirm(`Are you sure you want to ${edi...
// Perform and ECS edit and return whether it was successful.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/pages/admin/ecs/[id].tsx#L116-L131
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
accumulateHistogramCval
function accumulateHistogramCval(path: string[]) { return (cvals: JSONable) => { const histogram = getHistogramAtPathOrLogError(path, cvals); if (!histogram) { return; } const pathString = cvalPathToName(path); const baseOutputName = `cvals:${pathString}`; // Manually construct the com...
// Accumulates the data in a client histogram into the server's histogram,
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/pages/api/cval_logging.ts#L213-L248
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
accumulateCounterCval
function accumulateCounterCval<T extends string = string>( path: string[], counter: Counter<T>, labelValues?: LabelValues<T>, lookupCvalOptions?: LookupCvalOptions ) { return (cvals: JSONable) => { // We want to accumulate the diffs only, not the absolute client counts, // otherwise there will be much...
// TODO(top): In order for these to look more similar and be more consistent
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/pages/api/cval_logging.ts#L254-L272
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
expiresOnExpireAllCommand
const expiresOnExpireAllCommand = (e: LazyEntity) => { if (e.hasQuestGiver()) { return false; } const typeId = e.npcMetadata()?.type_id; if (typeId === undefined) { return false; } const type = idToNpcType(typeId); // By default don't kill quest giver NPCs, as ...
// Filters NPCs when an "expire all" command is sent... Filtered NPCs need
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/pages/api/admin/kill_all_npcs.ts#L32-L45
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
forwardAssetRequest
async function forwardAssetRequest( req: MaybeAuthedAPIRequest<WebServerApiRequest>, res: NextApiResponse ) { // Server-side redirect to prod. const remoteUrl = new URL(req.url!, "https://www.biomes.gg"); // Send out a request to prod for this asset, and await the response. const [status, headers, data] = ...
// For development environments, to reduce developer environment setup
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/pages/api/assets/player_mesh.glb.ts#L170-L206
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
doFetch
async function doFetch(worldApi: WorldApi, query: LeaderboardGetAfterQuery) { if (query.score === undefined) { const values = await worldApi .leaderboard() .get( categoryForRequestLeaderboard(query.leaderboard), query.window, query.order, query.count ); retur...
// TODO: move to pipeline
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/pages/api/social/leaderboard_get_after.ts#L41-L66
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
bulkEntityResponse
function bulkEntityResponse( entities: Iterable<ReadonlyEntity | undefined> ): WrappedEntity[] { const results: WrappedEntity[] = []; for (const entity of entities) { if (entity) { results.push(WrappedEntity.for(entity)); } } return results; }
// Wrap the response, but eliminate undefined.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/ask/service.ts#L41-L51
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
createSyntheticTray
function createSyntheticTray(baked: BakedBiscuitTray): BiscuitTray { const definitions: BiscuitDefinition[] = []; for (const biscuit of baked.contents.values()) { definitions.push(createSyntheticDefinition(biscuit)); } return BiscuitTray.of( attribs, BACKUP_BIKKIE_TRAY_ID, createTrayMetadata("Sy...
// Synthesize a tray from the current Bikkie-state, this loses
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/backup/serde.ts#L81-L92
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
loadVoxForWorld
function loadVoxForWorld( data: Buffer | l.GeneralNode<"Vox">, { color, isWearable }: { color?: string; isWearable?: boolean } ) { let vox = data instanceof Buffer ? l.LoadVox(toDataUri(data)) : data; const colorDescriptor = colorStringToDescriptor(color); if (colorDescriptor) { vox = l.ReplacePaletteEntr...
// Load a Vox file to suit in-world representation (i.e. placed, dropped, or in-hand)
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/bikkie/inference.ts#L74-L97
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
buildTyped
const buildTyped = async <T extends keyof AssetDataMap>( asset: l.GeneralNode<T> ): Promise<AssetDataMap[T]> => { const result = await assetServer.build(asset); if (isSignal(result)) { throw result; } else if (isError(result)) { throw new Error(result.info.join("")); } else { ret...
// Big overlap with 'Builder' and 'Exporter' from assets/scripts/export.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/bikkie/inference.ts#L270-L281
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
BikkieServer.bake
async bake() { await this.batcher.invalidate(); }
// Request baking of biscuits.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/bikkie/server.ts#L141-L143
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
BobTheBuilder.getStorageUsage
async getStorageUsage() { const { free, size } = await checkDiskSpace(this.cwd); if (!size) { return 1.0; } return Math.max(0, (size - free) / size); }
// Get the disk usage percentage of the workspace directory.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/bob/server.ts#L339-L345
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
BlockingQueue.push
push(...shardIds: ShardId[]) { let accepted = 0; for (const shard of shardIds) { if (!this.sharder.heldValues.has(shard)) { maybeLog(shard, "pushed, but not held"); continue; } maybeLog(shard, "pushed to high queue"); accepted++; this.high.add(shard); this.low...
// Push some elements to the high queue now, removing from others.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/gaia_v2/queue.ts#L119-L136
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
BlockingQueue.waitForChange
private async waitForChange(signal: AbortSignal) { return new Promise<void>((resolve) => { if (signal.aborted) { resolve(); return; } let timeout: NodeJS.Timeout | undefined; // Done waiting, doesn't mean success. const done = () => { signal.removeEventListener...
// - min delay timeout indicating something was deferred
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/gaia_v2/queue.ts#L150-L180
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
done
const done = () => { signal.removeEventListener("abort", done); if (timeout) { clearTimeout(timeout); timeout = undefined; } // In case abort or timeout, wait the CV to unblock the promise // we would otherwise leak. this.cv.signal(); resolve()...
// Done waiting, doesn't mean success.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/gaia_v2/queue.ts#L159-L169
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
includeInBatch
const includeInBatch = (source: Set<ShardId>) => { this.reducer(source); for (const shard of source) { if (batch.length >= CONFIG.gaiaShardsPerBatch) { return; } source.delete(shard); if (!this.sharder.heldValues.has(shard)) { maybeLog(shard, "dropped as n...
// When adding items to the batch respect the batch size, also
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/gaia_v2/queue.ts#L187-L201
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
Gremlin.connect
private async connect() { this.nextReconnectTime = undefined; const url = new URL( "/beta-sync", new URL(HostPort.forGremlinsSync().url, undefined) ).toString(); ok(!this.io); this.io = new ClientIo( { url, keepAliveIntervalMs: CONFIG.gremlinsKeepAliveMs, ...
// Connect the Gremlin
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/gizmo/gremlin.ts#L176-L213
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
Gremlin.tickConnectivity
private async tickConnectivity() { if (this.io === undefined) { if ( this.nextReconnectTime !== undefined && getNowMs() > this.nextReconnectTime ) { await this.connect(); return true; } else { return false; } } if ( this.lastConnect !== u...
// Returns true if our connection is in a healthy state and ready to go.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/gizmo/gremlin.ts#L216-L244
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
GizmoServer.determineTargetCount
private determineTargetCount(): number { const overallTarget = Math.min( this.maxPossibleOverallGremlins, Math.ceil(CONFIG.gremlinsPopulation) ); if (overallTarget <= 0) { return 0; } const targetPerReplica = Math.floor(overallTarget / this.replicas); if (this.index > 0) { ...
// divide evenly).
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/gizmo/server.ts#L72-L86
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
LogicHandler.attempt
async attempt( lockScope: LockMapScope, eventsToPublish: AnyEvent[] ): Promise<[AnyEvent[], any]> { if (eventsToPublish.length === 0) { return [[], {}]; // Nothing to do. } const batchContext = new EventBatchContext( this.voxeloo, new LogicVersionedEntitySource(this.voxeloo, thi...
// Attempt to process this batch, return remaining events that couldn't be handled.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/main.ts#L108-L177
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
ByKey.toString
toString() { return `[by-key ${this.keyType} ${this.key}]`; }
// Override toString
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/events/query.ts#L35-L37
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
QueryBuilderRoot.terrain
terrain(id: BiomesId) { return Query.for(id).terrain(); }
// Shortcuts.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/events/query.ts#L176-L178
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
EventBatchContext.constructor
constructor( private readonly voxeloo: VoxelooModule, private readonly versionedEntitySource: LogicVersionedEntitySource, public readonly secondsSinceEpoch: number ) {}
// changeset in this batch to ensure they get the same value.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/events/context/batch_context.ts#L91-L95
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
EventBatchContext.prepareSatisfy
private prepareSatisfy<TPrepareSpec extends PrepareSpecification>( involved: TPrepareSpec, handler: AnyEventHandler ): PreparedEntities<TPrepareSpec> | undefined { const result: PreparedEntities<PrepareSpecification> = {}; for (const [key, value] of entriesIn(involved)) { if (value === undefined...
// Satisfy all the queries in the given specification.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/events/context/batch_context.ts#L116-L144
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
EventBatchContext.satisfy
private satisfy<TInvolvedSpecification extends InvolvedSpecification>( entitySource: EntitySource, involved: TInvolvedSpecification ): [ InvolvedEntities<TInvolvedSpecification> | undefined, Map<BiomesId, undefined> | undefined ] { const result: any = {}; let created: Map<BiomesId, undefined...
// Satisfy all the queries in the given specification.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/events/context/batch_context.ts#L187-L257
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
EventBatchContext.prepareAll
prepareAll( handlerWorkByKind: Map<keyof EventSet, WorkByHandler> ): [Todo<TEvent>[], number] { let count = 0; const todo: Todo<TEvent>[] = []; for (const [handler, work] of handlerWorkByKind.values()) { const handlerTodo: [TEvent, InvolvedSpecification][] = []; for (const event of work) {...
// Note: This takes ownership of the event.s
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/events/context/batch_context.ts#L308-L327
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
ChangeSet.merge
merge(other: ChangeSet<THandled>) { for (const [id, tick] of other.versionMap) { this.versionMap.set(id, tick); } this.fetched.merge(other.fetched); this.handled.push(...other.handled); this.changes.push(other.changes.pop()); this.events.push(...other.events); for (const id of other.cr...
// Assumes the two changesets do not overlap in effects.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/events/context/change_set.ts#L48-L63
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
isAclChecker
function isAclChecker(value: unknown): value is AclChecker { return ( typeof value === "object" && value !== null && "kind" in value && value.kind === "aclChecker" ); }
// Silly necessary helper function needed until TS 5.0 (https://github.com/microsoft/TypeScript/pull/51502)
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/events/context/context.ts#L192-L199
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
resolveShapeName
function resolveShapeName(item: Item, isomorphism: Isomorphism) { const requestedShape = isomorphismShape(isomorphism); if ((item.shape || item.shaper) && requestedShape === getShapeID("full")) { return getShapeName(requestedShape); } else if (item.shape) { if (getShapeID(item.shape) === requestedShape) {...
// Resolves the name of the shape corresponding to the given isomorphism, and
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/events/handlers/shapes.ts#L22-L36
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
PlayerInventoryEditor.findBestRefForMerge
private findBestRefForMerge( itemAndCount: ReadonlyItemAndCount, { partialOk, noHotbar, noInventory, }: { partialOk?: boolean; noHotbar?: boolean; noInventory?: boolean; }, used?: Set<string> ): MergeIndex | undefined { const combinableAmount = partialOk ...
// You should not use this method, typically use: findSlotToMergeIntoInventory
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/inventory/player_inventory_editor.ts#L301-L395
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
createLockMapAndLog
function createLockMapAndLog() { const log: string[] = []; const fakeMutexes = new DefaultMap<BiomesId, IMutex>((id) => ({ acquire: async () => { log.push(`acquire ${id}`); }, release: () => { log.push(`release ${id}`); }, })); const lockMap = new LockMap(); Object.assign(lockMap, ...
// Create a fake lock map that logs all acquire releases.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/test/lock_map.test.ts#L8-L21
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
Outfit.canBeModifiedBy
public canBeModifiedBy(entityId: BiomesId): boolean { return this.delta.placedBy()?.id === entityId; }
// Predicate to check if the given entity can edit the outfit.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/utils/outfit.ts#L14-L16
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
Outfit.equipToEntity
public equipToEntity(equipper: Delta) { ok(equipper.wearing(), "Equipper must have a wearing component"); const temp = this.delta.mutableWearing(); this.delta.setWearing(equipper.mutableWearing()); equipper.setWearing(temp); }
// Equip the outfit on the given entity.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/utils/outfit.ts#L19-L24
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
Outfit.addToOutfit
public addToOutfit(item: Item): Item | undefined { const equipSlot = findItemEquippableSlot(item); ok(item.isWearable, "Item must be wearable"); ok(equipSlot, "Item must have an equip slot"); const existingWearable = this.delta.mutableWearing().items.get(equipSlot); this.delta.mutableWearing().items...
// Add an item to the outfit and return the item that was replaced, if any.
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/utils/outfit.ts#L27-L35
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
tryClearTemporaryObstructions
function tryClearTemporaryObstructions( terrainIterators: Iterable<{ blockPos: ReadonlyVec3; terrain: Terrain; }>[], terrainRelevantEntities: Map<BiomesId, QueriedEntityWith<"id">> ): "blocked" | "clear" | "retry" { const blocks: { terrain: Terrain; blockPos: ReadonlyVec3 }[] = []; const entities: Que...
// Goes through the provided terrain iterators and checks each terrain point
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/utils/restoration.ts#L72-L128
14252b95bf9e68495655af40c72750e8e3c44a42
biomes-game
github_2023
ill-inc
typescript
UserRobot.addCharge
private addCharge(power: number) { const baseChargeIncrease = Math.min(this.chargeUntilFull(), power); this.setBaseCharge(this.baseCharge() + baseChargeIncrease); power -= baseChargeIncrease; for (const { ref, battery } of this.batteries()) { power = battery.addCharge(power); this.inventory...
/** * Increase the base charge of the robot until its capacity is * full. Any remaining power after that will charge batteries in the * robot's inventory. */
https://github.com/ill-inc/biomes-game/blob/14252b95bf9e68495655af40c72750e8e3c44a42/src/server/logic/utils/robot.ts#L280-L295
14252b95bf9e68495655af40c72750e8e3c44a42