Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- import Icon from 'vue-awesome/components/Icon';
- import 'vue-awesome/icons/bell';
- export default {
- name: 'Home',
- components: {
- Icon
- },
- data() {
- return {
- isDay: false,
- inGameHour: 0,
- inGameMinute: 0,
- secsUntilNightStart: 0,
- secsUntilNightEnd: 0,
- secsUntilDailyRes: 0,
- secsUntilImpRes: 0,
- secsUntilTradeRes: 0,
- subs: []
- }
- },
- async created() {
- if (!this.$cookie.get('bdotaskauth'))
- return this.$router.push('/login');
- const request = await this.$api.getIngameSubs();
- const response = await request.json();
- if (response.fetched)
- this.subs = response.subs;
- setInterval(this.updateTime, 2 * 1000);
- setInterval(this.updateCountdowns, 2 * 1000);
- this.updateTime();
- this.updateCountdowns();
- },
- computed: {
- ampm() {
- return this.inGameHour < 12 ? 'AM' : 'PM';
- },
- displayHour() {
- console.log('qweqweqweqw')
- let t = this.inGameHour % 12;
- if (t === 0)
- t = 12;
- return t < 10 ? '0' + t : t;
- },
- displayMinute() {
- return this.inGameMinute < 10 ? '0' + this.inGameMinute : this.inGameMinute;
- }
- },
- methods: {
- updateCountdowns() {
- const d = new Date();
- let startHour = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), 0, 0, 0, 0);
- const secRealDay = (Date.now() - startHour) / 1000;
- this.secsUntilDailyRes = 24 * 60 * 60 - secRealDay;
- this.secsUntilImpRes = 3 * 60 * 60 - secRealDay % (60 * 60 * 3);
- this.secsUntilTradeRes = 4 * 60 * 60 - secRealDay % (60 * 60 * 4);
- },
- updateTime() {
- const d = new Date();
- let startHour = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), 0, 0, 0, 0);
- const secRealDay = (Date.now() - startHour) / 1000;
- const secsIntoGameDay = (secRealDay + 200 * 60 + 20 * 60) % (240 * 60);
- if (secsIntoGameDay >= 12000) {
- const secsIntoGameNight = secsIntoGameDay - 12000;
- const pctOfNightDone = secsIntoGameNight / (40 * 60);
- let gameHour = 9 * pctOfNightDone;
- gameHour = gameHour < 2 ? 22 + gameHour : gameHour - 2;
- const secsUntilNightEnd = 40 * 60 - secsIntoGameNight;
- this.isDay = false;
- this.inGameHour = gameHour / 1 >> 0;
- this.inGameMinute = gameHour % 1 * 60 >> 0;
- this.secsUntilNightEnd = secsUntilNightEnd;
- this.secsUntilNightStart = secsUntilNightEnd + 12000;
- }
- else {
- const secsIntoGameDaytime = secsIntoGameDay;
- const pctOfDayDone = secsIntoGameDay / (200 * 60);
- let gameHour = 7 + (22 - 7) * pctOfDayDone;
- const secsUntilNightStart = 12000 - secsIntoGameDaytime;
- this.isDay = true;
- this.inGameHour = gameHour / 1 >> 0;
- this.inGameMinute = gameHour % 1 * 60 >> 0;
- this.secsUntilNightEnd = secsUntilNightStart + 40 * 60;
- this.secsUntilNightStart = secsUntilNightStart;
- }
- },
- toHHMM(secs) {
- let hours = Math.floor(secs / (60 * 60));
- let minutes = Math.floor((secs - (hours * 3600)) / 60);
- if (hours < 10)
- hours = '0' + hours;
- if (minutes < 10)
- minutes = '0' + minutes;
- return hours + 'h : ' + minutes + 'm';
- },
- async toggleNotification(id) {
- const request = await this.$api.subIngameTime(id);
- const response = await request.json();
- console.log(response);
- }
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement