From 75bd2753d815d38303acd8728af6e52a3f7b0cf5 Mon Sep 17 00:00:00 2001 From: 4eb0da Date: Sun, 1 May 2022 12:22:49 +0300 Subject: [PATCH] Fix type warnings --- .eslintrc | 12 +++++++++++- docs/optframes/optframes.ts | 4 ++-- docs/preview/preview.ts | 2 +- mdl/parse.ts | 16 +++++++++------- renderer/interp.ts | 2 +- renderer/modelInterp.ts | 4 ++-- renderer/modelRenderer.ts | 2 +- renderer/particles.ts | 22 +++++++++++++++++++++- renderer/ribbons.ts | 22 +++++++++++++++++++++- 9 files changed, 69 insertions(+), 17 deletions(-) diff --git a/.eslintrc b/.eslintrc index 22c6e45..18fcdc6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,15 @@ { "parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint"], - "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"] + "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], + "rules": { + "@typescript-eslint/no-unused-vars": [ + "warn", + { + "argsIgnorePattern": "^_", + "varsIgnorePattern": "^_", + "caughtErrorsIgnorePattern": "^_" + } + ] + } } \ No newline at end of file diff --git a/docs/optframes/optframes.ts b/docs/optframes/optframes.ts index 20f1ec9..2c4f07c 100644 --- a/docs/optframes/optframes.ts +++ b/docs/optframes/optframes.ts @@ -4,7 +4,7 @@ import {parse as parseMDL} from '../../mdl/parse'; import {parse as parseMDX} from '../../mdx/parse'; import {generate as generateMDL} from '../../mdl/generate'; import {generate as generateMDX} from '../../mdx/generate'; -import {AnimKeyframe, AnimVector, Model} from '../../model'; +import {AnimKeyframe, AnimVector, Camera, Layer, Model, Node, TVertexAnim} from '../../model'; import '../common/shim'; document.addEventListener('DOMContentLoaded', function init () { @@ -130,7 +130,7 @@ document.addEventListener('DOMContentLoaded', function init () { return true; }; - const processKeys = (obj: any, key: string): void => { + const processKeys = (obj: Node | Camera | TVertexAnim | Layer, key: string): void => { const animVector: AnimVector = obj[key]; const sequences = model.Sequences; const globalSequences = model.GlobalSequences; diff --git a/docs/preview/preview.ts b/docs/preview/preview.ts index f86406b..5562865 100755 --- a/docs/preview/preview.ts +++ b/docs/preview/preview.ts @@ -369,7 +369,7 @@ function updateCanvasSize () { } function setAnimationList () { - let list: any[] = model.Sequences.map(seq => seq.Name); + let list: string[] = model.Sequences.map(seq => seq.Name); if (list.length === 0) { list = ['None']; diff --git a/mdl/parse.ts b/mdl/parse.ts index 8aaf5f2..7cde94c 100644 --- a/mdl/parse.ts +++ b/mdl/parse.ts @@ -3,7 +3,7 @@ import { CollisionShape, ParticleEmitter2, Camera, MaterialRenderMode, FilterMode, LayerShading, TextureFlags, GeosetAnimFlags, NodeFlags, CollisionShapeType, ParticleEmitter2Flags, ParticleEmitter2FramesFlags, Light, LightType, TVertexAnim, RibbonEmitter, ParticleEmitter2FilterMode, ParticleEmitter, ParticleEmitterFlags, NodeType, - EventObject, Sequence + EventObject, Sequence, ModelInfo } from '../model'; class State { @@ -23,6 +23,8 @@ class State { } } +type IntArray = number[] | Uint8Array | Uint16Array | Uint32Array | Float32Array; + function throwError (state: State, str = ''): void { throw new Error(`SyntaxError, near ${state.pos}` + (str ? ', ' + str : '')); } @@ -121,7 +123,7 @@ function parseNumber (state: State): number|null { return null; } -function parseArray (state: State, arr?: number[]|Uint8Array|Uint16Array|Uint32Array|Float32Array, pos?: number): typeof arr|null { +function parseArray (state: State, arr?: IntArray, pos?: number): typeof arr|null { if (state.char() !== '{') { return null; } @@ -178,9 +180,9 @@ function parseArrayOrSingleItem] { let prefix: string|number|null = null; - const obj = {}; + const obj: Record = {}; if (state.char() !== '{') { prefix = parseString(state); @@ -226,14 +228,14 @@ function parseVersion (state: State, model: Model): void { const [_unused, obj] = parseObject(state); if (obj.FormatVersion) { - model.Version = obj.FormatVersion; + model.Version = obj.FormatVersion as number; } } function parseModelInfo (state: State, model: Model): void { const [name, obj] = parseObject(state); - model.Info = obj; + model.Info = obj as unknown as ModelInfo; model.Info.Name = name as string; } @@ -251,7 +253,7 @@ function parseSequences (state: State, model: Model): void { obj.Name = name; obj.NonLooping = 'NonLooping' in obj; - res.push(obj); + res.push(obj as unknown as Sequence); } strictParseSymbol(state, '}'); diff --git a/renderer/interp.ts b/renderer/interp.ts index a7faae8..05c6117 100644 --- a/renderer/interp.ts +++ b/renderer/interp.ts @@ -34,7 +34,7 @@ function hermite (left: number, outTan: number, inTan: number, right: number, t: } export function findKeyframes (animVector: AnimVector, frame: number, from: number, to: number): - null | {frame: number, left: any, right: any} { + null | {frame: number, left: AnimKeyframe, right: AnimKeyframe} { if (!animVector) { return null; } diff --git a/renderer/modelInterp.ts b/renderer/modelInterp.ts index 49049ff..5829555 100644 --- a/renderer/modelInterp.ts +++ b/renderer/modelInterp.ts @@ -1,4 +1,4 @@ -import {AnimVector} from '../model'; +import {AnimKeyframe, AnimVector} from '../model'; import {findKeyframes, interpNum, interpVec3, interpQuat} from './interp'; import {vec3, quat} from 'gl-matrix'; import {RendererData} from './rendererData'; @@ -71,7 +71,7 @@ export class ModelInterp { return res; } - public findKeyframes (animVector: AnimVector): null | {frame: number, left: any, right: any} { + public findKeyframes (animVector: AnimVector): null | {frame: number, left: AnimKeyframe, right: AnimKeyframe} { if (!animVector) { return null; } diff --git a/renderer/modelRenderer.ts b/renderer/modelRenderer.ts index 333af56..d560fff 100644 --- a/renderer/modelRenderer.ts +++ b/renderer/modelRenderer.ts @@ -298,7 +298,7 @@ export class ModelRenderer { this.ribbonsController = new RibbonsController(this.interp, this.rendererData); } - public destroy () { + public destroy (): void { if (this.skeletonShaderProgram) { if (this.skeletonVertexShader) { this.gl.detachShader(this.skeletonShaderProgram, this.skeletonVertexShader); diff --git a/renderer/particles.ts b/renderer/particles.ts index 1f53c24..a48fa3c 100755 --- a/renderer/particles.ts +++ b/renderer/particles.ts @@ -11,7 +11,27 @@ import {lerp} from './interp'; let gl: WebGLRenderingContext; let shaderProgram: WebGLProgram; -const shaderProgramLocations: any = {}; +const shaderProgramLocations: { + vertexPositionAttribute: number | null; + textureCoordAttribute: number | null; + colorAttribute: number | null; + pMatrixUniform: WebGLUniformLocation | null; + mvMatrixUniform: WebGLUniformLocation | null; + samplerUniform: WebGLUniformLocation | null; + replaceableColorUniform: WebGLUniformLocation | null; + replaceableTypeUniform: WebGLUniformLocation | null; + discardAlphaLevelUniform: WebGLUniformLocation | null; +} = { + vertexPositionAttribute: null, + textureCoordAttribute: null, + colorAttribute: null, + pMatrixUniform: null, + mvMatrixUniform: null, + samplerUniform: null, + replaceableColorUniform: null, + replaceableTypeUniform: null, + discardAlphaLevelUniform: null +}; const particleStorage: Particle[] = []; const rotateCenter: vec3 = vec3.fromValues(0, 0, 0); diff --git a/renderer/ribbons.ts b/renderer/ribbons.ts index e8e51c3..1e2a164 100644 --- a/renderer/ribbons.ts +++ b/renderer/ribbons.ts @@ -5,7 +5,27 @@ import {FilterMode, Layer, LayerShading, Material, RibbonEmitter} from '../model import {mat4, vec3} from 'gl-matrix'; let gl: WebGLRenderingContext; let shaderProgram: WebGLProgram; -const shaderProgramLocations: any = {}; +const shaderProgramLocations: { + vertexPositionAttribute: number, + textureCoordAttribute: number, + pMatrixUniform: WebGLUniformLocation | null, + mvMatrixUniform: WebGLUniformLocation | null, + samplerUniform: WebGLUniformLocation | null, + replaceableColorUniform: WebGLUniformLocation | null, + replaceableTypeUniform: WebGLUniformLocation | null, + discardAlphaLevelUniform: WebGLUniformLocation | null, + colorUniform: WebGLUniformLocation | null +} = { + vertexPositionAttribute: null, + textureCoordAttribute: null, + pMatrixUniform: null, + mvMatrixUniform: null, + samplerUniform: null, + replaceableColorUniform: null, + replaceableTypeUniform: null, + discardAlphaLevelUniform: null, + colorUniform: null +}; const vertexShader = ` attribute vec3 aVertexPosition;