コード例 #1
0
        IEnumerator UploadLevel(string jsonFile)
        {
            DevEditorData level = new DevEditorData();
            level = JsonUtility.FromJson<DevEditorData>(jsonFile);

            DynamoDBInfo requested = RequestIDs();

            while (requested.listOfIndexes.Count == 0 || requested.lastIdUsed == 0) yield return null;

            string levelName = level.levelName;
            string kubicode = GenerateKubiCode(requested);

            // create a new upload request, input the relevant information
            var putItemRequest = new PutItemRequest
            {
                TableName = DatabaseInfo.userContent_tableName,
                Item = new Dictionary<string, AttributeValue>()
                {
                    { DatabaseInfo.userContent_pKey, new AttributeValue{ S =  kubicode } },
                    { DatabaseInfo.userContent_levelName, new AttributeValue { S = levelName } },
                    { DatabaseInfo.userContent_jsonFile, new AttributeValue { S = jsonFile } }
                }
            };

            var response = client.PutItemAsync(putItemRequest);

            // if something goes wrong, debug the log message from AWS
            if (response.Exception != null)
            {
                Debug.Log(response.Exception.Message);
            }

            // else, the item has successfully been uploaded
            else
            {
                Debug.Log(levelName + " has been uploaded successfully!");
                UserLevelFiles.AddToUploads(uploadLevelDropdown.captionText.text);
            }
            /*
            // connect to dynamoDB database and pass the request information to upload the item
            client.PutItemAsync(putItemRequest, (result) =>
            {
                // if something goes wrong, debug the log message from AWS
                if (result.Exception != null)
                {
                    Debug.Log(result.Exception.Message);
                    return;
                }

                // else, the item has successfully been uploaded
                else
                {
                    Debug.Log(levelName + " has been uploaded successfully!");
                    UserLevelFiles.AddToUploads(uploadLevelDropdown.captionText.text);
                }

            }, null);*/

            yield return null;
        }
コード例 #2
0
        IEnumerator GetRandomLevels()
        {
            DynamoDBInfo ids = RequestIDs();
            DynamoReceivedInfo receivedInfo = new DynamoReceivedInfo();

            while (ids.listOfIndexes.Count == 0) yield return null;

            List<int> idsToGet = SelectRandomLevels(ids, numberOfLevelsToGet);

            for (int i = 0; i < idsToGet.Count; i++)
            {
                receivedInfo.ClearNames();
                receivedInfo = GetLevelById(idsToGet[i]);

                while (receivedInfo.levelName == "" && receivedInfo.kubicode == "") yield return null;

                Debug.Log("I'm saving kubicode : " + receivedInfo.kubicode);

                GameObject newListObj = Instantiate(listPrefab, listTransform);
                kubiCode = newListObj.transform.GetChild(1).GetComponent<Text>();
                levelname = newListObj.transform.GetChild(0).GetComponent<Text>();

                kubiCode.text = receivedInfo.kubicode;
                levelname.text = receivedInfo.levelName;

                Button button = newListObj.GetComponentInChildren<Button>();
                button.onClick.AddListener(() => DownloadLevel(receivedInfo.kubicode));
            }

            yield return null;
        }
コード例 #3
0
        // use to generate a new code based on the last existing one
        private string GenerateKubiCode(DynamoDBInfo requested)
        {
            int index = ++requested.lastIdUsed;

            requested.listOfIndexes.Add(index);
            requested.lastIdUsed = index;

            Debug.Log("new is " + requested.lastIdUsed);

            UpdateInfoFile(requested);

            return index.ToString();
        }
コード例 #4
0
        List<int> SelectRandomLevels(DynamoDBInfo ids, int amountOfLevels)
        {
            List<int> randomLevels = new List<int>();

            for (int i = 0; i < amountOfLevels; i++)
            {
                int randomLevelToGet = ids.listOfIndexes[Random.Range(0, ids.listOfIndexes.Count)];
                ids.listOfIndexes.Remove(randomLevelToGet);

                randomLevels.Add(randomLevelToGet);
            }

            return randomLevels;
        }
コード例 #5
0
        private void CreateIDsFile()
        {
            Debug.Log("No file was found, creating a new info file");

            DynamoDBInfo info = new DynamoDBInfo();
            info.listOfIndexes = new List<int>();
            info.backupListOfIndexes = new List<int>();

            info.lastIdUsed = 000000000000000000; // 18 zeros
            info.listOfIndexes.Add(info.lastIdUsed);
            info.backupListOfIndexes = info.listOfIndexes;

            string json = JsonUtility.ToJson(info);

            var request = new PutItemRequest
            {
                TableName = DatabaseInfo.info_tableName,
                Item = new Dictionary<string, AttributeValue>
                {
                    { DatabaseInfo.info_pKey, new AttributeValue { N = DatabaseInfo.info_key} },
                    { DatabaseInfo.info_jsonFile, new AttributeValue{ S = json} }
                }
            };

            var response = client.PutItemAsync(request);
            
            if(response.Exception == null) Debug.Log("Info file has been uploaded successfully!");
            /*
            client.PutItemAsync(request, (result) =>
            {
                if (result.Exception != null)
                {
                    Debug.Log(result.Exception.Message);
                    return;
                }
                // else, the item has successfully been uploaded
                else Debug.Log("Info file has been uploaded successfully!");

            }, null);*/
        }
コード例 #6
0
        private void UpdateInfoFile(DynamoDBInfo file)
        {
            string json = JsonUtility.ToJson(file);

            var updateRequest = new UpdateItemRequest
            {
                TableName = DatabaseInfo.info_tableName,
                Key = new Dictionary<string, AttributeValue>
                {
                    { DatabaseInfo.info_pKey, new AttributeValue { N = DatabaseInfo.info_key } }
                },

                AttributeUpdates = new Dictionary<string, AttributeValueUpdate>
                {
                    {
                        DatabaseInfo.info_jsonFile, new AttributeValueUpdate
                        {
                            Action = AttributeAction.PUT,
                            Value = new AttributeValue {S = json }
                        }
                    }
                }
            };

            var response = client.UpdateItemAsync(updateRequest);

            if (response.Exception == null) Debug.Log("The item has been updated");

            /*client.UpdateItemAsync(updateRequest, (result) =>
            {
                if (result.Exception != null)
                {
                    Debug.Log(result.Exception.Message);
                    return;
                }

                else Debug.Log("The item has been updated");
            });*/
        }
コード例 #7
0
        // get information concerning the last id that was uploaded to the server. This happens in the KUBIKA_information table
        private DynamoDBInfo RequestIDs()
        {
            DynamoDBInfo info = new DynamoDBInfo();

            var getIdsRequest = new GetItemRequest
            {
                ConsistentRead = true,
                TableName = DatabaseInfo.info_tableName,
                Key = new Dictionary<string, AttributeValue>()
                {
                    { DatabaseInfo.info_pKey, new AttributeValue{ N = DatabaseInfo.info_key} }
                }
            };

            var response = client.GetItemAsync(getIdsRequest);

            string jsonFile = "";

            foreach (var keyValuePair in response.Result.Item)
            {
                if (keyValuePair.Key == DatabaseInfo.info_jsonFile) jsonFile = keyValuePair.Value.S;
            }

            if (jsonFile == "" || jsonFile == null) CreateIDsFile();

            // create a DynamoDBInfo file from the json information stored in the Table
            DynamoDBInfo copy = JsonUtility.FromJson<DynamoDBInfo>(jsonFile);

            info.backupListOfIndexes = copy.backupListOfIndexes;
            info.listOfIndexes = copy.listOfIndexes;
            info.lastIdUsed = copy.listOfIndexes[copy.listOfIndexes.Count - 1];

            /*client.GetItemAsync(getIdsRequest, (result) =>
            {
                if (result.Exception != null)
                {
                    Debug.Log(result.Exception.Message);
                    return;
                }

                else
                {
                    Debug.Log("Extracting an info file");

                    string jsonFile = "";

                    foreach (var keyValuePair in result.Response.Item)
                    {
                        if (keyValuePair.Key == DatabaseInfo.info_jsonFile) jsonFile = keyValuePair.Value.S;
                    }

                    if (jsonFile == "" || jsonFile == null) CreateIDsFile();

                    // create a DynamoDBInfo file from the json information stored in the Table
                    DynamoDBInfo copy = JsonUtility.FromJson<DynamoDBInfo>(jsonFile);

                    info.backupListOfIndexes = copy.backupListOfIndexes;
                    info.listOfIndexes = copy.listOfIndexes;
                    info.lastIdUsed = copy.listOfIndexes[copy.listOfIndexes.Count - 1];

                    Debug.Log("Last used is " + info.lastIdUsed);
                }

            }, null);*/

            return info;
        }