diff --git a/src/Firebase.js b/src/Firebase.js index 0f46104..71cab35 100644 --- a/src/Firebase.js +++ b/src/Firebase.js @@ -41,7 +41,11 @@ async function loginWithGoogle() { "uid": uid_str, "coins": 0, "rooms": ["Gray"], - "decorations": [] + "decorations": [], + "lastLogin": Date.now(), + // "friends": [], + // "requests": [], + // "email": "" }); } catch (e) { @@ -60,7 +64,15 @@ async function loginWithGoogle() { // @ts-ignore rooms: doc.data().rooms, // @ts-ignore - decorations: doc.data().decorations + decorations: doc.data().decorations, + // @ts-ignore + lastLogin: doc.data().lastLogin, + // // @ts-ignore + // friends: doc.data().friends, + // // @ts-ignore + // requests: doc.data().requests, + // // @ts-ignore + // email: doc.data().email }); } } @@ -117,7 +129,11 @@ async function addActivity(activity, date, length) { "uid": get(UserInfoStore).uid, "coins": get(UserInfoStore).coins + Math.round(length/1000), "rooms": get(UserInfoStore).rooms, - "decorations": get(UserInfoStore).decorations + "decorations": get(UserInfoStore).decorations, + "lastLogin": get(UserInfoStore).lastLogin, + // "friends": get(UserInfoStore).friends, + // "requests": get(UserInfoStore).requests, + // "email": get(UserInfoStore).email }); } catch (e) { @@ -160,18 +176,181 @@ async function buyRoom(room, price) { "uid": get(UserInfoStore).uid, "coins": get(UserInfoStore).coins - price, "rooms": rooms, - "decorations": get(UserInfoStore).decorations + "decorations": get(UserInfoStore).decorations, + "lastLogin": get(UserInfoStore).lastLogin, + // "friends": get(UserInfoStore).friends, + // "requests": get(UserInfoStore).requests, + // "email": get(UserInfoStore).email + }); } catch (e) { console.log(e); } } +/** + * @param {string} decoration + * @param {number} price + */ +async function buyDecoration(decoration, price) { + try { + let decorations = get(UserInfoStore).rooms; + decorations.push(decoration); + await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), { + "uid": get(UserInfoStore).uid, + "coins": get(UserInfoStore).coins - price, + "rooms": get(UserInfoStore).rooms, + "decorations": decorations, + "lastLogin": get(UserInfoStore).lastLogin, + // "friends": get(UserInfoStore).friends, + // "requests": get(UserInfoStore).requests, + // "email": get(UserInfoStore).email + }); + } + catch (e) { + console.log(e); + } +} + +/** + * + * @param {number} newTime + */ +async function addLastLogin(newTime){ + try{ + await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), { + "uid": get(UserInfoStore).uid, + "coins": get(UserInfoStore).coins, + "rooms": get(UserInfoStore).rooms, + "decorations": get(UserInfoStore).decorations, + "lastLogin": newTime, + // "friends": get(UserInfoStore).friends, + // "requests": get(UserInfoStore).requests, + // "email": get(UserInfoStore).email + }); + } + catch (e){ + console.log(e); + } +} +/* +Friend list func + +Add (accept) +Delete +Decline +Send + +*/ + +/** + * + * @param {any} aFriend + */ +async function addFriend(aFriend){ + try{ + // friends.push(aFriend); + // requests.remove(aFriend); + await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), { + "uid": get(UserInfoStore).uid, + "coins": get(UserInfoStore).coins, + "rooms": get(UserInfoStore).rooms, + "decorations": get(UserInfoStore).decorations, + "lastLogin": get(UserInfoStore).lastLogin, + // "friends": get(UserInfoStore).friends, + // "requests": get(UserInfoStore).requests, + // "email": get(UserInfoStore).email + }); + + + // Add friends on the sender side + } + catch (e){ + console.log(e); + } +} + +/** + * + * @param {any} delFriend + */ +async function deleteFriend(delFriend){ + try{ + // friends.remove(delFriend); + await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), { + "uid": get(UserInfoStore).uid, + "coins": get(UserInfoStore).coins, + "rooms": get(UserInfoStore).rooms, + "decorations": get(UserInfoStore).decorations, + "lastLogin": get(UserInfoStore).lastLogin, + // "friends": get(UserInfoStore).friends, + // "requests": get(UserInfoStore).requests, + // "email": get(UserInfoStore).email + }); + + // Remove friends on the receiver side + } + catch (e){ + console.log(e); + } +} + +/** + * + * @param {any} declFriend + */ +async function declineFriend(declFriend){ + try{ + // requests.remove(declFriend); + await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), { + "uid": get(UserInfoStore).uid, + "coins": get(UserInfoStore).coins, + "rooms": get(UserInfoStore).rooms, + "decorations": get(UserInfoStore).decorations, + "lastLogin": get(UserInfoStore).lastLogin, + // "friends": get(UserInfoStore).friends, + // "requests": get(UserInfoStore).requests, + // "email": get(UserInfoStore).email + }); + + // Remove friends on the receiver side + } + catch (e){ + console.log(e); + } +} + +/** + * + * @param {any} reqFriend + */ +async function sendFriendRequest(reqFriend){ + try{ + //On the receiver + // requests.push(reqFriend); + await updateDoc(doc(db, "userInfo", get(UserInfoStore).uid), { + "uid": get(UserInfoStore).uid, + "coins": get(UserInfoStore).coins, + "rooms": get(UserInfoStore).rooms, + "decorations": get(UserInfoStore).decorations, + "lastLogin": get(UserInfoStore).lastLogin, + // "friends": get(UserInfoStore).friends, + // "requests": get(UserInfoStore).requests, + // "email": get(UserInfoStore).email + }); + + } + catch (e){ + console.log(e); + } +} export { loginWithGoogle, logoutFromGoogle, addActivity, getActivities, - buyRoom + buyRoom, + buyDecoration, + addLastLogin } \ No newline at end of file diff --git a/src/UserInfoStore.ts b/src/UserInfoStore.ts index 48b95d0..d3b5a4c 100644 --- a/src/UserInfoStore.ts +++ b/src/UserInfoStore.ts @@ -4,12 +4,21 @@ const UserInfoStore = writable<{ uid: string, coins: number, rooms: [string], - decorations: [string] + decorations: [string], + lastLogin: number, + // friends: [string], + // requests: [string], + // email: string }>({ uid: "", coins: 0, rooms: [""], - decorations: [""] + decorations: [""], + lastLogin: -1 + // Date.now() + // friends: [""], + // requests: [""], + // email: "" }); export default { diff --git a/src/routes/Homepage.svelte b/src/routes/Homepage.svelte index af35cd7..1840371 100644 --- a/src/routes/Homepage.svelte +++ b/src/routes/Homepage.svelte @@ -12,10 +12,35 @@ */ let currentRoom; + /** + * @type {boolean} + */ + let visible = true; + onMount(() => { - currentRoom = "Gray"; + currentRoom = "Gray"; + + let newLogin = Date.now(); + let newLoginDate = new Date(newLogin).getDate(); + // newLogin = newLogin.getDate(); + // console.log($UserInfoStore.lastLogin.toString()); + let lastLoginDate = new Date ($UserInfoStore.lastLogin).getDate(); + + console.log("newLogin homepage1", newLogin); + console.log("newLogin homepage2", newLoginDate); + console.log("lastLogin homepage1", lastLoginDate); + console.log("lastLogin homepage2", $UserInfoStore.lastLogin); }); + const dailyRewardModal = () =>{ + SessionStore.set({ + inSession: false, + sessionLength: 0, + modalType: "dailyReward", + counter: $SessionStore.counter+1, + sessionActivity: "" + }); + } const startSessionModal = () => { SessionStore.set({ inSession: false, @@ -46,6 +71,16 @@ }); }; + const storeModal = () => { + SessionStore.set({ + inSession: false, + sessionLength: 0, + modalType: "store", + counter: $SessionStore.counter+1, + sessionActivity: "" + }); + }; + const logout = () => { SessionStore.set({ inSession: false, @@ -78,6 +113,25 @@ } } } + + let newLogin = Date.now(); + let newLoginDate = new Date(newLogin).getDate(); + + setInterval(() => { + let lastLogin = $UserInfoStore.lastLogin; + if (lastLogin != -1) { + let lastLoginDate = new Date ($UserInfoStore.lastLogin).getDate(); + if (newLoginDate == lastLoginDate) { + console.log("ASGYUASGJ"); + visible = false; + } + } + }, 100) + + const clicked = () => { + + visible = false + } -logout +
+ {#if visible} + + {/if} + logout +
+ {#if $SessionStore.inSession} {:else} @@ -193,17 +276,21 @@ {:else if currentRoom == "Gray"} isometric {/if} +
+ coin-icon +
{ $UserInfoStore.coins }
+
+
- + +
+
-
- coin-icon -
{ $UserInfoStore.coins }
-
+ {/if} diff --git a/src/routes/ModalManager.svelte b/src/routes/ModalManager.svelte index 84a7632..881ee3b 100644 --- a/src/routes/ModalManager.svelte +++ b/src/routes/ModalManager.svelte @@ -4,8 +4,10 @@ import FinishedSessionModal from './components/FinishedSessionModal.svelte'; import ActivitiesModal from './components/ActivitiesModal.svelte'; import CustomizationModal from './components/CustomizationModal.svelte'; + import StoreModal from './components/StoreModal.svelte'; import { writable } from 'svelte/store'; import Modal from 'svelte-simple-modal'; + import DailyReward from './components/DailyReward.svelte'; const modal = writable(null); let currModal = ""; @@ -32,6 +34,14 @@ // @ts-ignore modal.set(CustomizationModal); } + if ($SessionStore.modalType == "store") { + // @ts-ignore + modal.set(StoreModal); + } + if ($SessionStore.modalType == "dailyReward") { + // @ts-ignore + modal.set(DailyReward); + } currModal = $SessionStore.modalType; counter = $SessionStore.counter; } diff --git a/src/routes/components/DailyReward.svelte b/src/routes/components/DailyReward.svelte new file mode 100644 index 0000000..6c6a205 --- /dev/null +++ b/src/routes/components/DailyReward.svelte @@ -0,0 +1,21 @@ + + +

Daily Reward!

+

Welcome back!

+

You earned 100 coins!

\ No newline at end of file diff --git a/src/routes/components/StoreModal.svelte b/src/routes/components/StoreModal.svelte new file mode 100644 index 0000000..282a0b7 --- /dev/null +++ b/src/routes/components/StoreModal.svelte @@ -0,0 +1,180 @@ + + + + +
+

Store

+
+
+ +
+
+ +
+
+
+ {#if currentRoom=="Bed_Room"} +
Desk
+ {#each bed_room_inventory as decoration} + {#if !$UserInfoStore.decorations.includes(decoration.item_name) && decoration.item_type == "Desk"} + + {/if} + {/each} +
Bed
+ {#each bed_room_inventory as decoration} + {#if !$UserInfoStore.decorations.includes(decoration.item_name) && decoration.item_type == "Bed"} + + {/if} + {/each} +
Wallpaper
+ {#each bed_room_inventory as decoration} + {#if !$UserInfoStore.decorations.includes(decoration.item_name) && decoration.item_type == "Wallpaper"} + + {/if} + {/each} + {:else} +
Bookshelf
+ {#each library_inventory as decoration} + {#if !$UserInfoStore.decorations.includes(decoration.item_name) && decoration.item_type == "Bookshelf"} + + {/if} + {/each} +
Chair
+ {#each library_inventory as decoration} + {#if !$UserInfoStore.decorations.includes(decoration.item_name) && decoration.item_type == "Chair"} + + {/if} + {/each} + {/if} +
+ + + + + +