Skip to content

Commit

Permalink
chore: improve eslint setup
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Mar 21, 2022
1 parent 843aabe commit 426e080
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 43 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cache/
dist/
node_modules/
.eslintrc.js
8 changes: 6 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
const path = require('path');
module.exports = {
env: {
browser: true
browser: true,
node: true
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'prettier'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
project: path.resolve(__dirname, './tsconfig.json'),
tsconfigRootDir: __dirname,
tsconfigRootDir: __dirname
},
rules: {}
};
15 changes: 8 additions & 7 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "none",
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "avoid"
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "es5",
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "avoid",
"endOfLine": "lf"
}
11 changes: 9 additions & 2 deletions scripts/generateTransparentList.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs/promises');

/**
Expand All @@ -17,8 +18,14 @@ async function doTheFilter() {
const transparent = data
.filter(bl => bl.material.opaque === false || bl.id.includes('door'))
.map(bl => bl.id.replace('minecraft:', ''));
await fs.writeFile('../src/renderer/nonOccluding.json', JSON.stringify(nonOccluding));
await fs.writeFile('../src/renderer/transparent.json', JSON.stringify(transparent));
await fs.writeFile(
'../src/renderer/nonOccluding.json',
JSON.stringify(nonOccluding)
);
await fs.writeFile(
'../src/renderer/transparent.json',
JSON.stringify(transparent)
);
}

doTheFilter();
14 changes: 7 additions & 7 deletions src/renderer/model/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
SubMesh,
Texture,
Vector3,
Vector4
Vector4,
} from 'babylonjs';
import { InstancedMesh } from 'babylonjs/Meshes/instancedMesh';
import deepmerge from 'deepmerge';
Expand All @@ -27,7 +27,7 @@ import {
BlockStateDefinitionVariant,
BlockStateModelHolder,
POSSIBLE_FACES,
Vector
Vector,
} from './types';

const TINT_COLOR = new Color4(145 / 255, 189 / 255, 89 / 255, 1);
Expand Down Expand Up @@ -153,11 +153,11 @@ export function getModelLoader(resourceLoader: ResourceLoader): ModelLoader {

if (blockState.variants?.['']) {
models.push({
options: createWeightedModels(blockState.variants[''])
options: createWeightedModels(blockState.variants['']),
});
} else if (blockState.variants) {
models.push({
options: createWeightedModels(blockState.variants[variantName])
options: createWeightedModels(blockState.variants[variantName]),
});
} else if (blockState.multipart) {
const doesFilterPass = (
Expand Down Expand Up @@ -297,7 +297,7 @@ export function getModelLoader(resourceLoader: ResourceLoader): ModelLoader {
const elementSize = [
element.to[0] - element.from[0],
element.to[1] - element.from[1],
element.to[2] - element.from[2]
element.to[2] - element.from[2],
];

const colours = [];
Expand Down Expand Up @@ -360,7 +360,7 @@ export function getModelLoader(resourceLoader: ResourceLoader): ModelLoader {
wrap: true,
faceColors: hasColor ? colours : undefined,
updatable: false,
faceUV: uvs
faceUV: uvs,
},
scene
);
Expand Down Expand Up @@ -496,6 +496,6 @@ export function getModelLoader(resourceLoader: ResourceLoader): ModelLoader {
clearCache,
getBlockModelData,
getModelOption,
getModel
getModel,
};
}
9 changes: 8 additions & 1 deletion src/renderer/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ export interface BlockStateDefinition {

export type Vector = [number, number, number];

export const POSSIBLE_FACES = ['south', 'north', 'east', 'west', 'up', 'down'] as const;
export const POSSIBLE_FACES = [
'south',
'north',
'east',
'west',
'up',
'down',
] as const;
export type Faces = typeof POSSIBLE_FACES[number] | 'bottom';

export interface BlockModel {
Expand Down
18 changes: 9 additions & 9 deletions src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
faceToFacingVector,
INVISIBLE_BLOCKS,
NON_OCCLUDING_BLOCKS,
parseNbt
parseNbt,
} from './utils';
import {
Engine,
Expand All @@ -18,7 +18,7 @@ import {
HemisphericLight,
Color3,
Color4,
Mesh
Mesh,
} from 'babylonjs';
import { loadBlockStateDefinition } from './model/parser';
import { addArrowToScene, addBarsToScene } from './shapes';
Expand All @@ -41,12 +41,12 @@ export async function renderSchematic(
antialias = false,
backgroundColor = 0xffffff,
debug = false,
disableAutoRender = false
disableAutoRender = false,
}: SchematicRenderOptions
): Promise<SchematicHandles> {
const engine = new Engine(canvas, antialias, {
alpha: backgroundColor !== 'transparent',
powerPreference: 'high-performance'
powerPreference: 'high-performance',
});
if (size) {
if (typeof size === 'number') {
Expand All @@ -60,7 +60,7 @@ export async function renderSchematic(
}

const scene = new Scene(engine, {
useGeometryUniqueIdsMap: true
useGeometryUniqueIdsMap: true,
});

scene.ambientColor = new Color3(0.5, 0.5, 0.5);
Expand Down Expand Up @@ -104,7 +104,7 @@ export async function renderSchematic(
const {
width: worldWidth,
height: worldHeight,
length: worldLength
length: worldLength,
} = loadedSchematic;

const cameraOffset = Math.max(worldWidth, worldLength, worldHeight) / 2 + 1;
Expand All @@ -120,7 +120,7 @@ export async function renderSchematic(

const resourceLoader = await getResourceLoader([
`${corsBypassUrl}${versionManifestFile?.[0]?.clientJarUrl ?? URL_1_13}`,
...(resourcePacks ?? [])
...(resourcePacks ?? []),
]);
const modelLoader = getModelLoader(resourceLoader);

Expand Down Expand Up @@ -166,7 +166,7 @@ export async function renderSchematic(
const offBlock = loadedSchematic.getBlock({
x: x + faceOffset[0],
y: y + faceOffset[1],
z: z + faceOffset[2]
z: z + faceOffset[2],
});

if (!offBlock || NON_OCCLUDING_BLOCKS.has(offBlock.type)) {
Expand Down Expand Up @@ -240,6 +240,6 @@ export async function renderSchematic(
render,
getEngine(): Engine {
return engine;
}
},
};
}
4 changes: 2 additions & 2 deletions src/renderer/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function addArrowToScene(scene: Scene, cameraOffset: number): void {
diameterBottom: cameraOffset / 2,
height: cameraOffset / 200,
tessellation: 3,
subdivisions: 1
subdivisions: 1,
},
scene
);
Expand Down Expand Up @@ -40,7 +40,7 @@ export function addBarsToScene(
diameterBottom: cameraOffset / 400,
height: 1,
tessellation: 3,
subdivisions: 1
subdivisions: 1,
},
scene
);
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Engine } from "babylonjs";
import { Engine } from 'babylonjs';

export interface SchematicHandles {
/**
Expand All @@ -7,7 +7,7 @@ export interface SchematicHandles {
resize(size: number): void;
/**
* Set the size of the renderer.
*
*
* @param width The width
* @param height The height
*/
Expand All @@ -18,13 +18,13 @@ export interface SchematicHandles {
destroy(): void;
/**
* Call this to manually render the scene.
*
*
* To disable automatic rendering and purely rely on this function, see {@link SchematicRenderOptions#disableAutoRender}.
*/
render(): void;
/**
* Gets the internal BabylonJS engine.
*
*
* Note: This method is provided for advanced use cases and should not be used in most cases.
*/
getEngine(): Engine;
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ export const INVISIBLE_BLOCKS = new Set([
'void_air',
'structure_void',
'barrier',
'light'
'light',
]);

export const TRANSPARENT_BLOCKS = new Set([
...INVISIBLE_BLOCKS,
...TransparentBlocks
...TransparentBlocks,
]);

export const NON_OCCLUDING_BLOCKS = new Set([
...INVISIBLE_BLOCKS,
...NonOccludingBlocks
...NonOccludingBlocks,
]);

export function parseNbt(nbt: string): TagMap {
const buff = Buffer.from(nbt, 'base64');
const deflated = Buffer.from(unzip(buff));
const data = decode(deflated, {
unnamed: false,
useMaps: true
useMaps: true,
});
return data.value as TagMap;
}
2 changes: 1 addition & 1 deletion src/resource/resourceLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ export async function getResourceLoader(
return {
getResourceBlob,
getResourceString,
clearCache
clearCache,
};
}
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["src/**/*"],
"include": ["src/**/*", "scripts/generateTransparentList.js"],
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
Expand All @@ -14,7 +14,5 @@
"declaration": true
},
"exclude": ["node_modules", "dist"],
"types": [
"babylonjs"
]
"types": ["babylonjs"]
}

0 comments on commit 426e080

Please sign in to comment.