Change the asset keys
This commit is contained in:
@@ -73,7 +73,7 @@ export class CreditsScreen extends GuiScreen {
|
||||
}
|
||||
|
||||
#sections() {
|
||||
const sections = [{ heading: "bworld", text: AssetManager.instance.get<string>("bworld:assets_text") ?? "" }];
|
||||
const sections = [{ heading: "bworld", text: AssetManager.instance.get<string>("cubi:assets_text") ?? "" }];
|
||||
for (const mod of mod_credits) {
|
||||
sections.push({ heading: `${mod.name} ${mod.version}`, text: mod.text });
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export class GuiPlayerInventory extends GuiMenuScreen {
|
||||
#render_player(g: ModGraphics) {
|
||||
const { x, y, size } = PLAYER_BOX;
|
||||
g.rect(x, y, size, size, PLAYER_BOX_COLOR);
|
||||
const skin = this.#player.skin ?? AssetManager.instance.get<Texture>("bworld:skin");
|
||||
const skin = this.#player.skin ?? AssetManager.instance.get<Texture>("cubi:skin");
|
||||
const mouse = InputManager.get_mouse_position();
|
||||
draw_gui_player(
|
||||
skin,
|
||||
|
||||
@@ -167,7 +167,7 @@ export abstract class GuiMenuScreen extends GuiScreen {
|
||||
} else if (slot.icon) {
|
||||
// where an item's sprite would be
|
||||
const icon = get_sprite_region(slot.icon);
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
const [x, y, size] = [this.#slot_x(slot) + 3, this.#slot_y(slot) + 3, SLOT_SIZE - 6];
|
||||
draw_texture_region(atlas, icon.x, icon.y, icon.width, icon.height, x, y, size, size);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export function draw_gui_sprite(
|
||||
height?: number,
|
||||
color = [1, 1, 1, 1],
|
||||
) {
|
||||
const texture = AssetManager.instance.get<Texture>("bworld:gui");
|
||||
const texture = AssetManager.instance.get<Texture>("cubi:gui");
|
||||
const sprite = GUI_ATLAS[name];
|
||||
const [left, top, right, bottom] = sprite.border;
|
||||
draw_nine_slice(
|
||||
|
||||
@@ -121,7 +121,7 @@ export class ModGraphics implements Graphics {
|
||||
}
|
||||
|
||||
texture(id: string, x: number, y: number, w: number, h: number, part = [0, 0, 1, 1]) {
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
const region = get_sprite_region(id);
|
||||
const [u, v, pw, ph] = part;
|
||||
draw_texture_region(
|
||||
|
||||
@@ -92,7 +92,7 @@ export function draw_tooltip(lines: TooltipLine[], mouse_x: number, mouse_y: num
|
||||
y = Math.max(0, y);
|
||||
|
||||
draw_gui_sprite("tooltip", x, y, width, height);
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
lines.forEach((line, i) => {
|
||||
const line_y = y + PADDING + i * (line_height + LINE_GAP);
|
||||
if (line.icon) {
|
||||
|
||||
@@ -118,7 +118,7 @@ export const FULL_SKY_LIGHT = 15;
|
||||
// what minecraft calls the ClientLevel: this client's copy of the world, its chunks and the entities in it. the
|
||||
// chunks are what the server sent, see common/chunk_streaming.ts
|
||||
export class ClientLevel {
|
||||
image: Texture = AssetManager.instance.get("bworld:textures");
|
||||
image: Texture = AssetManager.instance.get("cubi:textures");
|
||||
chunks = new Map<number, Chunk>();
|
||||
// the chunks request_meshes and update_translucent_sorting look at, so they don't go through every chunk each frame
|
||||
#dirty = new Set<Chunk>();
|
||||
@@ -170,7 +170,7 @@ export class ClientLevel {
|
||||
type: "init",
|
||||
blocks_registry: strip_functions(EverythingRegistry.get_registry<BlockRegistry>("blocks")),
|
||||
models: Object.fromEntries(EverythingRegistry.entries<ModelJson>("models")),
|
||||
textures_info: AssetManager.instance.get("bworld:textures_info"),
|
||||
textures_info: AssetManager.instance.get("cubi:textures_info"),
|
||||
image: { width: this.image.width, height: this.image.height },
|
||||
visuals: [...block_visuals].map(([nid, visual]) => [nid, visual.replaces_model]),
|
||||
});
|
||||
|
||||
+7
-7
@@ -192,8 +192,8 @@ async function join_server(address: ServerAddress, name: string, status: (text:
|
||||
loaded_mods = true;
|
||||
const atlas_texture = load_texture(atlas.image);
|
||||
set_texture_animations(atlas_texture.tex, device.queue, atlas.animated);
|
||||
AssetManager.instance.assets["bworld:textures"] = atlas_texture;
|
||||
AssetManager.instance.assets["bworld:textures_info"] = atlas.regions;
|
||||
AssetManager.instance.assets["cubi:textures"] = atlas_texture;
|
||||
AssetManager.instance.assets["cubi:textures_info"] = atlas.regions;
|
||||
await load_client_mods(welcome.mods, bmods);
|
||||
console.log(`Mods: ${welcome.mods.map((mod) => `${mod.id} ${mod.version}`).join(", ") || "none"}`);
|
||||
|
||||
@@ -234,13 +234,13 @@ self.addEventListener("resize", resize_canvas);
|
||||
resize_canvas();
|
||||
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
|
||||
|
||||
AssetManager.instance.load("bworld:assets_text", "/assets/ASSETS.md");
|
||||
AssetManager.instance.load("cubi:assets_text", "/assets/ASSETS.md");
|
||||
|
||||
AssetManager.instance.load("bworld:skin", "/assets/sprites/skin_template.png");
|
||||
AssetManager.instance.load("bworld:gui", "/assets/sprites/gui.png");
|
||||
AssetManager.instance.load("cubi:skin", "/assets/sprites/skin_template.png");
|
||||
AssetManager.instance.load("cubi:gui", "/assets/sprites/gui.png");
|
||||
|
||||
AssetManager.instance.load("bworld:m6x11", "/assets/fonts/m6x11.png");
|
||||
AssetManager.instance.load("bworld:m6x11_fnt", "/assets/fonts/m6x11.fnt");
|
||||
AssetManager.instance.load("cubi:m6x11", "/assets/fonts/m6x11.png");
|
||||
AssetManager.instance.load("cubi:m6x11_fnt", "/assets/fonts/m6x11.fnt");
|
||||
|
||||
await AssetManager.instance.load_all();
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ let font_texture: Texture;
|
||||
let font_fnt: FntFont;
|
||||
|
||||
export function init_font() {
|
||||
font_texture = AssetManager.instance.get<Texture>("bworld:m6x11");
|
||||
font_texture = AssetManager.instance.get<Texture>("cubi:m6x11");
|
||||
|
||||
font_fnt = parse_fnt(AssetManager.instance.get("bworld:m6x11_fnt"));
|
||||
font_fnt = parse_fnt(AssetManager.instance.get("cubi:m6x11_fnt"));
|
||||
}
|
||||
|
||||
// bmfont's text format. glyphs in the image have transparent padding around them, which their offsets don't count, so
|
||||
|
||||
@@ -25,7 +25,7 @@ const PIXEL = 1 / 16;
|
||||
export function render_mod_entity(entity: RemoteEntity, camera: Camera, partial_tick: number) {
|
||||
const json = EverythingRegistry.get<EntityJson>("entities", entity.type);
|
||||
if (!json) return;
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
const region = get_sprite_region(json.texture);
|
||||
const hurt = entity.hurt_time > 0 || entity.dead ? HURT_TINT : undefined;
|
||||
const tint = entity_tint(entity, partial_tick, hurt, entity.data.on_fire === true);
|
||||
|
||||
@@ -70,7 +70,7 @@ export function gui_player_faces(skin: Texture, slim: boolean, dx: number, dy: n
|
||||
push_cube(skin, part, part.overlay, part.inflate, transform, undefined, emit_skin);
|
||||
}
|
||||
if (worn.length > 0) {
|
||||
push_worn(worn, pose, undefined, collect(AssetManager.instance.get<Texture>("bworld:textures")));
|
||||
push_worn(worn, pose, undefined, collect(AssetManager.instance.get<Texture>("cubi:textures")));
|
||||
}
|
||||
|
||||
return faces
|
||||
|
||||
@@ -64,7 +64,7 @@ export class HandRenderer {
|
||||
const tint = entity_tint(player, partial_tick);
|
||||
begin_view_model(FOV);
|
||||
if (item) {
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
set_current_texture(atlas.tex);
|
||||
const display = item_model_of(item)?.display.firstperson_righthand;
|
||||
const transform = display
|
||||
@@ -72,7 +72,7 @@ export class HandRenderer {
|
||||
: pose(item, (1 - equip) * 0.6, Math.sin(swing_progress * Math.PI));
|
||||
push_item(atlas, item, transform, tint);
|
||||
} else {
|
||||
const skin = player.skin ?? AssetManager.instance.get<Texture>("bworld:skin");
|
||||
const skin = player.skin ?? AssetManager.instance.get<Texture>("cubi:skin");
|
||||
const arm = right_arm(player.slim);
|
||||
const transform = arm_pose(arm.pivot, 1 - equip, swing_progress);
|
||||
set_current_texture(skin.tex);
|
||||
@@ -80,7 +80,7 @@ export class HandRenderer {
|
||||
push_cube(skin, arm, arm.overlay, arm.inflate, transform, tint);
|
||||
// what's worn on it goes over it, from the atlas
|
||||
if (player.worn.length > 0) {
|
||||
use_texture(AssetManager.instance.get<Texture>("bworld:textures").tex);
|
||||
use_texture(AssetManager.instance.get<Texture>("cubi:textures").tex);
|
||||
render_worn_arm(player, transform, tint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ export function ground_transform(item: ItemStack): ItemTransform {
|
||||
|
||||
// the atlas has to be the current texture
|
||||
export function render_item_entity(entity: ItemEntity, partial_tick: number) {
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
|
||||
// spinning and bobbing, like minecraft's ItemEntityRenderer
|
||||
const time = entity.age + partial_tick;
|
||||
@@ -130,7 +130,7 @@ const shown_stacks = new WeakMap<ItemData, ItemStack>();
|
||||
// every item blocks with item_display show on top of them, their "item" client data, see BlockRegistry.item_display.
|
||||
// the atlas has to be the current texture
|
||||
export function render_block_items(level: ClientLevel) {
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
const blocks = EverythingRegistry.get_registry<BlockRegistry>("blocks");
|
||||
for (const in_chunk of level.block_data.values()) {
|
||||
for (const { x, y, z, data } of in_chunk.values()) {
|
||||
|
||||
@@ -128,7 +128,7 @@ export class LevelRenderer {
|
||||
this.#drawn_entities = 0;
|
||||
if (!this.draw.entities) return;
|
||||
flush_batch();
|
||||
const default_skin = AssetManager.instance.get<Texture>("bworld:skin");
|
||||
const default_skin = AssetManager.instance.get<Texture>("cubi:skin");
|
||||
// what they wear is drawn with the atlas, after every skin
|
||||
const posed: { player: RemotePlayer; pose: PlayerPose; tint: Vec3 }[] = [];
|
||||
for (const entity of level.entities.values()) {
|
||||
@@ -203,7 +203,7 @@ export class LevelRenderer {
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
const tex = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const tex = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
const region = get_sprite_region(`cubi:break_${stage}`);
|
||||
for (const quad of this.#destroy_quads(info, value)) {
|
||||
push_decal_quad(tex, quad, x, y, z, region);
|
||||
|
||||
@@ -142,7 +142,7 @@ function draw_item_item(item: ItemStack, item_info: ItemRegistry, x: number, y:
|
||||
const draw = (texture_id: string, [r, g, b] = [1, 1, 1]) => {
|
||||
const sprite_region = get_sprite_region(texture_id);
|
||||
draw_texture_region(
|
||||
AssetManager.instance.get("bworld:textures"),
|
||||
AssetManager.instance.get("cubi:textures"),
|
||||
sprite_region.x,
|
||||
sprite_region.y,
|
||||
sprite_region.width,
|
||||
@@ -172,7 +172,7 @@ export function draw_fluid(fluid: FluidVariant, x: number, y: number, filled = 1
|
||||
const region = get_sprite_region(texture);
|
||||
const size = SLOT_SIZE - 6;
|
||||
draw_texture_region(
|
||||
AssetManager.instance.get("bworld:textures"),
|
||||
AssetManager.instance.get("cubi:textures"),
|
||||
region.x,
|
||||
region.y + region.height * (1 - done),
|
||||
region.width,
|
||||
@@ -212,7 +212,7 @@ const model_icons = new WeakMap<ItemModel, Float32Array>();
|
||||
|
||||
// an item's model in a slot: its faces that face the viewer, back to front
|
||||
function draw_item_model(model: ItemModel, x: number, y: number) {
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
use_texture(atlas.tex);
|
||||
let icon = model_icons.get(model);
|
||||
if (!icon) {
|
||||
@@ -277,7 +277,7 @@ function draw_item_block(block_info: BlockRegistry, x: number, y: number) {
|
||||
const front_texture = cube_face_texture(block_info, "front");
|
||||
const left_texture = cube_face_texture(block_info, "side");
|
||||
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
|
||||
const top = get_sprite_region(top_texture);
|
||||
const front = get_sprite_region(front_texture);
|
||||
|
||||
@@ -24,7 +24,7 @@ export function render_worn(player: Player, pose: PlayerPose, tint?: Vec3) {
|
||||
// what's worn on a player in that pose, its vertices to emit, the batch by default, like the player in the inventory
|
||||
export function push_worn(worn_items: ItemStack[], pose: PlayerPose, tint?: Vec3, emit?: VertexSink) {
|
||||
if (worn_items.length === 0) return;
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
const to_world = pose_to_world(pose);
|
||||
for (const stack of worn_items) {
|
||||
const worn = EverythingRegistry.get<ItemRegistry>("items", stack.type_id)?.worn;
|
||||
@@ -48,7 +48,7 @@ export function push_worn(worn_items: ItemStack[], pose: PlayerPose, tint?: Vec3
|
||||
// what's worn on a player's right arm, in first person, like artifacts' renderFirstPersonArm. transform is the arm's,
|
||||
// from points around its pivot (see hand_renderer's arm_pose). the atlas has to be the current texture
|
||||
export function render_worn_arm(player: Player, transform: (x: number, y: number, z: number) => Vec3, tint?: Vec3) {
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
const atlas = AssetManager.instance.get<Texture>("cubi:textures");
|
||||
const [px, py, pz] = right_arm(player.slim).pivot;
|
||||
// the model's pixels, standing still, to around the arm's pivot
|
||||
const to_arm = (x: number, y: number, z: number) => transform(x - px, y - py, z - pz);
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import { AssetManager } from "./assets.ts";
|
||||
type TexturesInfo = Record<string, SpriteRegion>;
|
||||
|
||||
export function get_sprite_region(id: string): SpriteRegion {
|
||||
const textures_info = AssetManager.instance.get<TexturesInfo>("bworld:textures_info");
|
||||
const textures_info = AssetManager.instance.get<TexturesInfo>("cubi:textures_info");
|
||||
return textures_info?.[id] ?? textures_info?.["cubi:missing"] ??
|
||||
{ x: 0, y: 0, width: TEXTURE_SIZE, height: TEXTURE_SIZE };
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ Deno.test("what the player wears is drawn on them too, with the atlas, in among
|
||||
await test_game("mods");
|
||||
const skin = { width: 64, height: 64, tex: "skin" } as unknown as Texture;
|
||||
const atlas = { width: 256, height: 256, tex: "atlas" } as unknown as Texture;
|
||||
AssetManager.instance.assets["bworld:textures"] = atlas as never;
|
||||
AssetManager.instance.assets["cubi:textures"] = atlas as never;
|
||||
// where each texture is in the atlas, none known: the renderer falls back to a spot of its own
|
||||
AssetManager.instance.assets["bworld:textures_info"] = {} as never;
|
||||
AssetManager.instance.assets["cubi:textures_info"] = {} as never;
|
||||
const plain = gui_player_faces(skin, false, 0, 0);
|
||||
const gloved = gui_player_faces(skin, false, 0, 0, [new ItemStack("artifacts:power_glove", 1)]);
|
||||
assert(plain.every((face) => face.texture === skin));
|
||||
|
||||
+1
-1
@@ -281,7 +281,7 @@ Deno.test("a broken bworld:fermentable recipe stops the server from starting", a
|
||||
// server's rules, the same as a client's
|
||||
async function drawn_juicer() {
|
||||
const { game } = await setup();
|
||||
AssetManager.instance.assets["bworld:textures_info"] = {};
|
||||
AssetManager.instance.assets["cubi:textures_info"] = {};
|
||||
const client_rules = fluid_rules;
|
||||
set_fluid_rules(game.mods.fluid_rules);
|
||||
// bworld's client script, with only what it needs for its visuals
|
||||
|
||||
@@ -74,7 +74,7 @@ async function registries() {
|
||||
write_testmod(dir);
|
||||
await test_game(dir);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
AssetManager.instance.assets["bworld:textures_info"] = {};
|
||||
AssetManager.instance.assets["cubi:textures_info"] = {};
|
||||
const nid = (id: string) => EverythingRegistry.get_id("blocks", id)!;
|
||||
const value = (id: string, state = 0) => block_value(nid(id), state);
|
||||
return { nid, value };
|
||||
@@ -336,7 +336,7 @@ Deno.test("an item is drawn the size it is on the ground, with one model for eve
|
||||
|
||||
Deno.test("a fluid's box is its texture cut to fit and tinted in its color, a model of its own that goes with it", async () => {
|
||||
const { nid, value } = await registries();
|
||||
AssetManager.instance.assets["bworld:textures_info"] = {
|
||||
AssetManager.instance.assets["cubi:textures_info"] = {
|
||||
"testmod:syrup_still": { x: 32, y: 0, width: 16, height: 16 },
|
||||
};
|
||||
let box: FluidInstance | undefined;
|
||||
@@ -434,7 +434,7 @@ Deno.test({
|
||||
shade: true,
|
||||
};
|
||||
// the atlas is just its texture
|
||||
AssetManager.instance.assets["bworld:textures_info"] = {
|
||||
AssetManager.instance.assets["cubi:textures_info"] = {
|
||||
"testmod:shaft": { x: 0, y: 0, width: 16, height: 16 },
|
||||
};
|
||||
const quads = instance_quads([quad], () => [1, 1, 1]);
|
||||
|
||||
Reference in New Issue
Block a user