Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Planet Gifting #18

Merged
merged 3 commits into from
May 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,8 @@ table {
margin-left: auto;
margin-right: auto;
}
td {
padding-left: 4px;
padding-right: 4px;
}
</style>
4 changes: 3 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
"cancel": "Cancel",
"nothing_found": "Nothing Found",
"nothing_happened": "Nothing Happend",
"explorespace": "Explore Space"
"explorespace": "Explore Space",
"explorer_lost": "Explorer Lost",
"planet_found": "Planet Found"
}
14 changes: 14 additions & 0 deletions src/services/steemconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ class SteemConnectService extends Client {

super.customJson([], [user], [appId], finalJson, cb);
}

giftPlanet(user, planetId, recipient, cb) {
var scJson = {};
var scCommand = {};
scJson["username"] = user;
scJson["type"] = "giftplanet";
scCommand["tr_var1"] = planetId;
scCommand["tr_var2"] = recipient;
scJson["command"] = scCommand;
var finalJson = JSON.stringify(scJson);
var appId = this.appId();

super.customJson([], [user], [appId], finalJson, cb);
}
}

export default new SteemConnectService();
7 changes: 6 additions & 1 deletion src/views/Items.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
</button>
<template v-if="showGift === item.id">
<input v-model="recipient" :placeholder="$t(placeholderGift)" />
<button @click="giftItem(item, index)" v-if="item.total > 0">
<button
:disabled="clicked.includes(item.id)"
@click="giftItem(item, index)"
v-if="item.total > 0"
>
{{ $t("Send") }}
</button>
</template>
Expand Down Expand Up @@ -103,6 +107,7 @@ export default {
this.items = response;
},
giftItem(item, index) {
this.clicked.push(item.id);
SteemConnectService.setAccessToken(this.accessToken);
SteemConnectService.giftItem(
this.loginUser,
Expand Down
29 changes: 18 additions & 11 deletions src/views/Missions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</p>
</template>
<template v-if="routeUser !== 'null'">
<table class="mission">
<table>
<thead>
<th @click="sortActive('id')">{{ $t("Active Mission") }}</th>
<th @click="sortActive('type')">{{ $t("Type") }}</th>
Expand All @@ -24,7 +24,12 @@
<td>{{ "(" + mission.start_x + "/" + mission.start_y + ")" }}</td>
<td>{{ "(" + mission.end_x + "/" + mission.end_y + ")" }}</td>
<td>{{ moment.unix(mission.arrival, "seconds").format("LLL") }}</td>
<td>{{ moment.unix(mission.return, "seconds").format("LLL") }}</td>
<td>
<span v-if="mission.return !== null">{{
moment.unix(mission.return, "seconds").format("LLL")
}}</span>
<span v-else>{{ $t("-") }}</span>
</td>
<td>{{ $t(mission.result || "-") }}</td>
</tr>
</tbody>
Expand All @@ -33,7 +38,7 @@
{{ $t("No Result") }}
</p>
<br />
<table class="mission">
<table>
<thead>
<th @click="sortOld('id')">{{ $t("Finished Mission") }}</th>
<th @click="sortOld('type')">{{ $t("Type") }}</th>
Expand All @@ -50,7 +55,12 @@
<td>{{ "(" + mission.start_x + "/" + mission.start_y + ")" }}</td>
<td>{{ "(" + mission.end_x + "/" + mission.end_y + ")" }}</td>
<td>{{ moment.unix(mission.arrival, "seconds").format("LLL") }}</td>
<td>{{ moment.unix(mission.return, "seconds").format("LLL") }}</td>
<td>
<span v-if="mission.return !== null">{{
moment.unix(mission.return, "seconds").format("LLL")
}}</span>
<span v-else>{{ $t("-") }}</span>
</td>
<td>{{ $t(mission.result || "-") }}</td>
</tr>
</tbody>
Expand Down Expand Up @@ -83,7 +93,7 @@ export default {
currentActiveSort: "arrival",
currentActiveSortDir: "asc",
currentOldSort: "return",
currentOldSortDir: "asc"
currentOldSortDir: "desc"
};
},
async mounted() {
Expand Down Expand Up @@ -164,11 +174,8 @@ export default {
</script>

<style>
table.mission,
.mission th,
.mission td {
border-collapse: collapse;
border: 1px solid dimgrey;
padding: 5px;
table {
margin-left: auto;
margin-right: auto;
}
</style>
138 changes: 124 additions & 14 deletions src/views/Planets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,88 @@
{{ $t("Rename") }}
</th>
<th>{{ $t("Context") }}</th>
<th v-if="!giftingLock">
<font color="red">{{ $t("Gift Planet") }}</font>
</th>
</thead>
<tbody>
<tr v-for="(planet, index) in planets" :key="planet.id">
<td>{{ planet.id }}</td>
<td>({{ planet.posx }}/{{ planet.posy }})</td>
<td>{{ planet.name }}</td>
<td v-if="routeUser === loginUser">
<button @click="toggleRename(planet.id)">
...
</button>
<template v-if="showRename === planet.id">
<input v-model="newName" :placeholder="$t(placeholderRename)" />
<button @click="renamePlanet(planet.id, index)">
{{ $t("Send") }}
<td>
<span v-if="routeUser === loginUser">
<button @click="toggleRename(planet.id)">
...
</button>
</template>
<template v-if="planet.id !== null && showRename === planet.id">
<input
v-model="newName"
:placeholder="$t(placeholderRename)"
/>
<button
:disabled="clicked.includes(planet.id)"
@click="renamePlanet(planet.id, newName, index)"
>
{{ $t("Send") }}
</button>
</template>
</span>
</td>
<td>
<button @click="setPlanet(planet.id, planet.name)">
{{ $t("Set") }}
</button>
</td>
<td v-if="!giftingLock">
<span v-if="routeUser === loginUser && planet.starter !== 1">
<button @click="toggleGifting(planet.id)">
...
</button>
<template
v-if="planet.id !== null && showGifting === planet.id"
>
<input
v-model="giftRecipient"
:placeholder="$t(placeholderGifting)"
/>
<button
:disabled="clicked.includes(planet.id)"
@click="giftPlanet(planet, giftRecipient, index)"
>
{{ $t("Send") }}
</button>
</template>
</span>
<span v-else>{{ $t("-") }}</span>
</td>
</tr>
</tbody>
</table>
<font v-if="!giftingLock" color="red">
<h2>
<i>{{ $t("Danger Zone") }}</i>
</h2>
<p>
{{
$t(
"Warning: You activated actions with potentially severe consequences."
)
}}
</p>
<p>
{{
$t(
"Gifting will hand over ownership of your planet to someone else and you can't claim it back."
)
}}
</p>
</font>
<p>
<button @click="toggleGiftingLock">
{{ $t("Gifting") }}
</button>
</p>
</template>
<template v-else>
<p>
Expand All @@ -54,6 +111,7 @@
<script>
import PlanetsService from "@/services/planets";
import SteemConnectService from "@/services/steemconnect";
import UserService from "@/services/user";
import { mapState } from "vuex";

export default {
Expand All @@ -64,7 +122,12 @@ export default {
planets: null,
newName: null,
showRename: null,
placeholderRename: "enter new name"
placeholderRename: "enter new name",
giftingLock: true,
showGifting: null,
giftRecipient: null,
placeholderGifting: "enter recipient",
clicked: []
};
},
async mounted() {
Expand Down Expand Up @@ -98,16 +161,17 @@ export default {
this.$store.dispatch("planet/setId", null);
this.$store.dispatch("planet/setName", null);
},
renamePlanet(planetId, index) {
renamePlanet(planetId, newName, index) {
this.clicked.push(planetId);
SteemConnectService.setAccessToken(this.accessToken);
SteemConnectService.renamePlanet(
this.loginUser,
planetId,
this.newName,
newName,
(error, result) => {
if (error === null && result.success) {
this.planets[index].name = this.newName;
this.$store.dispatch("planet/setName", this.newName);
this.planets[index].name = newName;
this.$store.dispatch("planet/setName", newName);
this.newName = null;
this.placeholderRename = "Success";
}
Expand All @@ -120,6 +184,52 @@ export default {
} else {
this.showRename = null;
}
},
toggleGiftingLock() {
if (this.giftingLock) {
this.giftingLock = false;
} else {
this.giftingLock = true;
}
},
toggleGifting(planetId) {
if (this.showGifting !== planetId) {
this.showGifting = planetId;
} else {
this.showGifting = null;
}
},
giftPlanet(planet, recipient, index) {
this.fetchhUser(recipient).then(searchedUser => {
if (searchedUser !== null && searchedUser === recipient) {
this.clicked.push(planet.id);
this.placeholder = "Search";
SteemConnectService.setAccessToken(this.accessToken);
SteemConnectService.giftPlanet(
this.loginUser,
planet.id,
recipient,
(error, result) => {
if (error === null && result.success) {
this.$store.dispatch("planet/setId", null);
this.giftRecipient = null;
this.planets[index].id = null;
this.placeholderGifting = "Success";
} else {
this.placeholderGifting = "Broadcast error";
this.giftRecipient = null;
}
}
);
} else {
this.placeholderGifting = "User not found";
this.giftRecipient = null;
}
});
},
async fetchhUser(user) {
const response = await UserService.get(user);
return response.username;
}
}
};
Expand Down
Loading