You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
mergeInto(LibraryManager.library, {
|
|
// Function to add or update user profile data
|
|
AddDataToFirestore: function (walletPtr, jsonPtr) {
|
|
var wallet = UTF8ToString(walletPtr);
|
|
var jsonData = UTF8ToString(jsonPtr);
|
|
var data = JSON.parse(jsonData);
|
|
|
|
window.db.collection("users").doc(wallet).collection("ProfileData").doc("Main").set(data)
|
|
.then(function () {
|
|
console.log("Data successfully written!");
|
|
})
|
|
.catch(function (error) {
|
|
console.error("Error writing document: ", error);
|
|
});
|
|
},
|
|
|
|
// Function to retrieve data from Firestore
|
|
GetUserProfileData: function (walletPtr) {
|
|
var wallet = UTF8ToString(walletPtr);
|
|
|
|
// Ensure the Firestore instance is accessible
|
|
if (typeof window.db === 'undefined') {
|
|
console.error("Firestore is not initialized.");
|
|
return;
|
|
}
|
|
|
|
window.db
|
|
.collection("users")
|
|
.doc(wallet)
|
|
.collection("ProfileData")
|
|
.doc("Main")
|
|
.get()
|
|
.then(function (doc) {
|
|
if (doc.exists) {
|
|
var data = doc.data();
|
|
var jsonData = JSON.stringify(data);
|
|
if (typeof web3UnityInstance !== 'undefined') {
|
|
web3UnityInstance.SendMessage("FirebaseManager", "OnUserProfileDataReceived", jsonData);
|
|
} else {
|
|
console.error("web3UnityInstance is undefined.");
|
|
}
|
|
} else {
|
|
console.log("No such document!");
|
|
}
|
|
})
|
|
.catch(function (error) {
|
|
console.error("Error getting document:", error);
|
|
});
|
|
}
|
|
});
|