diff --git a/START.html b/START.html new file mode 100644 index 0000000..7bb2ce0 --- /dev/null +++ b/START.html @@ -0,0 +1,26 @@ + + +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/help/data_xample.js b/help/data_xample.js index 0c8b6ed..4446acd 100644 --- a/help/data_xample.js +++ b/help/data_xample.js @@ -3,12 +3,11 @@ async function createTemp() { await couchDB.set("users", { "turtle": { "password": "1234", - "level": 1, + "level": 0, + "xp": 0, "avatar": null, - "abilities": [ - ], - "enabled_abilities": [ - ], + "abilities": [], + "enabled_abilities": [], "role": "student", "courses": [ "weiche_ware", @@ -17,8 +16,9 @@ async function createTemp() { }, "dumble-door": { "password": "bla", - "level": 4, - "avatar": "https://static.turtle-coding-gbr.de/profile-pic.png", + "level": 10, + "xp": 0, + "avatar": "https://static.turtle-coding-gbr.de/gmci/profile-pic.png", "abilities": [ ], "enabled_abilities": [ @@ -30,9 +30,18 @@ async function createTemp() { }, "narrator": { "password": "stanley", - "level": 4, - "avatar": "https://static.turtle-coding-gbr.de/st", + "level": 10, + "xp": 0, + "avatar": "https://static.turtle-coding-gbr.de/gmci/st", "abilities": [ + "dark_mode", + "accent_color", + "pink_mode", + "profile_pic", + "simple_border", + "gold_border", + "epic_border", + "title_of_honor" ], "enabled_abilities": [ ], @@ -72,17 +81,17 @@ async function createTemp() { { "date": "2025-12-27", "questions": [ - { "title": "1", "type": "text" }, - { "title": "2", "type": "scala" } + { "title": "Wie war die Vorlesung?", "type": "text" }, + { "title": "Wie war der Professor?", "type": "scala" } ], "result": [ - ["Gut, aber ...", 5], - ["Schlecht", 1] + ["Gut, weil ...", 5], + ["Schlecht, weil ...", 1] ] } ], "start_date": "2025-12-23", - "expire_date": "2025-12-27" + "expire_date": "2026-02-20" }); await couchDB.set("course:weiche_ware", { "title": "Weiche Ware", @@ -99,8 +108,8 @@ async function createTemp() { } ], "result": [ - ["Gut, aber ...", 5], - ["Schlecht", 1] + ["Gut, weil ...", 5], + ["Schlecht, weil ...", 1] ], "result_history": [ { @@ -110,12 +119,12 @@ async function createTemp() { { "title": "2", "type": "scala" } ], "result": [ - ["Gut, aber ...", 5], - ["Schlecht", 1] + ["Gut, weil ...", 5], + ["Schlecht, weil ...", 1] ] } ], "start_date": "2025-12-23", - "expire_date": "2025-12-27" + "expire_date": "2025-02-20" }); } \ No newline at end of file diff --git a/imgs/humoid_profil.png b/imgs/humoid_profil.png index f4f415d..e88339c 100644 Binary files a/imgs/humoid_profil.png and b/imgs/humoid_profil.png differ diff --git a/imgs/rosa_profil.png b/imgs/rosa_profil.png index ccc5adb..b04e052 100644 Binary files a/imgs/rosa_profil.png and b/imgs/rosa_profil.png differ diff --git a/imgs/standart_profil.png b/imgs/standart_profil.png index 5f9a15d..97dfb46 100644 Binary files a/imgs/standart_profil.png and b/imgs/standart_profil.png differ diff --git a/lib/basic.js b/lib/basic.js index 5f2123c..e127477 100644 --- a/lib/basic.js +++ b/lib/basic.js @@ -374,14 +374,15 @@ var userData = null; const userDataListener = []; async function setUserData(couchDB) { - const res = await getUserData(couchDB); - if (res == null) { + const user = await getUserData(couchDB); + if (user == null) { location.href = "../login.html"; return false; } - userData = res; - updateAllProfiles(res); - _constructProfile(res); + userData = user; + updateAllProfiles(user); + _constructProfile(user); + await checkUserCourses(couchDB, user); while (userDataListener.length > 0) { const call = userDataListener[userDataListener.length - 1]; @@ -407,18 +408,51 @@ async function updateUserData(couchDB, user = userData) { function updateAllProfiles(user) { - const hasProfilAbility = user.enabled_abilities.includes("profile_pic"); + const features = user.enabled_abilities ??= []; + const hasProfilAbility = features.includes("profile_pic"); const profiles = document.getElementsByClassName("profile"); for (var i of profiles) { - if (hasProfilAbility) { + if (hasProfilAbility && user.avatar) { i.style.backgroundImage = `url("${user.avatar}")`; } else { - i.style.removeProperty("backgroundImage"); + if (features.includes("pink_mode")) { + i.style.backgroundImage = `url("https://static.turtle-coding-gbr.de/gmci/rosa_profil.png")`; + } else { + i.style.backgroundImage = `url("https://static.turtle-coding-gbr.de/gmci/standart_profil.png")`; + } } i.onclick = _onProfileClick; } } +async function checkUserCourses(couchDB, userData) { + for (var cName of userData.courses) { + const course = await couchDB.get("course:" + cName); + if (!course || !course.expire_date) continue; + + const expire_date = new Date(course.expire_date); + if (expire_date < new Date()) { + course.result_history ??= []; + course.questions ??= []; + course.result ??= []; + + if (course.questions.length == 0 || course.result.length == 0) continue; + + course.result_history.push({ + "date": course.start_date ?? expire_date, + "questions": course.questions, + "result": course.result + }); + course.questions = []; + course.result = []; + + await couchDB.set("course:" + cName, course); + + console.log(`Course ${cName} expired`); + } + } +} + function _onProfileClick(event) { var buttonRect = this.getBoundingClientRect(); @@ -542,4 +576,26 @@ function getUserDisplayName(user) { const hasHonor = (user.enabled_abilities ??= []).includes("title_of_honor"); const title_of_honor = hasHonor ? "(Sir) " : ""; return `${title_of_honor}${ !user.title ? "" : user.title + " " }${ form1(user.name) }`; +} + +async function levelUpXP(couchDB, user = userData, xp = 1) { + var resLevelUp = false; + + userData.xp ??= 0; + userData.level ??= 0; + + userData.xp += xp; + while (userData.xp >= userData.level+1) { + userData.xp -= (userData.level + 1); + userData.level++; + resLevelUp = true; + } + + if (userData.xp < 0) { + console.error("UserData-XP was below zero!"); + userData.xp = 0; + } + + await updateUserData(couchDB, user); + return resLevelUp; } \ No newline at end of file diff --git a/login.html b/login.html index e09f2e6..192f262 100644 --- a/login.html +++ b/login.html @@ -1,160 +1,154 @@ - - - - - -