{"size": 1062, "ext": "js", "max_stars_repo_path": "test/tools/references/code-generation/base-application.js", "max_stars_repo_name": "trave/zombiebox", "max_stars_repo_stars_event_min_datetime": "2019-06-04T15:01:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T03:03:05.000Z", "max_issues_repo_path": "test/tools/references/code-generation/base-application.js", "max_issues_repo_name": "trave/zombiebox", "max_issues_repo_issues_event_min_datetime": "2019-06-04T17:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-01T15:48:18.000Z", "max_forks_repo_path": "test/tools/references/code-generation/base-application.js", "max_forks_repo_name": "trave/zombiebox", "max_forks_repo_forks_event_min_datetime": "2019-09-05T04:26:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-05T18:27:12.000Z"}
{"max_stars_count": 86, "max_issues_count": 20, "max_forks_count": 11, "avg_line_length": 16.0909090909, "max_line_length": 66, "alphanum_fraction": 0.6525423729}
import {PLATFORM_NAME} from 'generated/define';
import AbstractApplication from 'zb/abstract-application';

import createTamagotchiDevice from 'tamagotchi/factory';
import tamagotchiDevice from 'tamagotchi/device';
import createPcDevice from 'pc/factory';
import pcDevice from 'pc/device';



/**
 * @abstract
 */
export default class BaseApplication extends AbstractApplication {
	/**
	 */
	constructor() {
		super();
	}


	/**
	 * @return {boolean}
	 */
	isDeviceTamagotchi() {
		return this.device instanceof tamagotchiDevice;
	}

	/**
	 * @return {boolean}
	 */
	isDevicePc() {
		return this.device instanceof pcDevice;
	}

	/**
	 * @override
	 */
	_createDevice() {
		let device;

		if (PLATFORM_NAME) {
			const factory = {
				'tamagotchi': createTamagotchiDevice,
				'pc': createPcDevice,
			}[PLATFORM_NAME];

			if (factory) {
				device = factory();
			}
		} else {
			device = (
				createTamagotchiDevice() ||
				createPcDevice() ||
				null
			);
		}

		if (!device) {
			throw new Error('Can\'t detect a platform.');
		}

		return device;
	}
};
