<commit_before>/**
 * load_resources
 *
 * Loads images, etc and tracks progress. (WIP)
 * TODO: Rely on Promises to resolve progress
 */

import { checkIfEverythingIsLoaded } from './initialization'

// Image tileset loading
// TODO: Deprecate in favor of inlined SVGs
const TILESET_IMAGE_VERSION = 55
const IMAGES_TO_BE_LOADED = [
  '/images/tiles-1.png',
  '/images/tiles-2.png',
  '/images/tiles-3.png',
  '/images/sky-front.png',
  '/images/sky-rear.png'
]

const SVGS_TO_BE_LOADED = [
  '/assets/images/icons.svg',
  '/assets/images/images.svg'
]

const SVGStagingEl = document.getElementById('svg')

export const images = [] // This is an associative array; TODO: something else
let loading = []

// Set loading bar
const loadingEl = document.getElementById('loading-progress')
loadingEl.max += 5 // Legacy; this is for other things that must load

// Global for legacy reasons
let imagesToBeLoaded = 1

export function getImagesToBeLoaded () {
  return imagesToBeLoaded
}

// Load everything
loadImages()
loadSVGs()

// When everything is loaded...
Promise.all(loading)
  .then(function () {
    imagesToBeLoaded = 0

    window.dispatchEvent(new window.CustomEvent('stmx:assets_loaded'))

    // legacy, TODO: replace with promise
    checkIfEverythingIsLoaded()
  })

function loadImages () {
  loadingEl.max += IMAGES_TO_BE_LOADED.length

  for (let url of IMAGES_TO_BE_LOADED) {
    loading.push(getImage(url + '?v' + TILESET_IMAGE_VERSION)
      .then(function (image) {
        // Store on the global images object, using the url as the key<commit_msg>adding some comments for stmt:assets_loaded event<commit_after>/**
 * load_resources
 *
 * Loads images, etc and tracks progress. (WIP)
 * TODO: Rely on Promises to resolve progress
 */

import { checkIfEverythingIsLoaded } from './initialization'

// Image tileset loading
// TODO: Deprecate in favor of inlined SVGs
const TILESET_IMAGE_VERSION = 55
const IMAGES_TO_BE_LOADED = [
  '/images/tiles-1.png',
  '/images/tiles-2.png',
  '/images/tiles-3.png',
  '/images/sky-front.png',
  '/images/sky-rear.png'
]

const SVGS_TO_BE_LOADED = [
  '/assets/images/icons.svg',
  '/assets/images/images.svg'
]

const SVGStagingEl = document.getElementById('svg')

export const images = [] // This is an associative array; TODO: something else
let loading = []

// Set loading bar
const loadingEl = document.getElementById('loading-progress')
loadingEl.max += 5 // Legacy; this is for other things that must load

// Global for legacy reasons
let imagesToBeLoaded = 1

export function getImagesToBeLoaded () {
  return imagesToBeLoaded
}

// Load everything
loadImages()
loadSVGs()

// When everything is loaded...
Promise.all(loading)
  .then(function () {
    imagesToBeLoaded = 0

    // Event stmx:assets_loaded - dispatched when all IMG and SVG assets have been loaded.
    // If you're trying to render a street thumbnail before rendering a whole street, you'll need to wait for
    // this event to be dispatched so that all IMG and SVGs can be rendered in canvas
    window.dispatchEvent(new window.CustomEvent('stmx:assets_loaded'))

    // legacy, TODO: replace with promise
    checkIfEverythingIsLoaded()
  })

function loadImages () {
  loadingEl.max += IMAGES_TO_BE_LOADED.length

  for (let url of IMAGES_TO_BE_LOADED) {
    loading.push(getImage(url + '?v' + TILESET_IMAGE_VERSION)
      .then(function (image) {
        // Store on the global images object, using the url as the key
{'fraction_non_alphanumeric': 0.11027496382054992, 'fraction_numerical': 0.004630969609261939, 'mean_word_length': 3.760330578512397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2631181', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1070, 'n_words': 320}