vanilladocs
vanillapunch.com
API / base/platform

base/platform

플랫폼 정보.

Platform information.

Platformextends Object

짝Counterpart: vanilla-engine Platform

플랫폼 정보.

Platform information.

예제Exampleuser agent 글로 플랫폼 가리기Detect the platform from a user agent string
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);
예제Example지금 기기 알아보기Detect the current device
import { Platform } from "./build/vanilla.js";

const platform = new Platform();
const platformInfo = platform.getPlatformInfo();
console.log(platformInfo.platformName, platformInfo.browserName, platform.isMobile, platform.isDesktopWeb());
생성자constructorconstructor()#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

짝Counterpart: vanilla-engine Platform.new

필드fieldplatformName#0.0.8 부터since 0.0.8소스source

플랫폼 이름. (PlatformType 값, getPlatformInfo 나 applyUserAgent 가 채운다)

Platform name. (a PlatformType value, filled by getPlatformInfo or applyUserAgent)

반환Returnsstring

짝Counterpart: vanilla-engine Platform.get_platform_name

필드fieldbrowserName#0.0.8 부터since 0.0.8소스source

브라우저 이름. (BrowserType 값, getPlatformInfo 나 applyUserAgent 가 채운다)

Browser name. (a BrowserType value, filled by getPlatformInfo or applyUserAgent)

반환Returnsstring

짝Counterpart: vanilla-engine Platform.get_browser_name

필드fieldisMobile = false#0.0.8 부터since 0.0.8소스source

모바일 기기인지. (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

메서드methodgetOrAddCanvas(canvasId)#0.2.0 부터since 0.2.0소스source

캔버스 생성 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)

메서드methodgetPlatformInfo()#0.0.8 부터since 0.0.8소스source

플랫폼 정보 탐지 및 적용.

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

메서드methodapplyUserAgent(userAgent)#0.4.0 부터since 0.4.0소스source

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

메서드methodisDesktopWeb()#0.4.0 부터since 0.4.0소스source

데스크탑 웹인지 반환. (마우스 휠, 키보드 안내처럼 데스크탑에서만 보일 것을 가릴 때 쓴다)

  • 모바일이면 아니다. 아이패드의 사파리는 데스크탑처럼 맥이라고 알리므로, 맥인데 손가락 입력이 여럿 되면 아이패드로 본다.
  • 플랫폼 정보를 새로 읽는다.

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

메서드methodisCoarsePointer()#0.4.0 부터since 0.4.0소스source

주된 손이 손가락인지 반환. (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

메서드methodgetResourceUsage()#0.4.0 부터since 0.4.0소스source

리소스 사용량 반환.

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

메서드methodgetResouceUsage()#0.0.8 부터since 0.0.8소스source

리소스 사용량 반환. (옛 이름의 오타를 그대로 둔 별칭, 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

메서드methodgetSafeAreaRect(canvas)#0.0.8 부터since 0.0.8소스source

세이프 에어리어 반환.

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

예제Example캔버스에서 노치를 피한 자리 구하기Get the area of a canvas that avoids the notch
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

짝Counterpart: vanilla-engine PlatformType

플랫폼 타입.

Platform type.

이름Name값Value설명Description
windowsWindows윈도우.Windows.
macOSmacOS맥.Mac.
androidAndroid안드로이드.Android.
steamDeckSteamDeck스팀덱 추가Steam Deck added
iPadOSiPadOSiPadOS 추가iPadOS added
iOSiOS아이폰, 아이팟.iPhone, iPod.
linuxLinux리눅스.Linux.
unknownUnknown알 수 없음.Unknown.

BrowserTypeenum

짝Counterpart: vanilla-engine BrowserType

브라우저 타입.

Browser type.

이름Name값Value설명Description
chromeChrome크롬.Chrome.
edgeEdge엣지.Edge.
firefoxFirefox파이어폭스.Firefox.
internetExplorerInternet Explorer인터넷 익스플로러.Internet Explorer.
safariSafari사파리.Safari.
unknownUnknown알 수 없음.Unknown.