<commit_before>import DebuggerModuleBase from "./DebuggerModuleBase";
import Debugger from "../Debugger";
import SceneManager from "../../Core/SceneManager";
import JThreeContext from "../../JThreeContext";
import ContextComponents from "../../ContextComponents";
import Scene from "../../Core/Scene";
import BasicRenderer from "../../Core/Renderers/BasicRenderer";
import Q from "q";
import IRequestBufferTexture from "./Renderer/IRequestBufferTexture";
import IRequestShadowMapTexture from "./Renderer/IRequestShadowMapTexture";
import IRequestBufferTextureProgress from "./Renderer/IRequestBufferTextureProgress";
import IRequestShadowMapProgress from "./Renderer/IRequestShadowMapProgress";
class RendererDebugger extends DebuggerModuleBase {
  private _bufferTextureRequest: IRequestBufferTexture;

  private _shadowMapRequest: IRequestShadowMapTexture;

  private _bufferTextureProgressRequest: IRequestBufferTextureProgress;

  private _shadowMapProgressRequest: IRequestShadowMapProgress;

  public attach(debug: Debugger): void {
    const sm = JThreeContext.getContextComponent<SceneManager>(ContextComponents.SceneManager);
    sm.Scenes.forEach(s => {
      this._attachToScene(s, debug);
    });
    sm.on("change", (h) => {
      if (h.isAdditionalChange) {
        this._attachToScene(h.changedScene, debug);
      } else {
        // TODO add code for delete
      }
    });
  }

  public getShadowMapImage(rendererID: string, generator?: any): Q.IPromise<HTMLImageElement> {
    const d = Q.defer<HTMLImageElement>();
    this._shadowMapRequest = {
      deffered: d,
      rendererID: rendererID,
      generator: generator
    };
    return d.promise;
  }

  public getShadowMapProgressImage(rendererID: string, generator?: any): Q.IPromise<HTMLImageElement> {
    const d = Q.defer<HTMLImageElement>();
    this._shadowMapProgressRequest = {
      deffered: d,
      rendererID: rendererID,
      generator: generator,
      begin: false
    };
    return d.promise;
  }

  public getTextureHtmlImage(stageID: string, bufferTextureID: string, generator?: any): Q.IPromise<HTMLImageElement> {
    const d = Q.defer<HTMLImageElement>();
    this._bufferTextureRequest = {
      deffered: d,
      stageID: stageID,
      bufferTextureID: bufferTextureID,
      generator: generator
    };
    return d.promise;
  }

  public getTextureProgressHtmlImage(stageID: string, bufferTextureID: string, generator?: any): Q.IPromise<HTMLImageElement> {
    const d = Q.defer<HTMLImageElement>();
    this._bufferTextureProgressRequest = {
      deffered: d,
      stageID: stageID,
      bufferTextureID: bufferTextureID,
      generator: generator,
      begin: false
    };
    return d.promise;
  }

  private _attachToScene(scene: Scene, debug: Debugger): void {
    scene.Renderers.forEach(r => {
      this._attachToRenderer(r, debug);
    });
    scene.on("changed-renderer", (h) => {
      if (h.isAdditionalChange) {
        this._attachToRenderer(h.renderer, debug);
      } else {
        // TODO add code for delete
      }
    });
  }

  private _canvasToimg(renderer: BasicRenderer): HTMLImageElement {
    const canvas = renderer.Canvas;
    const img = new Image(canvas.canvasElement.width, canvas.canvasElement.height);
    img.src = canvas.canvasElement.toDataURL();
    return img;
  }

  private _attachToRenderer(renderer: BasicRenderer, debug: Debugger): void {
    debug.debuggerAPI.renderers.addRenderer(renderer, this);
    renderer.on("rendered-stage", (v) => {
      if (this._bufferTextureRequest && v.completedChain.stage.ID === this._bufferTextureRequest.stageID) {
       debugger;
        if (v.bufferTextures[this._bufferTextureRequest.bufferTextureID] == null) {
          this._bufferTextureRequest.deffered.resolve(this._canvasToimg(renderer));
          this._bufferTextureRequest = null;
          return;
        }
        this._bufferTextureRequest.deffered.resolve(v.bufferTextures[this._bufferTextureRequest.bufferTextureID].wrappers[0].generateHtmlImage(this._bufferTextureRequest.generator));
        this._bufferTextureRequest = null;
      }
    });
    renderer.on("rendered-path", (v) => {
      if (this._shadowMapRequest && renderer.ID === this._shadowMapRequest.rendererID) {
        // this.shadowMapRequest.deffered.resolve(v.scene.LightRegister.shadowMapResourceManager.shadowMapTileTexture.wrappers[0].generateHtmlImage(this.shadowMapRequest.generator));
        this._shadowMapRequest = null;
      }<commit_msg>fix for linter<commit_after>import DebuggerModuleBase from "./DebuggerModuleBase";
import Debugger from "../Debugger";
import SceneManager from "../../Core/SceneManager";
import JThreeContext from "../../JThreeContext";
import ContextComponents from "../../ContextComponents";
import Scene from "../../Core/Scene";
import BasicRenderer from "../../Core/Renderers/BasicRenderer";
import Q from "q";
import IRequestBufferTexture from "./Renderer/IRequestBufferTexture";
import IRequestShadowMapTexture from "./Renderer/IRequestShadowMapTexture";
import IRequestBufferTextureProgress from "./Renderer/IRequestBufferTextureProgress";
import IRequestShadowMapProgress from "./Renderer/IRequestShadowMapProgress";
class RendererDebugger extends DebuggerModuleBase {
  private _bufferTextureRequest: IRequestBufferTexture;

  private _shadowMapRequest: IRequestShadowMapTexture;

  private _bufferTextureProgressRequest: IRequestBufferTextureProgress;

  private _shadowMapProgressRequest: IRequestShadowMapProgress;

  public attach(debug: Debugger): void {
    const sm = JThreeContext.getContextComponent<SceneManager>(ContextComponents.SceneManager);
    sm.Scenes.forEach(s => {
      this._attachToScene(s, debug);
    });
    sm.on("change", (h) => {
      if (h.isAdditionalChange) {
        this._attachToScene(h.changedScene, debug);
      } else {
        // TODO add code for delete
      }
    });
  }

  public getShadowMapImage(rendererID: string, generator?: any): Q.IPromise<HTMLImageElement> {
    const d = Q.defer<HTMLImageElement>();
    this._shadowMapRequest = {
      deffered: d,
      rendererID: rendererID,
      generator: generator
    };
    return d.promise;
  }

  public getShadowMapProgressImage(rendererID: string, generator?: any): Q.IPromise<HTMLImageElement> {
    const d = Q.defer<HTMLImageElement>();
    this._shadowMapProgressRequest = {
      deffered: d,
      rendererID: rendererID,
      generator: generator,
      begin: false
    };
    return d.promise;
  }

  public getTextureHtmlImage(stageID: string, bufferTextureID: string, generator?: any): Q.IPromise<HTMLImageElement> {
    const d = Q.defer<HTMLImageElement>();
    this._bufferTextureRequest = {
      deffered: d,
      stageID: stageID,
      bufferTextureID: bufferTextureID,
      generator: generator
    };
    return d.promise;
  }

  public getTextureProgressHtmlImage(stageID: string, bufferTextureID: string, generator?: any): Q.IPromise<HTMLImageElement> {
    const d = Q.defer<HTMLImageElement>();
    this._bufferTextureProgressRequest = {
      deffered: d,
      stageID: stageID,
      bufferTextureID: bufferTextureID,
      generator: generator,
      begin: false
    };
    return d.promise;
  }

  private _attachToScene(scene: Scene, debug: Debugger): void {
    scene.Renderers.forEach(r => {
      this._attachToRenderer(r, debug);
    });
    scene.on("changed-renderer", (h) => {
      if (h.isAdditionalChange) {
        this._attachToRenderer(h.renderer, debug);
      } else {
        // TODO add code for delete
      }
    });
  }

  private _canvasToimg(renderer: BasicRenderer): HTMLImageElement {
    const canvas = renderer.Canvas;
    const img = new Image(canvas.canvasElement.width, canvas.canvasElement.height);
    img.src = canvas.canvasElement.toDataURL();
    return img;
  }

  private _attachToRenderer(renderer: BasicRenderer, debug: Debugger): void {
    debug.debuggerAPI.renderers.addRenderer(renderer, this);
    renderer.on("rendered-stage", (v) => {
      if (this._bufferTextureRequest && v.completedChain.stage.ID === this._bufferTextureRequest.stageID) {
        if (v.bufferTextures[this._bufferTextureRequest.bufferTextureID] == null) {
          this._bufferTextureRequest.deffered.resolve(this._canvasToimg(renderer));
          this._bufferTextureRequest = null;
          return;
        }
        this._bufferTextureRequest.deffered.resolve(v.bufferTextures[this._bufferTextureRequest.bufferTextureID].wrappers[0].generateHtmlImage(this._bufferTextureRequest.generator));
        this._bufferTextureRequest = null;
      }
    });
    renderer.on("rendered-path", (v) => {
      if (this._shadowMapRequest && renderer.ID === this._shadowMapRequest.rendererID) {
        // this.shadowMapRequest.deffered.resolve(v.scene.LightRegister.shadowMapResourceManager.shadowMapTileTexture.wrappers[0].generateHtmlImage(this.shadowMapRequest.generator));
        this._shadowMapRequest = null;
      }
{'fraction_non_alphanumeric': 0.1128887894383531, 'fraction_numerical': 0.00044752741105392703, 'mean_word_length': 3.818867924528302, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6944386', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2491, 'n_words': 483}