base/platform
플랫폼 정보.
Platform information.
Platformextends Object
플랫폼 정보.
Platform information.
import { Platform, PlatformType, BrowserType } from "./build/vanilla.js";
const platform = new Platform();
platform.applyUserAgent("Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36");
console.log(platform.platformName === PlatformType.android, platform.browserName === BrowserType.chrome, platform.isMobile);import { Platform } from "./build/vanilla.js";
const platform = new Platform();
const platformInfo = platform.getPlatformInfo();
console.log(platformInfo.platformName, platformInfo.browserName, platform.isMobile, platform.isDesktopWeb());플랫폼 이름. (PlatformType 값, getPlatformInfo 나 applyUserAgent 가 채운다)
Platform name. (a PlatformType value, filled by getPlatformInfo or applyUserAgent)
반환Returnsstring
짝Counterpart: vanilla-engine Platform.get_platform_name
브라우저 이름. (BrowserType 값, getPlatformInfo 나 applyUserAgent 가 채운다)
Browser name. (a BrowserType value, filled by getPlatformInfo or applyUserAgent)
반환Returnsstring
짝Counterpart: vanilla-engine Platform.get_browser_name
모바일 기기인지. (user agent 에 Mobi, Android, iPhone, iPad 가 있으면 참)
Whether it is a mobile device. (true if the user agent contains Mobi, Android, iPhone or iPad)
반환Returnsboolean
짝Counterpart: vanilla-engine Platform.is_mobile
캔버스 생성 or 반환.
Creates or returns the canvas.
- canvasIdstring
- 찾을 요소의 id.id of the element to find.
반환ReturnsHTMLCanvasElement 그 id 의 요소. (없으면 캔버스를 만들어 id 를 주고 body 끝에 붙인다)The element with that id. (if none, a canvas is created with that id and appended to the end of body)
플랫폼 정보 탐지 및 적용.
Detects and applies platform information.
반환Returns{ platformName: string, browserName: string } navigator.userAgent 로 고른 플랫폼 이름과 브라우저 이름. (platformName, browserName, isMobile 필드도 채운다)Platform name and browser name detected from navigator.userAgent. (also fills the platformName, browserName and isMobile fields)
짝Counterpart: vanilla-engine Platform.get_platform_info
user agent 글로 플랫폼, 브라우저, 모바일 여부 고르기. (getPlatformInfo 가 브라우저의 글로 부른다)
Determines the platform, browser and mobile status from the user agent string. (getPlatformInfo calls it with the browser's string)
- userAgentstring
- 브라우저의 user agent 글. (navigator.userAgent 꼴)User agent string of the browser. (in the navigator.userAgent form)
짝Counterpart: vanilla-engine Platform.apply_user_agent
데스크탑 웹인지 반환. (마우스 휠, 키보드 안내처럼 데스크탑에서만 보일 것을 가릴 때 쓴다)
- 모바일이면 아니다. 아이패드의 사파리는 데스크탑처럼 맥이라고 알리므로, 맥인데 손가락 입력이 여럿 되면 아이패드로 본다.
- 플랫폼 정보를 새로 읽는다.
Returns whether it is desktop web. (Used to decide things shown only on desktop, like mouse wheel or keyboard hints)
- Not if mobile. Safari on iPad reports itself as Mac like a desktop, so a Mac with multi-touch input is treated as an iPad.
- Reads platform information anew.
반환Returnsboolean 데스크탑 웹이면 참.True if it is desktop web.
짝Counterpart: vanilla-engine Platform.is_desktop_web
주된 손이 손가락인지 반환. (CSS 의 pointer: coarse, 단축키 안내처럼 마우스로 하는 화면에만 보일 것을 가릴 때 쓴다)
Returns whether the primary pointer is a finger. (CSS pointer: coarse, used to decide things shown only on mouse-driven screens, like shortcut hints)
반환Returnsboolean (pointer: coarse) 미디어 질의가 맞으면 참. (matchMedia 가 없으면 거짓)True if the (pointer: coarse) media query matches. (false if matchMedia is not available)
짝Counterpart: vanilla-engine Platform.is_coarse_pointer
리소스 사용량 반환.
Returns resource usage.
반환Returns{ totalTransferSize: number, totalDecodedSize: number, loadedFiles: array } 네트워크로 받은 크기의 합, 풀린 크기의 합(바이트)과 불러온 파일 목록. (파일마다 path, name, type, transferSize, decodedSize, performance 의 resource 항목에서 읽는다)Total transferred size, total decoded size (bytes) and the list of loaded files. (path, name, type, transferSize, decodedSize per file, read from the resource entries of performance)
짝Counterpart: vanilla-engine Platform.get_resource_usage
리소스 사용량 반환. (옛 이름의 오타를 그대로 둔 별칭, getResourceUsage 와 같다)
Returns resource usage. (Alias that keeps the typo of the old name, same as getResourceUsage)
반환Returns{ totalTransferSize: number, totalDecodedSize: number, loadedFiles: array } getResourceUsage 의 결과.Result of getResourceUsage.
짝Counterpart: vanilla-engine Platform.get_resouce_usage
세이프 에어리어 반환.
Returns the safe area.
- canvasHTMLCanvasElement | null
- 크기를 잴 캔버스. (CSS 크기 clientWidth, clientHeight 를 쓴다, null 이면 창의 innerWidth, innerHeight 를 쓴다)Canvas to measure. (uses its CSS size clientWidth, clientHeight; if null, the window's innerWidth, innerHeight)
반환ReturnsRect 세이프 에어리어 여백을 뺀 사각형. (모두 CSS 픽셀, left, top 은 왼쪽, 위 여백, 여백은 CSS 의 env(safe-area-inset-*) 값, 너비와 높이는 0 이상)Rectangle with the safe area insets removed. (all in CSS pixels; left and top are the left and top insets, the insets are the CSS env(safe-area-inset-*) values, width and height are 0 or more)
짝Counterpart: vanilla-engine Platform.get_safe_area_rect
import { Platform } from "./build/vanilla.js";
const platform = new Platform();
const canvas = platform.getOrAddCanvas("gameCanvas");
canvas.width = 640;
canvas.height = 360;
const safeAreaRect = platform.getSafeAreaRect(canvas);
console.log(safeAreaRect.left, safeAreaRect.top, safeAreaRect.width, safeAreaRect.height);PlatformTypeenum
플랫폼 타입.
Platform type.
| 이름Name | 값Value | 설명Description |
|---|---|---|
windows | Windows | 윈도우.Windows. |
macOS | macOS | 맥.Mac. |
android | Android | 안드로이드.Android. |
steamDeck | SteamDeck | 스팀덱 추가Steam Deck added |
iPadOS | iPadOS | iPadOS 추가iPadOS added |
iOS | iOS | 아이폰, 아이팟.iPhone, iPod. |
linux | Linux | 리눅스.Linux. |
unknown | Unknown | 알 수 없음.Unknown. |
BrowserTypeenum
브라우저 타입.
Browser type.
| 이름Name | 값Value | 설명Description |
|---|---|---|
chrome | Chrome | 크롬.Chrome. |
edge | Edge | 엣지.Edge. |
firefox | Firefox | 파이어폭스.Firefox. |
internetExplorer | Internet Explorer | 인터넷 익스플로러.Internet Explorer. |
safari | Safari | 사파리.Safari. |
unknown | Unknown | 알 수 없음.Unknown. |