entangled-worlds-orbiters-shared 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "entangled-worlds-orbiters-shared",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Shared library for entangled worlds orbiters - contains core world rendering, moons system, and UI components",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -1,22 +1,20 @@
1
1
  /**
2
2
  * Texture Configuration Loader
3
- * Loads texture definitions from local config file or remote endpoint
3
+ * Loads texture definitions from remote endpoint or uses passed config
4
4
  */
5
5
  import { resolvePublicUrl } from './env.js';
6
6
 
7
- const DEFAULT_CONFIG_URL = '/config/textures.json';
8
- const FALLBACK_CONFIG_URL = 'https://api.entangled-worlds.com/config/textures.json'; // Future endpoint
9
-
10
7
  let cachedConfig = null;
11
8
  let configPromise = null;
9
+ let lastConfigUrl = null;
12
10
 
13
11
  /**
14
- * Load texture configuration from local file or remote endpoint
15
- * @param {string} configUrl - Override default config URL
12
+ * Load texture configuration from remote endpoint or use passed config
13
+ * @param {string} configUrl - Override config URL
16
14
  * @param {boolean} useCache - Whether to use cached config if available
17
15
  * @returns {Promise<Object>} Texture configuration object
18
16
  */
19
- export async function loadTextureConfig(configUrl = DEFAULT_CONFIG_URL, useCache = true) {
17
+ export async function loadTextureConfig(configUrl = null, useCache = true) {
20
18
  if (useCache && cachedConfig) {
21
19
  return cachedConfig;
22
20
  }
@@ -25,11 +23,19 @@ export async function loadTextureConfig(configUrl = DEFAULT_CONFIG_URL, useCache
25
23
  return configPromise;
26
24
  }
27
25
 
26
+ if (configUrl) {
27
+ lastConfigUrl = configUrl;
28
+ }
29
+
30
+ const targetUrl = configUrl || lastConfigUrl;
31
+
28
32
  configPromise = (async () => {
29
33
  try {
30
- // Resolve config URL against public base if it's a relative path
31
- const resolvedConfigUrl = /^https?:\/\//i.test(configUrl) ? configUrl : resolvePublicUrl(configUrl);
32
- const response = await fetch(resolvedConfigUrl);
34
+ if (!targetUrl) {
35
+ throw new Error('No texture config URL provided');
36
+ }
37
+
38
+ const response = await fetch(targetUrl);
33
39
 
34
40
  if (!response.ok) {
35
41
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
@@ -46,19 +52,10 @@ export async function loadTextureConfig(configUrl = DEFAULT_CONFIG_URL, useCache
46
52
  return config;
47
53
  } catch (error) {
48
54
  console.error('[TextureConfig] Failed to load config:', error);
49
-
50
- // If primary URL fails and it's not already the fallback, try fallback
51
- if (configUrl !== FALLBACK_CONFIG_URL) {
52
- try {
53
- return await loadTextureConfig(FALLBACK_CONFIG_URL, false);
54
- } catch (fallbackError) {
55
- console.error('[TextureConfig] Fallback also failed:', fallbackError);
56
- }
57
- }
58
-
59
- // Return minimal fallback configuration
55
+ // Return minimal fallback configuration when loading fails
60
56
  console.warn('[TextureConfig] Using hardcoded fallback config');
61
- return getHardcodedFallback();
57
+ cachedConfig = getHardcodedFallback();
58
+ return cachedConfig;
62
59
  } finally {
63
60
  configPromise = null;
64
61
  }
@@ -267,10 +264,10 @@ function getHardcodedFallback() {
267
264
  * @param {string} configUrl - Override config URL
268
265
  * @returns {Promise<Object>} Fresh configuration object
269
266
  */
270
- export async function reloadTextureConfig(configUrl = DEFAULT_CONFIG_URL) {
267
+ export async function reloadTextureConfig(configUrl = null) {
271
268
  cachedConfig = null;
272
269
  configPromise = null;
273
- return loadTextureConfig(configUrl, false);
270
+ return loadTextureConfig(configUrl || lastConfigUrl, false);
274
271
  }
275
272
 
276
273
  /**