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 { ModItem } from "./mod_item";
|
||||||
import { ModProcessor } from "./mod_processor";
|
import { ModProcessor } from "./mod_processor";
|
||||||
import { ModSystem, ModSystemWithFilter } from "./mod_system";
|
import { ModSystem, ModSystemWithFilter } from "./mod_system";
|
||||||
|
import { keyCodeOf } from "./mod_utils";
|
||||||
import { gComponentRegistry, gItemRegistry, gMetaBuildingRegistry } from "../core/global_registries";
|
import { gComponentRegistry, gItemRegistry, gMetaBuildingRegistry } from "../core/global_registries";
|
||||||
import { GameSystemManager } from "../game/game_system_manager";
|
import { GameSystemManager } from "../game/game_system_manager";
|
||||||
import { GameCore } from "../game/core";
|
import { GameCore } from "../game/core";
|
||||||
@ -11,6 +12,7 @@ import { registerBuildingVariant } from "../game/building_codes";
|
|||||||
import { supportedBuildings } from "../game/hud/parts/buildings_toolbar";
|
import { supportedBuildings } from "../game/hud/parts/buildings_toolbar";
|
||||||
import { KEYMAPPINGS, key } from "../game/key_action_mapper";
|
import { KEYMAPPINGS, key } from "../game/key_action_mapper";
|
||||||
import { T } from "../translations";
|
import { T } from "../translations";
|
||||||
|
import { globalConfig } from "../core/config";
|
||||||
|
|
||||||
export { MetaModBuilding } from "./mod_building";
|
export { MetaModBuilding } from "./mod_building";
|
||||||
export { ModComponent } from "./mod_component";
|
export { ModComponent } from "./mod_component";
|
||||||
@ -211,7 +213,7 @@ export async function initMods() {
|
|||||||
|
|
||||||
supportedBuildings.push(building);
|
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();
|
const translations = building.getTranslations();
|
||||||
|
|
||||||
@ -227,11 +229,7 @@ export async function initMods() {
|
|||||||
logger.log(mod_infos);
|
logger.log(mod_infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const categoryId in KEYMAPPINGS) {
|
initShapes();
|
||||||
for (const mappingId in KEYMAPPINGS[categoryId]) {
|
|
||||||
KEYMAPPINGS[categoryId][mappingId].id = mappingId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.log(`${Mods.length} mods loaded`);
|
logger.log(`${Mods.length} mods loaded`);
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,26 @@ import { Loader } from "../core/loader";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* url: string
|
* url: string,
|
||||||
* width: number
|
* width: number,
|
||||||
* height: number
|
* height: number
|
||||||
* }} ExternalSpriteMeta
|
* }} ExternalSpriteMeta
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{
|
||||||
|
* normal: ExternalSpriteMeta
|
||||||
|
* blueprint: ExternalSpriteMeta
|
||||||
|
* }} SpriteTypesMetas
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{
|
||||||
|
* default: Array<SpriteTypesMetas>
|
||||||
|
* [variant: string]: Array<SpriteTypesMetas>
|
||||||
|
* }} BuildingSpriteMetas
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* name: string,
|
* name: string,
|
||||||
@ -21,7 +35,7 @@ import { Loader } from "../core/loader";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* variants: {[x: string]: BuildingVariantTranslation, default: BuildingVariantTranslation},
|
* variants: {[variant: string]: BuildingVariantTranslation, default: BuildingVariantTranslation},
|
||||||
* keybinding: string
|
* keybinding: string
|
||||||
* }} BuildingTranlsations
|
* }} BuildingTranlsations
|
||||||
*/
|
*/
|
||||||
@ -46,7 +60,7 @@ export class MetaModBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the building keybinding
|
* Returns the building keybinding
|
||||||
* @returns {String}
|
* @returns {String | number}
|
||||||
*/
|
*/
|
||||||
static getKeybinding() {
|
static getKeybinding() {
|
||||||
abstract;
|
abstract;
|
||||||
@ -54,12 +68,12 @@ export class MetaModBuilding extends MetaBuilding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the building translations
|
* Returns the building translations
|
||||||
* @returns {BuildingTranlsations}
|
* @returns {BuildingTranlsations}
|
||||||
*/
|
*/
|
||||||
static getTranslations() {
|
static getTranslations() {
|
||||||
abstract;
|
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
|
* Returns the sprite for a given variant
|
||||||
* @param {number} rotationVariant
|
* @param {number} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
|
* @param {keyof BuildingSpriteMetas} type
|
||||||
* @returns {AtlasSprite}
|
* @returns {AtlasSprite}
|
||||||
*/
|
*/
|
||||||
getSprite(rotationVariant, variant) {
|
getSprite(rotationVariant, variant, type = "normal") {
|
||||||
const sprite_id =
|
const sprite_id =
|
||||||
this.id + (variant === defaultBuildingVariant ? "" : "-" + variant) + "-" + rotationVariant;
|
this.id +
|
||||||
|
(variant === defaultBuildingVariant ? "" : "-" + variant) +
|
||||||
|
"-" +
|
||||||
|
rotationVariant +
|
||||||
|
"-" +
|
||||||
|
type;
|
||||||
|
|
||||||
if (this.cachedSprites[sprite_id]) {
|
if (this.cachedSprites[sprite_id]) {
|
||||||
return this.cachedSprites[sprite_id];
|
return this.cachedSprites[sprite_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
const sprite = new AtlasSprite(sprite_id);
|
const sprite = new AtlasSprite(sprite_id);
|
||||||
|
this.cachedSprites[sprite_id] = sprite;
|
||||||
|
|
||||||
const meta = this.getSpriteMeta(rotationVariant, variant);
|
const meta = this.getSpriteMetas()[variant][rotationVariant][type];
|
||||||
const scales = atlasFiles.map(af => af.meta.scale);
|
const scales = atlasFiles.map(af => af.meta.scale);
|
||||||
for (const res of scales) {
|
for (const res of scales) {
|
||||||
sprite.linksByResolution[res] = Loader.spriteNotFoundSprite.linksByResolution[res];
|
sprite.linksByResolution[res] = Loader.spriteNotFoundSprite.linksByResolution[res];
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileAsDataURI(meta.url).then(data => {
|
getFileAsDataURI(meta.url).then(data => {
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
@ -115,24 +136,22 @@ export class MetaModBuilding extends MetaBuilding {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
getBlueprintSprite(rotationVariant = 0, variant = defaultBuildingVariant) {
|
|
||||||
return this.getSprite(rotationVariant, variant);
|
|
||||||
}
|
|
||||||
|
|
||||||
getPreviewSprite(rotationVariant = 0, variant = defaultBuildingVariant) {
|
getBlueprintSprite(rotationVariant = 0, variant = defaultBuildingVariant) {
|
||||||
return this.getSprite(rotationVariant, variant);
|
return this.getSprite(rotationVariant, variant, "blueprint");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPreviewSprite(rotationVariant = 0, variant = defaultBuildingVariant) {
|
||||||
|
return this.getSprite(rotationVariant, variant);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the sprite metadata for a given variant
|
* Returns the sprite metadata for a given variant
|
||||||
* @param {number} rotationVariant
|
* @returns {BuildingSpriteMetas}
|
||||||
* @param {string} variant
|
|
||||||
* @returns {ExternalSpriteMeta}
|
|
||||||
*/
|
*/
|
||||||
getSpriteMeta(rotationVariant, variant) {
|
getSpriteMetas() {
|
||||||
abstract;
|
abstract;
|
||||||
return { url: "", width: 0, height: 0 };
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,18 @@ export function getFileAsDataURI(url) {
|
|||||||
reader.readAsDataURL(blob) ;
|
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();
|
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(
|
console.log(
|
||||||
`%cshapez.io ️%c\n© 2020 Tobias Springer IT Solutions\nCommit %c${G_BUILD_COMMIT_HASH}%c on %c${new Date(
|
`%cshapez.io ️%c\n© 2020 Tobias Springer IT Solutions\nCommit %c${G_BUILD_COMMIT_HASH}%c on %c${new Date(
|
||||||
G_BUILD_TIME
|
G_BUILD_TIME
|
||||||
|
Loading…
Reference in New Issue
Block a user