vanilladocs
vanillapunch.com
API / platform/document

platform/document

문서. (원본이 브라우저 document 에서 읽고 쓰는 것: html 의 lang, head 의 meta)

  • 원본은 전역 document 를 그대로 쓴다. LanguagePack 이 언어를 불러오면 document.documentElement.lang 을 바꾸고, BuildInfo 는 meta[name="build-version"] 의 content 에서 배포 빌드가 적어 둔 판을 읽는다.
  • 웹은 원본처럼 브라우저 문서를 읽고 쓴다.
  • 데스크탑은 HTML 문서가 없어, 엔진이 스레드마다 문서 값(언어, meta 목록)을 들고 같은 일을 한다. 처음 값은 EngineConfiguration 의 document_language, document_meta_list 다. (웹 판의 index.html 이 html lang 과 head 의 meta 로 적어 두는 자리) 배포 빌드가 웹 판의 index.html 에 판을 적듯, 데스크탑 게임은 빌드할 때 넣은 값(build.rs 의 rustc-env 와 env! 같은 것)을 document_meta_list 에 넣는다.
  • 엔진 설정의 값은 웹에서도 비어 있지 않으면 엔진을 만들 때 문서에 쓴다. (같은 게임 코드가 두 플랫폼에서 같은 문서를 갖는다) 비어 있으면 웹은 페이지가 적어 둔 그대로다.

Document. (what the original reads and writes in the browser document: html lang, meta in head)

  • The original uses the global document as is. When LanguagePack loads a language it changes document.documentElement.lang, and BuildInfo reads the version written by the release build from the content of meta[name="build-version"].
  • On web it reads and writes the browser document as in the original.
  • Desktop has no HTML document, so the engine holds document values (language, meta list) per thread and does the same work. Initial values are document_language and document_meta_list of EngineConfiguration. (where the web version's index.html writes html lang and the meta in head) Just as the release build writes the version into the web version's index.html, a desktop game puts values inserted at build time (such as rustc-env of build.rs and env!) into document_meta_list.
  • On web too, the engine settings' values are written to the document when the engine is created if they are not empty. (the same game code has the same document on both platforms) If empty, on web it stays as the page wrote it.

Documentstruct

소스source

문서. (정적 함수 묶음, 원본 전역 document 의 lang 과 meta)

Document. (a set of static functions, lang and meta of the original global document)

예제Example언어와 판 meta 쓰고 읽기Write and read the language and version meta
use vanilla::Document;

Document::set_language("en");
assert_eq!(Document::get_language(), "en");
Document::set_meta_content("build-version", "1.2.3");
assert_eq!(Document::get_meta_content("build-version"), Some(String::from("1.2.3")));
Document::remove_meta("build-version");
assert_eq!(Document::get_meta_content("build-version"), None);
정적staticpub fn get_language() -> String#0.4.0 부터since 0.4.0소스source

문서 언어. (원본 document.documentElement.lang, 적지 않았으면 빈 글)

Document language. (the original document.documentElement.lang, empty text if not written)

반환ReturnsString 언어 태그. ("ko", "en-US" 같은, 적지 않았으면 빈 글)Language tag. (such as "ko", "en-US", empty text if not written)

정적staticpub fn set_language(language: &str)#0.4.0 부터since 0.4.0소스source

문서 언어 설정. (원본 document.documentElement.lang = 언어 태그)

Sets the document language. (the original document.documentElement.lang = language tag)

language&str
언어 태그. ("ko", "en-US" 같은)Language tag. (such as "ko", "en-US")
정적staticpub fn get_meta_content(meta_name: &str) -> Option<String>#0.4.0 부터since 0.4.0소스source

meta 의 content. (원본 document.querySelector(meta[name="이름"]).getAttribute("content"), 그런 meta 가 없으면 None)

content of a meta. (the original document.querySelector(meta[name="name"]).getAttribute("content"), None if there is no such meta)

meta_name&str
meta 의 name. ("build-version" 같은)name of the meta. (such as "build-version")

반환ReturnsOption<String> 그 이름의 첫 meta 의 content. 그런 meta 가 없으면 None.content of the first meta with that name. None if there is no such meta.

정적staticpub fn set_meta_content(meta_name: &str, content: &str)#0.4.0 부터since 0.4.0소스source

meta 의 content 설정. (그 이름의 meta 가 없으면 head 끝에 만든다)

Sets the content of a meta. (creates one at the end of head if there is no meta with that name)

meta_name&str
meta 의 name.name of the meta.
content&str
쓸 content.content to write.
정적staticpub fn remove_meta(meta_name: &str)#0.4.0 부터since 0.4.0소스source

meta 지우기. (그 이름의 첫 meta)

Removes a meta. (the first meta with that name)

meta_name&str
지울 meta 의 name. (없으면 아무것도 하지 않는다)name of the meta to remove. (does nothing if missing)