diff --git a/js/places/place-edit.js b/js/places/place-edit.js
index 02491e7..3d0960c 100755
--- a/js/places/place-edit.js
+++ b/js/places/place-edit.js
@@ -1,17 +1,21 @@
-const ID = window.location.pathname.split('/')[3]
+const PlaceID = window.location.pathname.split('/')[3]
const Form = document.querySelector('form[action="/create/place/update"]')
var Settings;
+var PlaceData = null
!(async () => {
ActivityToggle()
//RequestGameProfile()
+ CopyOwnedPlace()
})()
async function ActivityToggle() {
- const Response = await fetch('https://api.polytoria.com/v1/places/'+ID)
- let Status = await Response.json()
- Status = Status.isActive
+ if (PlaceData === null) {
+ PlaceData = await fetch('https://api.polytoria.com/v1/places/' + PlaceID)
+ PlaceData = await PlaceData.json()
+ }
+ let Status = PlaceData.isActive
const DIV = document.createElement('div')
DIV.classList = 'form-group mt-4'
@@ -32,7 +36,7 @@ async function ActivityToggle() {
DIV.appendChild(ActivityBtn)
ActivityBtn.addEventListener('click', function() {
- fetch(`https://polytoria.com/api/places/${ID}/toggle-active`, {
+ fetch(`https://polytoria.com/api/places/${PlaceID}/toggle-active`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
@@ -84,6 +88,71 @@ function RequestGameProfile() {
cardBg: CardBody.children[4].value,
text: CardBody.children[5].value
}
- window.location.href = 'https://polyplus.vercel.app/app/game-profile.html?gameId=' + ID + '&profile=' + encodeURIComponent(btoa(JSON.stringify(Result)))
+ window.location.href = 'https://polyplus.vercel.app/app/game-profile.html?gameId=' + PlaceID + '&profile=' + encodeURIComponent(btoa(JSON.stringify(Result)))
});
+}
+
+async function CopyOwnedPlace() {
+ console.log('ran function')
+ if (PlaceData === null) {
+ PlaceData = await fetch('https://api.polytoria.com/v1/places/' + PlaceID)
+ PlaceData = await PlaceData.json()
+ }
+
+ if (PlaceData.creator.id !== parseInt(JSON.parse(window.localStorage.getItem('account_info')).ID)) {
+ console.log('returned')
+ return
+ }
+
+ const DIV = document.createElement('div')
+ DIV.classList = 'form-group mt-4'
+ DIV.innerHTML = `
+
+
+
+ `
+
+ Form.insertBefore(DIV, Form.children[Form.children.length-1])
+
+ const DownloadButton = DIV.getElementsByTagName('button')[0]
+ DownloadButton.addEventListener('click', async function() {
+ console.log('clicked download epic')
+
+ let CreatorToken = await fetch('https://polytoria.com/api/places/edit', {
+ method: "POST",
+ headers: {
+ 'X-CSRF-Token': document.querySelector('input[name="_csrf"]').value
+ },
+ body: JSON.stringify({ placeID: PlaceID })
+ })
+ CreatorToken = await CreatorToken.json()
+ CreatorToken = CreatorToken.token
+
+ fetch(`https://api.polytoria.com/v1/places/get-place?id=${PlaceID}&tokenType=creator`, {
+ headers: {
+ 'Authorization': CreatorToken
+ }
+ })
+ .then(response => {
+ if (!response.ok) {
+ throw new Error('Network not ok')
+ }
+ return response.blob()
+ })
+ .then(data => {
+ //const JSONBlob = new Blob([data], {type: "application/xml"})
+ const DownloadURL = URL.createObjectURL(data)
+
+ const Link = document.createElement('a')
+ Link.href = DownloadURL
+ Link.download = PlaceData.name + '.poly'
+ document.body.appendChild(Link)
+ Link.click()
+ Link.remove()
+ })
+ .catch(error => {console.log(error)});
+ })
}
\ No newline at end of file
diff --git a/js/places/place-view.js b/js/places/place-view.js
index 31903c1..25d56ab 100644
--- a/js/places/place-view.js
+++ b/js/places/place-view.js
@@ -12,7 +12,7 @@ let InfoColumns = document.querySelectorAll('#main-content .col:has(#likes-data-
let CalculateRevenueButton;
const AchievementsTab = document.getElementById('achievements-tabpane')
-const Achievements = Array.from(AchievementsTab.children)
+const Achievements = Array.from(AchievementsTab.getElementsByClassName('card'))
!(() => {
if (PlaceID === undefined) { return }
@@ -68,10 +68,6 @@ const Achievements = Array.from(AchievementsTab.children)
})();
}
- if (Settings.StoreOwnTagsOn === true) {
- OwnedTags()
- }
-
if (Settings.ShowPlaceRevenueOn === true) {
const NameRow = document.createElement('li')
NameRow.innerText = 'Revenue:'
@@ -99,6 +95,12 @@ const Achievements = Array.from(AchievementsTab.children)
if (AchievementsTab.getElementsByClassName('display-3')[0] === undefined) {
AchievementProgressBar()
AchievementEarnedPercentage()
+
+ for (let achievement of Achievements) {
+ if ((achievement.getElementsByClassName('fad fa-check-circle')[0] !== undefined) === false) {
+ achievement.style.opacity = '0.5'
+ }
+ }
}
});
})()
@@ -339,39 +341,9 @@ async function InlineEditing() {
console.log('Error while editing game')
});
}
-
- /*
- PlaceTitleSpan.setAttribute('contenteditable', Editing.toString())
- if (PlaceDesc !== null) {
- console.log('Description exists')
- PlaceDesc.setAttribute('contenteditable', Editing.toString())
- }
- if (Editing === false) {
- const Send = new FormData()
- Send.append("_csrf", document.querySelector('input[name="_csrf"]').value)
- Send.append("id", PlaceID)
- Send.append("name", PlaceTitle.innerText || '')
-
- fetch('/create/place/update', {method:"POST",body:Send})
- .then(response => {
- if (!response.ok) {
- throw new Error('Network not ok')
- }
- return response.text()
- })
- .then(data => {
- console.log('Successfully edited game')
- })
- .catch(error => {
- console.log('Error while editing game')
- });
- }
- */
});
}
-//const Data = JSON.parse('{"gameTitle": "Hyper[Fart]","bg": "#000","accent": "#007bff","secondary": "#","cardBg": "#313131","font": "","text": "#fff"}')
-const Data = JSON.parse('{"gameTitle":"Isolation: Brix High School","bg":"#0148af","accent":"#986c6a","secondary":"#b7d3f2","cardBg":"#313131","text":"#fff"}')
async function GameProfiles(data) {
return
data = Data
@@ -427,25 +399,6 @@ async function IRLPrice() {
}
}
-async function OwnedTags() {
- /*
- This feature is disabled due to Polytoria website now having this without the use of an extension - items are now grayed out if they are owned
- */
- return
- const Response = await fetch('https://api.polytoria.com/v1/users/' + UserID + '/inventory/')
- const Gamepasses = document.querySelector('#gamepasses-tabpane .row.flex-row').children
- for (let gamepass of Gamepasses) {
- const GamePassID = gamepass.getElementsByTagName('a')[0].getAttribute('href').split('/')
- console.log(GamePassID)
- }
-
- const Achievements = document.querySelector('#achievements-tabpane .row.flex-row').children
- for (let gamepass of Achievements) {
- const GamePassID = gamepass.getElementsByTagName('a')[0].getAttribute('href').split('/')
- console.log(GamePassID)
- }
-}
-
async function PlaceRevenue() {
const Visits = parseInt(document.querySelector('li:has(i.fad.fa-users.text-muted[style])').innerText)
const BricksPerView = 5
@@ -492,12 +445,60 @@ async function PlaceRevenue() {
function round5(number) { const remainder = number % 5; if (remainder < 2.5) { return number - remainder; } else { return number + (5 - remainder); } }
+function ImprovedAchievements() {
+ const AchievementCount = Achievements.length
+ let AchievementsEarned = 0
+
+ for (let achievement of Achievements) {
+ Achieved = (achievement.getElementsByClassName('fad fa-check-circle')[0] !== undefined)
+
+ if (Achieved === true) {
+ achievement.style.borderColor = 'gold'
+ AchievementsEarned++
+ }
+ }
+
+ const PercentageEarned = ((AchievementsEarned*100)/AchievementCount).toFixed(0)
+
+ const ProgressBar = document.createElement('div')
+ ProgressBar.role = 'progressbar'
+ ProgressBar.classList = 'progress'
+ ProgressBar.style.background = '#000'
+ ProgressBar.ariaValueNow = PercentageEarned
+ ProgressBar.ariaValueMin = "0"
+ ProgressBar.ariaValueMax = "100"
+ ProgressBar.innerHTML = `