public async Task ExampleUsage2() { // Get your key from https://console.developers.google.com/apis/credentials var apiKey = "AIzaSyCtcFQMgRIUHhSuXggm4BtXT4eZvUrBWN0"; // See https://docs.google.com/spreadsheets/d/1Hwu4ZtRR0iXD65Wuj_XyJxLw4PN8SE0sRgnBKeVoq3A var sheetId = "1Hwu4ZtRR0iXD65Wuj_XyJxLw4PN8SE0sRgnBKeVoq3A"; var sheetName = "MySheet1"; // Has to match the sheet name IKeyValueStore onlineNewsStore = new GoogleSheetsKeyValueStore(new InMemoryKeyValueStore(), apiKey, sheetId, sheetName); IKeyValueStore onDeviceEventsStore = new InMemoryKeyValueStore(); IKeyValueStore newsStore = new DualStore(onlineNewsStore, onDeviceEventsStore); var newsLocalDataStore = new InMemoryKeyValueStore().GetTypeAdapter <News.LocalData>(); NewsManager manager = new NewsManager(newsLocalDataStore, newsStore.GetTypeAdapter <News>()); var title = "First App Start"; var descr = "You just started the app the first time!"; var url = "https://github.com/cs-util-com/cscore"; var urlText = "Show details.."; News n = News.NewLocalNewsEvent(title, descr, url, urlText); await onDeviceEventsStore.Set(n.key, n); IEnumerable <News> allNews = await manager.GetAllNews(); Assert.Contains(allNews, x => x.title == title); Log.d(JsonWriter.AsPrettyString(allNews)); IEnumerable <News> unreadNews = await manager.GetAllUnreadNews(); Assert.Contains(unreadNews, x => x.title == title); }
public async Task TestDualStore() { var firstStore = new InMemoryKeyValueStore(); var secondStor = new InMemoryKeyValueStore(); var dualStore = new DualStore(firstStore, secondStor); var key1 = "key1"; var key2 = "key2"; var value1 = "v1"; var fallb1 = "f1"; Assert.False(await dualStore.ContainsKey(key1)); Assert.Null(await dualStore.Set(key1, value1)); Assert.True(await dualStore.ContainsKey(key1)); Assert.True(await firstStore.ContainsKey(key1)); Assert.False(await secondStor.ContainsKey(key1)); Assert.Single(await dualStore.GetAllKeys()); Assert.Single(await firstStore.GetAllKeys()); Assert.Empty(await secondStor.GetAllKeys()); Assert.Equal(value1, await dualStore.Get(key1, fallb1)); Assert.Equal(value1, await firstStore.Get(key1, fallb1)); Assert.Equal(fallb1, await secondStor.Get(key1, fallb1)); Assert.Equal(fallb1, await dualStore.Get(key2, fallb1)); Assert.True(await dualStore.Remove(key1)); Assert.Equal(fallb1, await dualStore.Get(key1, fallb1)); Assert.Equal(fallb1, await firstStore.Get(key1, fallb1)); Assert.False(await dualStore.Remove(key2)); }
public static NewsManager NewManagerViaGSheets(string apiKey, string sheetId, string sheetName, IKeyValueStore onDeviceEventsStore) { var newsDir = EnvironmentV2.instance.GetOrAddTempFolder("NewsManagerCache"); var gSheetsCache = new FileBasedKeyValueStore(newsDir.GetChildDir("GSheetsData")); var newsLocalDataCache = new FileBasedKeyValueStore(newsDir.GetChildDir("LocalData")); IKeyValueStore newsStore = new GoogleSheetsKeyValueStore(gSheetsCache, apiKey, sheetId, sheetName); if (onDeviceEventsStore != null) { newsStore = new DualStore(newsStore, onDeviceEventsStore); } return(new NewsManager(newsLocalDataCache.GetTypeAdapter <News.LocalData>(), newsStore.GetTypeAdapter <News>())); }
/// <summary> /// Gets all tiles of a specific set type. /// </summary> /// <param name="allTiles"></param> /// <param name="type"></param> /// <returns></returns> protected virtual DualStore <TileDetails, GameObject> GetTileSetType(DualStore <TileDetails, GameObject> allTiles, TileSetType type) { DualStore <TileDetails, GameObject> thisTileset = new DualStore <TileDetails, GameObject>(); foreach (KeyValuePair <TileDetails, GameObject> kv in allTiles.KeyValuePairs) { if (kv.Key.Type == type) { thisTileset.Add(kv.Key, kv.Value); } } return(thisTileset); }
/// <summary> /// gets all the tiles of a specific tiletype. /// </summary> /// <param name="tiles"></param> /// <param name="type"></param> /// <returns></returns> protected virtual List <GameObject> GetTileTypes(DualStore <TileDetails, GameObject> tiles, TileType type) { List <GameObject> thetiles = new List <GameObject>(); foreach (KeyValuePair <TileDetails, GameObject> kv in tiles.KeyValuePairs) { if (kv.Key.TileType == type) { thetiles.Add(kv.Value); } } return(thetiles); }
/// <summary> /// Retrieves the tileset from all the different tilesets. /// </summary> /// <param name="allTiles"></param> /// <returns></returns> protected virtual DualStore <TileDetails, GameObject> GetTileset(DualStore <TileDetails, GameObject> allTiles) { //choose a tileset to play on. int tileSetNo = UnityEngine.Random.Range(0, TileSets.Count); string tileSet = TileSets[tileSetNo]; DualStore <TileDetails, GameObject> thisTileset = new DualStore <TileDetails, GameObject>(); foreach (KeyValuePair <TileDetails, GameObject> kv in allTiles.KeyValuePairs) { if (kv.Key.TileSet == tileSet) { thisTileset.Add(kv.Key, kv.Value); } } return(thisTileset); }
/// <summary> /// Retrieves the tileset from all the different tilesets. /// </summary> /// <param name="allTiles"></param> /// <returns></returns> protected virtual DualStore<TileDetails, GameObject> GetTileset(DualStore<TileDetails, GameObject> allTiles) { //choose a tileset to play on. int tileSetNo = UnityEngine.Random.Range(0, TileSets.Count); string tileSet = TileSets[tileSetNo]; DualStore<TileDetails, GameObject> thisTileset = new DualStore<TileDetails, GameObject>(); foreach (KeyValuePair<TileDetails, GameObject> kv in allTiles.KeyValuePairs) { if (kv.Key.TileSet == tileSet) { thisTileset.Add(kv.Key, kv.Value); } } return thisTileset; }
public override void OnStartServer() { if (!isServer) { return; } int seed = UnityEngine.Random.seed; rand = new System.Random(seed); //splits all the objects into something I can search with. DualStore <TileDetails, GameObject> gameObjects = new DualStore <TileDetails, GameObject>(); foreach (GameObject obj in TileTypes) { TileDetails details = obj.GetComponent <TileDetails>(); gameObjects.Add(details, obj); } gameObjects = GetTileset(gameObjects); Dictionary <TileSetType, TileLevel> tilesByTileSetType = new Dictionary <TileSetType, TileLevel>(); foreach (TileSetType type in Enum.GetValues(typeof(TileSetType))) { TileLevel level = new TileLevel(seed); DualStore <TileDetails, GameObject> tileSetTiles = GetTileSetType(gameObjects, type); foreach (TileType ttype in Enum.GetValues(typeof(TileType))) { level.AssignTiles(ttype, GetTileTypes(tileSetTiles, ttype)); } tilesByTileSetType.Add(type, level); } SpawnTiles(tilesByTileSetType); }
public override void OnStartServer() { if (!isServer) return; int seed = UnityEngine.Random.seed; rand = new System.Random(seed); //splits all the objects into something I can search with. DualStore<TileDetails, GameObject> gameObjects = new DualStore<TileDetails, GameObject>(); foreach(GameObject obj in TileTypes) { TileDetails details = obj.GetComponent<TileDetails>(); gameObjects.Add(details, obj); } gameObjects = GetTileset(gameObjects); Dictionary<TileSetType, TileLevel> tilesByTileSetType = new Dictionary<TileSetType, TileLevel>(); foreach(TileSetType type in Enum.GetValues(typeof(TileSetType))) { TileLevel level = new TileLevel(seed); DualStore<TileDetails, GameObject> tileSetTiles = GetTileSetType(gameObjects, type); foreach(TileType ttype in Enum.GetValues(typeof(TileType))) { level.AssignTiles(ttype, GetTileTypes(tileSetTiles, ttype)); } tilesByTileSetType.Add(type, level); } SpawnTiles(tilesByTileSetType); }
/// <summary> /// Creates an instantites the tiles. /// </summary> /// <param name="map"></param> /// <param name="dividerLevel"></param> /// <param name="availiableTile"></param> protected virtual void GenerateElevators(TileType[,] map, int dividerLevel, Dictionary <TileSetType, TileLevel> availiableTile) { List <Vector2> leftEnds = new List <Vector2>(); List <Vector2> rightEnds = new List <Vector2>(); for (int xdx = 0; xdx < map.GetLength(0); xdx++) { for (int ydx = 0; ydx < map.GetLength(1); ydx++) { TileType type = map[xdx, ydx]; if (type == TileType.LeftEnd) { leftEnds.Add(new Vector2(xdx, ydx)); } else if (type == TileType.RightEnd) { rightEnds.Add(new Vector2(xdx, ydx)); } } } DualStore <Vector2, Vector2> veritcal = new DualStore <Vector2, Vector2>(); foreach (Vector2 vec in rightEnds) { int xdx = (int)vec.x + 1; //int ydx = (int)vec.y; for (int ydx = (int)vec.y - 1; ydx > 0; ydx--) { if (map[xdx, ydx] != TileType.None) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1)); ydx = -1; } else if (map[xdx - 1, ydx] == TileType.RightEnd) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx)); ydx = -1; } else if (map[xdx + 1, ydx] == TileType.LeftEnd) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx)); ydx = -1; } } } foreach (Vector2 vec in leftEnds) { int xdx = (int)vec.x - 1; //int ydx = (int)vec.y; for (int ydx = (int)vec.y - 1; ydx > 0; ydx--) { if (map[xdx, ydx] != TileType.None) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1)); ydx = -1; } else if (map[xdx - 1, ydx] == TileType.RightEnd) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx)); ydx = -1; } else if (map[xdx + 1, ydx] == TileType.LeftEnd) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx)); ydx = -1; } } } foreach (KeyValuePair <Vector2, Vector2> kv in veritcal.KeyValuePairs) { TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels; GameObject obj = availiableTile[level].GetTileType(TileType.Platform); var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion()); ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement; move.EndPos = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize); move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize); move.moveDir = MovementDirection.updown; //ElevatorMovement move = tile.GetComponent<ElevatorMovement>(); Debug.Log(tile); NetworkServer.Spawn(tile); } DualStore <Vector2, Vector2> horizontal = new DualStore <Vector2, Vector2>(); foreach (Vector2 vec in rightEnds) { int ydx = (int)vec.y; for (int xdx = (int)vec.x + 1; xdx < map.GetLength(0) - 1; xdx++) { if (map[xdx, ydx] != TileType.None) { horizontal.Add(new Vector2(vec.x, vec.y), new Vector2(xdx - 1, ydx)); xdx = map.GetLength(0); } } } foreach (KeyValuePair <Vector2, Vector2> kv in horizontal.KeyValuePairs) { TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels; GameObject obj = availiableTile[level].GetTileType(TileType.Platform); var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion()); ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement; move.EndPos = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize); move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize); move.moveDir = MovementDirection.leftright; //ElevatorMovement move = tile.GetComponent<ElevatorMovement>(); Debug.Log(tile); NetworkServer.Spawn(tile); } }
/// <summary> /// Creates an instantites the tiles. /// </summary> /// <param name="map"></param> /// <param name="dividerLevel"></param> /// <param name="availiableTile"></param> protected virtual void GenerateElevators(TileType[,] map, int dividerLevel, Dictionary<TileSetType, TileLevel> availiableTile) { List<Vector2> leftEnds = new List<Vector2>(); List<Vector2> rightEnds = new List<Vector2>(); for (int xdx = 0; xdx < map.GetLength(0); xdx++) { for (int ydx = 0; ydx < map.GetLength(1); ydx++) { TileType type = map[xdx, ydx]; if (type == TileType.LeftEnd) { leftEnds.Add(new Vector2(xdx, ydx)); } else if (type == TileType.RightEnd) { rightEnds.Add(new Vector2(xdx, ydx)); } } } DualStore<Vector2, Vector2> veritcal = new DualStore<Vector2, Vector2>(); foreach (Vector2 vec in rightEnds) { int xdx = (int)vec.x + 1; //int ydx = (int)vec.y; for (int ydx = (int)vec.y - 1; ydx > 0; ydx--) { if (map[xdx, ydx] != TileType.None) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1)); ydx = -1; } else if (map[xdx - 1, ydx] == TileType.RightEnd) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx)); ydx = - 1; } else if (map[xdx + 1, ydx] == TileType.LeftEnd) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx)); ydx = -1; } } } foreach (Vector2 vec in leftEnds) { int xdx = (int)vec.x - 1; //int ydx = (int)vec.y; for (int ydx = (int)vec.y - 1; ydx > 0; ydx--) { if (map[xdx, ydx] != TileType.None) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1)); ydx = -1; } else if (map[xdx - 1, ydx] == TileType.RightEnd) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx)); ydx = -1; } else if (map[xdx + 1, ydx] == TileType.LeftEnd) { veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx)); ydx = -1; } } } foreach (KeyValuePair<Vector2, Vector2> kv in veritcal.KeyValuePairs) { TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels; GameObject obj = availiableTile[level].GetTileType(TileType.Platform); var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion()); ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement; move.EndPos = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize); move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize); move.moveDir = MovementDirection.updown; //ElevatorMovement move = tile.GetComponent<ElevatorMovement>(); Debug.Log(tile); NetworkServer.Spawn(tile); } DualStore<Vector2, Vector2> horizontal = new DualStore<Vector2, Vector2>(); foreach (Vector2 vec in rightEnds) { int ydx = (int)vec.y; for (int xdx = (int)vec.x + 1; xdx < map.GetLength(0) - 1; xdx++) { if (map[xdx, ydx] != TileType.None) { horizontal.Add(new Vector2(vec.x, vec.y), new Vector2(xdx - 1, ydx)); xdx = map.GetLength(0); } } } foreach (KeyValuePair<Vector2, Vector2> kv in horizontal.KeyValuePairs) { TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels; GameObject obj = availiableTile[level].GetTileType(TileType.Platform); var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion()); ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement; move.EndPos = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize); move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize); move.moveDir = MovementDirection.leftright; //ElevatorMovement move = tile.GetComponent<ElevatorMovement>(); Debug.Log(tile); NetworkServer.Spawn(tile); } }
/// <summary> /// gets all the tiles of a specific tiletype. /// </summary> /// <param name="tiles"></param> /// <param name="type"></param> /// <returns></returns> protected virtual List<GameObject> GetTileTypes (DualStore<TileDetails, GameObject> tiles, TileType type) { List<GameObject> thetiles = new List<GameObject>(); foreach (KeyValuePair<TileDetails, GameObject> kv in tiles.KeyValuePairs) { if (kv.Key.TileType == type) { thetiles.Add(kv.Value); } } return thetiles; }
/// <summary> /// Gets all tiles of a specific set type. /// </summary> /// <param name="allTiles"></param> /// <param name="type"></param> /// <returns></returns> protected virtual DualStore<TileDetails, GameObject> GetTileSetType (DualStore<TileDetails, GameObject> allTiles, TileSetType type) { DualStore<TileDetails, GameObject> thisTileset = new DualStore<TileDetails, GameObject>(); foreach (KeyValuePair<TileDetails, GameObject> kv in allTiles.KeyValuePairs) { if (kv.Key.Type == type) { thisTileset.Add(kv.Key, kv.Value); } } return thisTileset; }