Skip to content

Commit

Permalink
AirSDK: fix cache/storage support via flash.net.SharedObject
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Feb 28, 2025
1 parent 7690818 commit c8364e0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"license": "MIT",
"tags": ["multiplayer", "networking", "websockets", "netcode"],
"description": "Colyseus Multiplayer SDK",
"version": "0.16.2",
"version": "0.16.3",
"classPath": "src/",
"releasenote": "Bring back .onChange() callback for collections.",
"releasenote": "AirSDK: fix cache/storage support via flash.net.SharedObject",
"contributors": ["endel"],
"dependencies": {
"colyseus-websocket": "1.0.14",
Expand Down
3 changes: 3 additions & 0 deletions hxml/test.flash.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hxml/test.defaults.hxml
--swf tests/bin/flash_test.swf
-swf-version 11
40 changes: 39 additions & 1 deletion src/io/colyseus/Storage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package io.colyseus;

import tink.core.Future;

#if (flash)
import flash.net.SharedObject;
#end

class Storage {
public static var PATH = "colyseus-storage";
private static var inmemoryKV: Map<String, String> = new Map<String,String>();
Expand Down Expand Up @@ -50,7 +54,41 @@ class Storage {
return storage.removeItem(PATH + ":" + name);
}

#else
#elseif (flash)

// Private helper to get the SharedObject instance
private static function getSharedObject():SharedObject {
return SharedObject.getLocal(PATH);
}

private static function getData(name:String):String {
var so:SharedObject = getSharedObject();
// Check if the key exists in the SharedObject's data

if (Reflect.hasField(so.data, name)) {
return Reflect.getProperty(so.data, name);
}
return null;
}

private static function setData(name:String, value:String):Void {
var so:SharedObject = getSharedObject();
// Set the value for the given name (key)
Reflect.setProperty(so.data, name, value);
// Save the data to disk
so.flush();
}

private static function removeData(name:String):Void {
var so:SharedObject = getSharedObject();
// Remove the specific key if it exists
if (Reflect.hasField(so.data, name)) {
Reflect.deleteField(so.data, name);
so.flush(); // Persist the change
}
}

#else

private static function getData(name:String)
{
Expand Down

0 comments on commit c8364e0

Please sign in to comment.