organized modules

This commit is contained in:
Ayo 2019-12-24 17:03:31 +08:00
parent 6a9fc1e1c7
commit 1ed4884100
16 changed files with 20 additions and 78 deletions

2
ayo.js
View file

@ -1,4 +1,4 @@
import { LeaderBoardService } from './src/services/leader-board.service.js';
import { LeaderBoardService } from './src/modules/leader-board/leader-board';
const leaderBoard = new LeaderBoardService('mw-leaders', 'mw-all');

View file

@ -1,15 +1,7 @@
/*
Author: Ayo Ayco
Email: ramon.aycojr@gmail.com
Website: AyoAyco.com
Blog: FullHacker.com
Live: games.fullhacker.com/minesweeper
*/
import './index.css';
import './services/loading/loading.css';
import './modules/loading/loading.css';
import './assets/favicon.ico';
import { Minesweeper } from './minesweeper.js';
/** start the game **/
const myMinesweeper = new Minesweeper();
myMinesweeper.initialize();

View file

@ -1,20 +1,12 @@
/*
Author: Ayo Ayco
Email: ramon.aycojr@gmail.com
Website: AyoAyco.com
Blog: FullHacker.com
Live: games.fullhacker.com/minesweeper
*/
import {
LeaderBoardService,
LoggerService,
StorageService,
TimerService
} from './services';
} from './modules';
import { levels } from './levels.js';
const VERSION = "0.3.7";
const VERSION = "0.3.8";
const MOBILE_BUSY_DELAY = 250;
const PC_BUSY_DELAY = 500;
const TEST_MODE = false;

View file

@ -3,7 +3,6 @@ import 'firebase/firestore';
export class DatabaseService {
constructor() {
// Your web app's Firebase configuration
const config = {
apiKey: "AIzaSyAbDzNHCSFh59e3r5sZA4_2ZHJnJ6SCCxM",
authDomain: "moment-188701.firebaseapp.com",
@ -13,7 +12,6 @@ export class DatabaseService {
messagingSenderId: "113827947104",
appId: "1:113827947104:web:b176f746d8358302c51905"
};
// Initialize Firebase
firebase.initializeApp(config);
this.store = firebase.firestore();
}

View file

@ -1,11 +1,3 @@
/*
Author: Ayo Ayco
Email: ramon.aycojr@gmail.com
Website: AyoAyco.com
Blog: FullHacker.com
Live: games.fullhacker.com/minesweeper
*/
export const DialogService = function() {
let isOpen = false;
let isInitialized = false;
@ -16,7 +8,6 @@ export const DialogService = function() {
const container = document.createElement('div');
container.className = 'dialog-container';
// add dialog wrapper and container elements
this.initialize = function() {
const bodyElement = document.getElementsByTagName('body')[0];
wrapper.appendChild(container);

View file

9
src/modules/index.js Normal file
View file

@ -0,0 +1,9 @@
export * from './database/db.js';
export * from './dialog/dialog.js';
export * from './encryption/encryption.js';
export * from './leader-board/leader-board.js';
export * from './loading/loading.js';
export * from './logger/logger.js';
export * from './storage/storage.js';
export * from './timer/timer.js';
export * from './user/user.js';

View file

@ -1,7 +1,7 @@
import { DatabaseService } from "./db.service.js";
import { TimerService } from "./timer.service.js";
import { UserService } from "./user.service.js";
import { LoadingService } from "./loading/loading.js";
import { DatabaseService } from '../database/db';
import { TimerService } from '../timer/timer';
import { UserService } from '../user/user';
import { LoadingService } from '../loading/loading';
const dbService = new DatabaseService();
const timerService = new TimerService();
@ -63,6 +63,7 @@ export class LeaderBoardService {
this.unsubscribe();
}
this.lastPlace = Number.MAX_SAFE_INTEGER;
// todo: use 'where' to filter by day, week, month, and all-time
this.topList = this.leaders.doc(level)
.collection('games').orderBy('time').limit(10);
this.unsubscribe = this.setListener(this.topList, displayElement, title);
@ -98,7 +99,7 @@ export class LeaderBoardService {
const name = game.data().name || 'Anonymous';
const item = document.createElement('div');
item.style.display = 'flex';
const nameElement =document.createElement('div'); // `<span class="ellipsis" title="${name}">${name}</span>` ;
const nameElement =document.createElement('div');
nameElement.innerHTML = name;
nameElement.setAttribute('title', name);
nameElement.style.textOverflow = 'ellipsis';

View file

@ -1,11 +1,3 @@
/*
Author: Ayo Ayco
Email: ramon.aycojr@gmail.com
Website: AyoAyco.com
Blog: FullHacker.com
Live: games.fullhacker.com/minesweeper
*/
export class LoggerService {
debug(message, data) {
if (typeof message === 'string') {

View file

@ -1,11 +1,3 @@
/*
Author: Ayo Ayco
Email: ramon.aycojr@gmail.com
Website: AyoAyco.com
Blog: FullHacker.com
Live: games.fullhacker.com/minesweeper
*/
export class StorageService {
constructor() {

View file

@ -1,12 +1,4 @@
import { LoggerService } from "./logger.service.js";
/*
Author: Ayo Ayco
Email: ramon.aycojr@gmail.com
Website: AyoAyco.com
Blog: FullHacker.com
Live: games.fullhacker.com/minesweeper
*/
import { LoggerService } from "../logger/logger";
const INTERVAL = 1;
@ -30,7 +22,6 @@ export class TimerService {
start() {
if (this.running || !this.display) return;
// run timer
this.running = true;
this.startTime = new Date().getTime();
this.id = window.setInterval(() => this.updateDisplay(), INTERVAL);

View file

@ -1,8 +0,0 @@
/*
Author: Ayo Ayco
Email: ramon.aycojr@gmail.com
Website: AyoAyco.com
Blog: FullHacker.com
Live: games.fullhacker.com/minesweeper
*/

View file

@ -1,8 +0,0 @@
export * from './db.service';
export * from './dialog.service';
export * from './leader-board.service';
export * from './loading/loading';
export * from './logger.service';
export * from './storage.service';
export * from './timer.service';
export * from './user.service';