mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Better buildings support
This commit is contained in:
parent
3b4417ba0b
commit
ee0770ec0b
@ -3,6 +3,7 @@ import { ModComponent } from "./mod_component";
|
||||
import { ModItem } from "./mod_item";
|
||||
import { ModProcessor } from "./mod_processor";
|
||||
import { ModSystem, ModSystemWithFilter } from "./mod_system";
|
||||
import { keyCodeOf } from "./mod_utils";
|
||||
import { gComponentRegistry, gItemRegistry, gMetaBuildingRegistry } from "../core/global_registries";
|
||||
import { GameSystemManager } from "../game/game_system_manager";
|
||||
import { GameCore } from "../game/core";
|
||||
@ -11,6 +12,7 @@ import { registerBuildingVariant } from "../game/building_codes";
|
||||
import { supportedBuildings } from "../game/hud/parts/buildings_toolbar";
|
||||
import { KEYMAPPINGS, key } from "../game/key_action_mapper";
|
||||
import { T } from "../translations";
|
||||
import { globalConfig } from "../core/config";
|
||||
|
||||
export { MetaModBuilding } from "./mod_building";
|
||||
export { ModComponent } from "./mod_component";
|
||||
@ -211,7 +213,7 @@ export async function initMods() {
|
||||
|
||||
supportedBuildings.push(building);
|
||||
|
||||
KEYMAPPINGS.buildings[base_id] = { keyCode: key(building.getKeybinding()) };
|
||||
KEYMAPPINGS.buildings[base_id] = { keyCode: keyCodeOf(building.getKeybinding()), id: base_id };
|
||||
|
||||
const translations = building.getTranslations();
|
||||
|
||||
@ -227,11 +229,7 @@ export async function initMods() {
|
||||
logger.log(mod_infos);
|
||||
}
|
||||
|
||||
for (const categoryId in KEYMAPPINGS) {
|
||||
for (const mappingId in KEYMAPPINGS[categoryId]) {
|
||||
KEYMAPPINGS[categoryId][mappingId].id = mappingId;
|
||||
}
|
||||
}
|
||||
initShapes();
|
||||
|
||||
logger.log(`${Mods.length} mods loaded`);
|
||||
}
|
||||
|
@ -6,12 +6,26 @@ import { Loader } from "../core/loader";
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* url: string
|
||||
* width: number
|
||||
* url: string,
|
||||
* width: number,
|
||||
* height: number
|
||||
* }} ExternalSpriteMeta
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* normal: ExternalSpriteMeta
|
||||
* blueprint: ExternalSpriteMeta
|
||||
* }} SpriteTypesMetas
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* default: Array<SpriteTypesMetas>
|
||||
* [variant: string]: Array<SpriteTypesMetas>
|
||||
* }} BuildingSpriteMetas
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* name: string,
|
||||
@ -21,7 +35,7 @@ import { Loader } from "../core/loader";
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* variants: {[x: string]: BuildingVariantTranslation, default: BuildingVariantTranslation},
|
||||
* variants: {[variant: string]: BuildingVariantTranslation, default: BuildingVariantTranslation},
|
||||
* keybinding: string
|
||||
* }} BuildingTranlsations
|
||||
*/
|
||||
@ -46,7 +60,7 @@ export class MetaModBuilding extends MetaBuilding {
|
||||
|
||||
/**
|
||||
* Returns the building keybinding
|
||||
* @returns {String}
|
||||
* @returns {String | number}
|
||||
*/
|
||||
static getKeybinding() {
|
||||
abstract;
|
||||
@ -54,12 +68,12 @@ export class MetaModBuilding extends MetaBuilding {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the building translations
|
||||
* Returns the building translations
|
||||
* @returns {BuildingTranlsations}
|
||||
*/
|
||||
static getTranslations() {
|
||||
abstract;
|
||||
return {variants: { default: { name: "", description: ""} }, keybinding: ""};
|
||||
return { variants: { default: { name: "", description: "" } }, keybinding: "" };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,23 +90,30 @@ export class MetaModBuilding extends MetaBuilding {
|
||||
* Returns the sprite for a given variant
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
* @param {keyof BuildingSpriteMetas} type
|
||||
* @returns {AtlasSprite}
|
||||
*/
|
||||
getSprite(rotationVariant, variant) {
|
||||
getSprite(rotationVariant, variant, type = "normal") {
|
||||
const sprite_id =
|
||||
this.id + (variant === defaultBuildingVariant ? "" : "-" + variant) + "-" + rotationVariant;
|
||||
this.id +
|
||||
(variant === defaultBuildingVariant ? "" : "-" + variant) +
|
||||
"-" +
|
||||
rotationVariant +
|
||||
"-" +
|
||||
type;
|
||||
|
||||
if (this.cachedSprites[sprite_id]) {
|
||||
return this.cachedSprites[sprite_id];
|
||||
}
|
||||
|
||||
const sprite = new AtlasSprite(sprite_id);
|
||||
this.cachedSprites[sprite_id] = sprite;
|
||||
|
||||
const meta = this.getSpriteMeta(rotationVariant, variant);
|
||||
const scales = atlasFiles.map(af => af.meta.scale);
|
||||
for (const res of scales) {
|
||||
sprite.linksByResolution[res] = Loader.spriteNotFoundSprite.linksByResolution[res];
|
||||
}
|
||||
const meta = this.getSpriteMetas()[variant][rotationVariant][type];
|
||||
const scales = atlasFiles.map(af => af.meta.scale);
|
||||
for (const res of scales) {
|
||||
sprite.linksByResolution[res] = Loader.spriteNotFoundSprite.linksByResolution[res];
|
||||
}
|
||||
|
||||
getFileAsDataURI(meta.url).then(data => {
|
||||
const img = document.createElement("img");
|
||||
@ -115,24 +136,22 @@ export class MetaModBuilding extends MetaBuilding {
|
||||
});
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
getBlueprintSprite(rotationVariant = 0, variant = defaultBuildingVariant) {
|
||||
return this.getSprite(rotationVariant, variant);
|
||||
}
|
||||
}
|
||||
|
||||
getPreviewSprite(rotationVariant = 0, variant = defaultBuildingVariant) {
|
||||
return this.getSprite(rotationVariant, variant);
|
||||
}
|
||||
getBlueprintSprite(rotationVariant = 0, variant = defaultBuildingVariant) {
|
||||
return this.getSprite(rotationVariant, variant, "blueprint");
|
||||
}
|
||||
|
||||
getPreviewSprite(rotationVariant = 0, variant = defaultBuildingVariant) {
|
||||
return this.getSprite(rotationVariant, variant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite metadata for a given variant
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
* @returns {ExternalSpriteMeta}
|
||||
* @returns {BuildingSpriteMetas}
|
||||
*/
|
||||
getSpriteMeta(rotationVariant, variant) {
|
||||
getSpriteMetas() {
|
||||
abstract;
|
||||
return { url: "", width: 0, height: 0 };
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,18 @@ export function getFileAsDataURI(url) {
|
||||
reader.readAsDataURL(blob) ;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number | string} key
|
||||
*/
|
||||
export function keyCodeOf(key) {
|
||||
if (typeof key === "number") {
|
||||
return key;
|
||||
}
|
||||
if (key.match(/F\d+/)) {
|
||||
return 111 + +key.slice(1);
|
||||
}
|
||||
return key.toUpperCase().charCodeAt(0);
|
||||
}
|
@ -19,37 +19,6 @@ if (window.coreThreadLoadedCb) {
|
||||
window.coreThreadLoadedCb();
|
||||
}
|
||||
|
||||
// Logrocket
|
||||
// if (!G_IS_DEV && !G_IS_STANDALONE) {
|
||||
// const monthlyUsers = 300; // thousand
|
||||
// const logrocketLimit = 10; // thousand
|
||||
// const percentageOfUsers = logrocketLimit / monthlyUsers;
|
||||
|
||||
// if (Math.random() <= percentageOfUsers) {
|
||||
// logger.log("Analyzing this session with logrocket");
|
||||
// const logrocket = require("logrocket");
|
||||
// logrocket.init("p1x9zh/shapezio");
|
||||
|
||||
// try {
|
||||
// logrocket.getSessionURL(function (sessionURL) {
|
||||
// logger.log("Connected lockrocket to GA");
|
||||
// // @ts-ignore
|
||||
// try {
|
||||
// window.ga("send", {
|
||||
// hitType: "event",
|
||||
// eventCategory: "LogRocket",
|
||||
// eventAction: sessionURL,
|
||||
// });
|
||||
// } catch (ex) {
|
||||
// logger.warn("Logrocket connection to analytics failed:", ex);
|
||||
// }
|
||||
// });
|
||||
// } catch (ex) {
|
||||
// logger.warn("Logrocket connection to analytics failed:", ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
console.log(
|
||||
`%cshapez.io ️%c\n© 2020 Tobias Springer IT Solutions\nCommit %c${G_BUILD_COMMIT_HASH}%c on %c${new Date(
|
||||
G_BUILD_TIME
|
||||
|
Loading…
Reference in New Issue
Block a user