Merge upstream changes to web port

This commit is contained in:
2026-01-24 15:38:47 +02:00
342 changed files with 7071 additions and 2879 deletions

View File

@@ -88,16 +88,20 @@ public class Emitter extends Group {
}
public void start( Factory factory, float interval, int quantity ) {
//by default the delay is random, up to the interval
startDelayed( factory, interval, quantity, Random.Float(interval));
}
public void startDelayed( Factory factory, float interval, int quantity, float delay ) {
this.factory = factory;
this.lightMode = factory.lightMode();
this.interval = interval;
this.quantity = quantity;
count = 0;
time = Random.Float( interval );
time = interval - delay;
on = true;
started = true;
}

View File

@@ -21,9 +21,6 @@
package com.watabou.utils;
import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue;
import com.badlogic.gdx.utils.JsonWriter;
import com.watabou.noosa.Game;
import com.watabou.utils.DeviceCompat;
@@ -43,7 +40,6 @@ import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@@ -526,20 +522,7 @@ public class Bundle {
}
String jsonString = jsonBuilder.toString();
Object json;
try {
json = new JSONTokener(jsonString).nextValue();
} catch (Exception e){
//TODO support for v1.1.X saves has been dropped, can probably remove this soon
//if the string can't be tokenized, it may be written by v1.1.X, which used libGDX JSON.
// Some of these are written in a 'minified' format, some have duplicate keys.
// We read them in with the libGDX JSON code, fix duplicates, write as full JSON
// and then try to read again with org.json
Game.reportException(e);
JsonValue gdxJSON = new JsonReader().parse(jsonString);
killDuplicateKeysInLibGDXJSON(gdxJSON);
json = new JSONTokener(gdxJSON.prettyPrint(JsonWriter.OutputType.json, 0)).nextValue();
}
Object json = new JSONTokener(jsonString).nextValue();
reader.close();
//if the data is an array, put it in a fresh object with the default key
@@ -547,6 +530,10 @@ public class Bundle {
json = new JSONObject().put( DEFAULT_KEY, json );
}
if (!(json instanceof JSONObject)){
throw new JSONException("Malformed JSON Object: " + jsonString);
}
return new Bundle( (JSONObject) json );
} catch (Exception e) {
Game.reportException(e);
@@ -554,24 +541,6 @@ public class Bundle {
}
}
private static void killDuplicateKeysInLibGDXJSON(JsonValue val){
HashSet<String> keys = new HashSet<>();
while(val != null) {
if (val.name != null && keys.contains(val.name)){
//delete the duplicate key
val.prev.next = val.next;
if (val.next != null) val.next.prev = val.prev;
val.parent.size--;
} else {
keys.add(val.name);
if (val.child != null){
killDuplicateKeysInLibGDXJSON(val.child);
}
}
val = val.next;
}
}
public static boolean write( Bundle bundle, OutputStream stream ){
return write(bundle, stream, compressByDefault);
}

View File

@@ -23,6 +23,7 @@ package com.watabou.utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.utils.Os;
import com.badlogic.gdx.utils.SharedLibraryLoader;
import com.watabou.noosa.Game;
import com.badlogic.gdx.Application;

View File

@@ -85,9 +85,9 @@ public class FileUtils {
} else if (file.length() == 0) {
file.delete();
} else {
if (file.name().endsWith(".tmp")){
if (file.name().endsWith(".spdtmp")){
FileHandle temp = file;
FileHandle original = getFileHandle( defaultFileType, "", temp.path().replace(".tmp", "") );
FileHandle original = getFileHandle( defaultFileType, "", temp.path().replace(".spdtmp", "") );
//replace the base file with the temp one if base is invalid or temp is valid and newer
try {
@@ -204,7 +204,7 @@ public class FileUtils {
//write to a temp file, then move the files.
// This helps prevent save corruption if writing is interrupted
if (file.exists()){
FileHandle temp = getFileHandle(fileName + ".tmp");
FileHandle temp = getFileHandle(fileName + ".spdtmp");
bundleToStream(temp.write(false), bundle);
file.delete();
temp.moveTo(file);