vanilladocs
vanillapunch.com
API / misc/visual

misc/visual

비주얼 컴포넌트. (원본 misc/visual.js 의 Visual, 비주얼 에디터 문서를 정한 자리에 노드 트리로 짓는다)

  • 문서는 비주얼 에디터(vanilla.js tools/visualeditor)가 저장하는 UIDocument JSON 글이다. ({ version, root, frameSize? }, 씬과 프리팹 모두) VisualAsset 이 파일을 읽어 문서를 든 Visual 을 만든다.
  • create_node 가 문서의 노드 트리를 새로 지어 뿌리의 로컬 위치를 location 으로 둔다. (부르는 쪽이 원하는 부모에 붙인다, 부를 때마다 새 트리)
  • 스스로 그리거나 갱신하지 않는다.
  • 원본과 다른 점: 원본 createNode() 는 전역 UIDocument 로 짓고, 러스트 판 create_node 는 짓는 UIDocument 와 노드 트리를 받는다. (러스트 UIDocument 는 등록 표를 든 값이다) 원본이 문서가 없으면 null, 문서 꼴이 틀리면 예외인 것은 Ok(None), Err 다.

Visual component. (Visual of the original misc/visual.js, builds a visual editor document into a node tree at a set location)

  • The document is the UIDocument JSON text saved by the visual editor (vanilla.js tools/visualeditor). ({ version, root, frameSize? }, both scenes and prefabs) VisualAsset reads the file and makes a Visual holding the document.
  • create_node builds a new node tree from the document and sets the root's local position to location. (The caller attaches it to the parent it wants, a new tree on every call)
  • It does not draw or update by itself.
  • Difference from the original: the original createNode() builds with the global UIDocument, the Rust create_node takes the UIDocument to build with and the node tree. (A Rust UIDocument is a value holding the registration tables) Where the original returns null for no document and throws for a malformed one, Rust gives Ok(None) and Err.

Visualstruct traits Default, Component

짝Counterpart: vanilla.js Visual소스source

비주얼 컴포넌트.

  • 비주얼 에디터 문서 글과 위치를 든다. create_node 가 그 문서로 새 노드 트리를 짓는다. 그리지도 갱신하지도 않는다. (is_tick_needed 가 false)

Visual component.

  • Holds visual editor document text and a location. create_node builds a new node tree from that document. It does not draw or update. (is_tick_needed is false)
예제Example문서를 든 비주얼로 노드 트리 짓기Build a node tree from a visual holding a document
use vanilla::{Component, NodeTree, UIDocument, Vector2, Visual};

let document_text = r#"{"version":1,"root":{"type":"WorldNode","name":"Badge","position":[300,200],"contentSize":[64,64],"components":[],"children":[]}}"#;
let mut visual = Visual::new();
visual.set_document_text(Some(document_text.to_string()));
visual.set_location(Vector2::create(40.0, 20.0));

let mut document = UIDocument::new();
let mut node_tree = NodeTree::new();
let parent_id = node_tree.create_node("parent");
let badge_id = visual.create_node(&mut document, &mut node_tree).expect("document").expect("root");
assert!(node_tree.add_child(parent_id, badge_id));
assert_eq!(node_tree[badge_id].get_name(), "Badge");
assert_eq!(node_tree[badge_id].get_local_position(), Vector2::create(40.0, 20.0));
assert_eq!(node_tree.get_parent_id(badge_id), Some(parent_id));
assert_eq!(visual.get_component_type(), "Visual");
생성자constructorpub fn new() -> Visual#0.3.2 부터since 0.3.2소스source

생성. (위치 0)

Constructor. (position 0)

반환ReturnsVisual 문서 글이 없고 위치가 (0, 0) 인 비주얼.A visual with no document text at location (0, 0).

짝Counterpart: vanilla.js Visual.constructor

메서드methodpub fn set_location(&mut self, location: Vector2)#0.3.2 부터since 0.3.2소스source

위치 설정.

Sets the position.

locationVector2
create_node 가 지은 뿌리 노드에 줄 로컬 위치. (부모 기준, 기본 0)Local position given to the root node built by create_node. (Relative to the parent, default 0)

짝Counterpart: vanilla.js Visual.setLocation

메서드methodpub fn get_location(&self) -> Vector2#0.3.2 부터since 0.3.2소스source

위치 반환.

Returns the position.

반환ReturnsVector2 지은 뿌리 노드에 줄 로컬 위치.Local position given to the built root node.

짝Counterpart: vanilla.js Visual.getLocation

메서드methodpub fn set_document_text(&mut self, document_text: Option<String>)#0.4.0 부터since 0.4.0소스source

문서 글 설정.

Set the document text.

document_textOption<String>
비주얼 에디터가 저장한 UIDocument JSON 글. (None 이면 비운다, 읽는 것은 create_node 때)UIDocument JSON text saved by the visual editor. (None clears it, it is read at create_node)

짝Counterpart: vanilla.js Visual.setDocumentText

메서드methodpub fn get_document_text(&self) -> Option<&str>#0.4.0 부터since 0.4.0소스source

문서 글 반환.

Get the document text.

반환ReturnsOption<&str> 든 문서 글. 없으면 None.Held document text. None when there is none.

짝Counterpart: vanilla.js Visual.getDocumentText

메서드methodpub fn create_node(&self, document: &mut UIDocument, node_tree: &mut NodeTree) -> Result<Option<NodeId>, String>#0.4.0 부터since 0.4.0소스source

문서로 노드 트리 짓기.

Build a node tree from the document.

document&mut UIDocument
노드와 컴포넌트를 지을 UIDocument. (게임이 등록한 종류와 그림 해석기를 쓴다)UIDocument that builds the nodes and components. (Uses the kinds and image resolver the game registered)
node_tree&mut NodeTree
지을 노드 트리.Node tree to build in.

반환ReturnsResult<Option<NodeId>, String> 새로 지은 뿌리 노드. (어느 부모에도 붙지 않았고 로컬 위치가 location 이다) 문서가 없으면 Ok(None), 문서 꼴이 틀리면 Err.Newly built root node. (Not attached to any parent, its local position is location) Ok(None) when there is no document, Err when the document is malformed.

짝Counterpart: vanilla.js Visual.createNode

예제Example문서가 없을 때, 꼴이 틀릴 때, 같은 문서로 두 벌 짓기No document, a malformed document, and two copies from the same document
use vanilla::{NodeTree, UIDocument, Vector2, Visual};

let mut document = UIDocument::new();
let mut node_tree = NodeTree::new();
let mut visual = Visual::new();
assert_eq!(visual.create_node(&mut document, &mut node_tree), Ok(None));
visual.set_document_text(Some(String::from(r#"{"version":1}"#)));
assert!(visual.create_node(&mut document, &mut node_tree).is_err());

visual.set_document_text(Some(String::from(r#"{"version":1,"root":{"type":"WorldNode","name":"Coin","contentSize":[32,32],"components":[],"children":[]}}"#)));
let first_id = visual.create_node(&mut document, &mut node_tree).expect("document").expect("root");
visual.set_location(Vector2::create(48.0, 0.0));
let second_id = visual.create_node(&mut document, &mut node_tree).expect("document").expect("root");
assert_ne!(first_id, second_id);
assert_eq!(node_tree[second_id].get_name(), "Coin");
assert_eq!(node_tree[first_id].get_local_position().x, 0.0);
assert_eq!(node_tree[second_id].get_local_position().x, 48.0);
assert!(node_tree.get_parent_id(second_id).is_none());