AR-js-org / AR.js-threejs

An experimental Typescript module for AR.js
MIT License
30 stars 2 forks source link

Improving the typescript code #1

Closed kalwalt closed 1 year ago

kalwalt commented 1 year ago

Improving Typescript code

I wil try to improve the existent code, developing each interfaces for every class, and writing a minimal documentation in the code. I would also make setParameters() function used internally in ArToolkitSource, ArToolkitContext, ArMarkerControls as an utility function in a separate file, to shrink the code size. This is the function:

setParameters(parameters: any) {
    if (parameters === undefined) return;
    for (var key in parameters) {
      var newValue = parameters[key];

      if (newValue === undefined) {

        console.warn("ArToolkitSource: '" + key + "' parameter is undefined.");
        continue;
      }

      //@ts-ignore
      var currentValue = this.parameters[key];

      if (currentValue === undefined) {
        console.warn(
          "ArToolkitSource: '" + key + "' is not a property of this material."
        );
        continue;
      }
      //@ts-ignore
      this.parameters[key] = newValue;
    }
  }

ARjs and THREEx namespaces

I will try also to export not only the classes but also the ARjs and THREEx namespaces, I think we can do like this:

import { ArToolkitContext as _ArToolkitContext } from "./ArToolkitContext";
import { ArToolkitProfile as _ArtoolkitProfile } from "./ArToolkitProfile";
import { ArToolkitSource as _ArToolkitSource } from "./ArToolkitSource";
import { ArMarkerControls as _ArMarkerControls  } from "./ArMarkerControls";
import { Utils as _Utils } from "./new-api/Utils";

export namespace THREEx {
  export const ArToolkitContext = _ArToolkitContext;
  export const ArToolkitProfile = _ArtoolkitProfile;
  export const ArToolkitSource  = _ArToolkitSource;
  export const ArMarkerControls = _ArMarkerControls ;
};

export namespace ARjs {
  export const Utils = _Utils;
 };