Skip to content

Commit

Permalink
Fix type warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
4eb0da committed May 1, 2022
1 parent e27a0db commit 75bd275
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 17 deletions.
12 changes: 11 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -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": "^_"
}
]
}
}
4 changes: 2 additions & 2 deletions docs/optframes/optframes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion docs/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
16 changes: 9 additions & 7 deletions mdl/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 : ''));
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -178,9 +180,9 @@ function parseArrayOrSingleItem<ArrType extends Uint16Array|Uint32Array|Int32Arr
return arr;
}

function parseObject (state: State): [string|number|null, any] {
function parseObject (state: State): [string|number|null, Record<string, number | string | boolean | IntArray>] {
let prefix: string|number|null = null;
const obj = {};
const obj: Record<string, number | string | IntArray> = {};

if (state.char() !== '{') {
prefix = parseString(state);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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, '}');
Expand Down
2 changes: 1 addition & 1 deletion renderer/interp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions renderer/modelInterp.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion renderer/modelRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 21 additions & 1 deletion renderer/particles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 21 additions & 1 deletion renderer/ribbons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 75bd275

Please sign in to comment.