Advertisement
emesten

Untitled

Aug 12th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. <script>
  2. import Icon from 'vue-awesome/components/Icon';
  3. import 'vue-awesome/icons/bell';
  4.  
  5. export default {
  6. name: 'Home',
  7. components: {
  8. Icon
  9. },
  10. data() {
  11. return {
  12. isDay: false,
  13. inGameHour: 0,
  14. inGameMinute: 0,
  15. secsUntilNightStart: 0,
  16. secsUntilNightEnd: 0,
  17. secsUntilDailyRes: 0,
  18. secsUntilImpRes: 0,
  19. secsUntilTradeRes: 0,
  20. subs: []
  21. }
  22. },
  23. async created() {
  24. if (!this.$cookie.get('bdotaskauth'))
  25. return this.$router.push('/login');
  26.  
  27. const request = await this.$api.getIngameSubs();
  28. const response = await request.json();
  29. if (response.fetched)
  30. this.subs = response.subs;
  31.  
  32.  
  33. setInterval(this.updateTime, 2 * 1000);
  34. setInterval(this.updateCountdowns, 2 * 1000);
  35. this.updateTime();
  36. this.updateCountdowns();
  37. },
  38. computed: {
  39. ampm() {
  40. return this.inGameHour < 12 ? 'AM' : 'PM';
  41. },
  42. displayHour() {
  43. console.log('qweqweqweqw')
  44. let t = this.inGameHour % 12;
  45. if (t === 0)
  46. t = 12;
  47. return t < 10 ? '0' + t : t;
  48. },
  49. displayMinute() {
  50. return this.inGameMinute < 10 ? '0' + this.inGameMinute : this.inGameMinute;
  51. }
  52. },
  53. methods: {
  54. updateCountdowns() {
  55. const d = new Date();
  56. let startHour = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), 0, 0, 0, 0);
  57. const secRealDay = (Date.now() - startHour) / 1000;
  58.  
  59. this.secsUntilDailyRes = 24 * 60 * 60 - secRealDay;
  60. this.secsUntilImpRes = 3 * 60 * 60 - secRealDay % (60 * 60 * 3);
  61. this.secsUntilTradeRes = 4 * 60 * 60 - secRealDay % (60 * 60 * 4);
  62. },
  63. updateTime() {
  64. const d = new Date();
  65. let startHour = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), 0, 0, 0, 0);
  66. const secRealDay = (Date.now() - startHour) / 1000;
  67. const secsIntoGameDay = (secRealDay + 200 * 60 + 20 * 60) % (240 * 60);
  68.  
  69. if (secsIntoGameDay >= 12000) {
  70.  
  71. const secsIntoGameNight = secsIntoGameDay - 12000;
  72. const pctOfNightDone = secsIntoGameNight / (40 * 60);
  73. let gameHour = 9 * pctOfNightDone;
  74. gameHour = gameHour < 2 ? 22 + gameHour : gameHour - 2;
  75. const secsUntilNightEnd = 40 * 60 - secsIntoGameNight;
  76.  
  77. this.isDay = false;
  78. this.inGameHour = gameHour / 1 >> 0;
  79. this.inGameMinute = gameHour % 1 * 60 >> 0;
  80. this.secsUntilNightEnd = secsUntilNightEnd;
  81. this.secsUntilNightStart = secsUntilNightEnd + 12000;
  82. }
  83. else {
  84. const secsIntoGameDaytime = secsIntoGameDay;
  85. const pctOfDayDone = secsIntoGameDay / (200 * 60);
  86. let gameHour = 7 + (22 - 7) * pctOfDayDone;
  87. const secsUntilNightStart = 12000 - secsIntoGameDaytime;
  88.  
  89. this.isDay = true;
  90. this.inGameHour = gameHour / 1 >> 0;
  91. this.inGameMinute = gameHour % 1 * 60 >> 0;
  92. this.secsUntilNightEnd = secsUntilNightStart + 40 * 60;
  93. this.secsUntilNightStart = secsUntilNightStart;
  94. }
  95. },
  96. toHHMM(secs) {
  97. let hours = Math.floor(secs / (60 * 60));
  98. let minutes = Math.floor((secs - (hours * 3600)) / 60);
  99.  
  100. if (hours < 10)
  101. hours = '0' + hours;
  102. if (minutes < 10)
  103. minutes = '0' + minutes;
  104.  
  105. return hours + 'h : ' + minutes + 'm';
  106. },
  107. async toggleNotification(id) {
  108. const request = await this.$api.subIngameTime(id);
  109. const response = await request.json();
  110. console.log(response);
  111. }
  112. }
  113. }
  114. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement