Quellcode durchsuchen

add `setup.mediaPathRawToString()`

(cherry picked from commit 37be5f32537530999e0a23d4f2d63ceca9fe0c83)
Stephan Fuchs vor 7 Monaten
Ursprung
Commit
e3bdf54d86

+ 1 - 1
sugarcube/src/locations/_system/locations.ts

@@ -1,6 +1,6 @@
 setup.getLocation = function(locationId){
     return setup.locations[locationId] ?? {
-        
+        image:''
     };
 }
 

+ 13 - 0
sugarcube/src/macros/media/mediaPath.ts

@@ -1,4 +1,16 @@
+setup.mediaPathRawToString = function(rawPath:ImagePath){
+    if(typeof rawPath === "string")
+        return rawPath;
+    if(Array.isArray(rawPath)){
+        const string:string = rawPath[0].toString();
+        const max:number = +rawPath[1];
+        return string.replace('#',rand(1,max).toString());
+    }
+    console.error('Unsupported type in setup.mediaPathRawToString:',rawPath,typeof rawPath);
+}
+
 setup.mediaPath = function(rawPath:string){
+    rawPath = setup.mediaPathRawToString(rawPath);
     if(rawPath.substring(0,6) == 'https:' || rawPath.substring(0,5) == 'http:')
         return rawPath;
 
@@ -7,6 +19,7 @@ setup.mediaPath = function(rawPath:string){
 }
 
 setup.mediaPathImage = function(rawPath:string){
+    rawPath = setup.mediaPathRawToString(rawPath);
     if(rawPath.substring(0,6) == 'https:' || rawPath.substring(0,5) == 'http:')
         return rawPath;