Compare commits

..

141 Commits

Author SHA1 Message Date
Lucien Greathouse
90661b7743 Release 0.5.0-alpha.12 2019-07-02 16:46:11 -07:00
Lucien Greathouse
d07571ea7e Theme adjustments 2019-07-02 16:29:59 -07:00
Lucien Greathouse
fbf29e336f Adjust theme colors with new brand, not very pretty yet 2019-07-02 16:27:19 -07:00
Lucien Greathouse
09a0a803a1 Update image branding in the plugin 2019-07-02 16:22:01 -07:00
Lucien Greathouse
dd0327ba85 Update Changelog in prep for next release 2019-07-02 16:18:04 -07:00
Lucien Greathouse
d900887d97 Add a test for meta files attached to Lua scripts 2019-07-02 16:15:24 -07:00
Lucien Greathouse
2a0efe70a5 Add rough tests to ensure broken projects stay broken 2019-07-02 16:09:49 -07:00
Lucien Greathouse
ce09e57315 Tighten up meta files a bit more 2019-07-02 15:53:44 -07:00
Lucien Greathouse
91023c5239 Update more repository links 2019-07-02 15:37:10 -07:00
Lucien Greathouse
714fb10fac Remove old docs scripts and update links to new repo 2019-07-02 15:35:29 -07:00
Lucien Greathouse
aa3e43207f Update documentation to include meta docs 2019-07-02 15:30:56 -07:00
Lucien Greathouse
e045989d39 Update Changelog 2019-06-27 22:31:05 -07:00
Lucien Greathouse
ad5695210d More strict .meta.json files 2019-06-27 22:24:44 -07:00
Lucien Greathouse
4dab6e5008 Update README 2019-06-24 11:27:40 -07:00
Lucien Greathouse
522f26cf4e Update docs config for new repo 2019-06-22 23:41:16 -07:00
Lucien Greathouse
3eca4bc439 Rework README 2019-06-21 18:02:09 -07:00
Lucien Greathouse
b374f67b52 Merge branch 'onboarding-docs' 2019-06-21 17:54:01 -07:00
Lucien Greathouse
c68277be2c Update docs links 2019-06-21 17:51:38 -07:00
Lucien Greathouse
bb8a3e82e6 New doc site 2019-06-21 17:44:08 -07:00
Lucien Greathouse
b511d4ba53 Update dependencies 2019-06-21 17:20:38 -07:00
Lucien Greathouse
fd997d4bda Update README 2019-06-20 15:34:35 -07:00
Lucien Greathouse
21d04a9f85 Add another bullet point 2019-06-19 10:41:44 -07:00
Lucien Greathouse
dcb5c12197 Fill out some new docs 2019-06-17 16:06:25 -07:00
Lucien Greathouse
125e8766c5 Fix failing snapshot test from previous change 2019-06-16 16:46:38 -07:00
Lucien Greathouse
7bce1f6df4 docs: Fix typos on 'Why Rojo' page 2019-06-16 16:29:08 -07:00
Lucien Greathouse
8f66fb6fef Set source path on rbxm/rbxmx models 2019-06-13 17:40:28 -07:00
Lucien Greathouse
711e009e6d Rename InitMeta to ExtraMetadata 2019-06-12 18:33:59 -07:00
Lucien Greathouse
212fe31cb3 Tweak mechanism that ignores .meta.json files 2019-06-12 18:29:48 -07:00
boyned//Kampfkarren
a3dc4fa001 Support for .meta.json files other than init (#189)
* Support for .meta.json files other than init

* Localize .meta.json application
2019-06-12 18:22:47 -07:00
Lucien Greathouse
ff53113358 Add test project for recent project strictness change 2019-06-12 16:02:27 -07:00
Lucien Greathouse
94cbe15b54 Reserve names starting with a dollar sign, closes #191. 2019-06-12 15:54:28 -07:00
Lucien Greathouse
90516e035d Refactor project to start making a little more sense 2019-06-12 15:11:19 -07:00
Lucien Greathouse
c77c754f6d Give plugin GUI a name 2019-06-11 18:00:12 -07:00
Lucien Greathouse
288c52a2cd Updated changelog 2019-06-11 17:56:06 -07:00
Lucien Greathouse
f0fa7326dd Add an icon to the plugin toolbar button 2019-06-11 17:52:12 -07:00
Lucien Greathouse
f29b0f2f26 New UI, simpler 2019-06-11 17:31:42 -07:00
Lucien Greathouse
5dcac24f99 Add a square Rojo logo with transparent background 2019-06-11 15:00:21 -07:00
Lucien Greathouse
1eb11ac377 Add R logo icons 2019-06-11 15:00:09 -07:00
Lucien Greathouse
2e89cdcfad Fix malformed Enum being emitted when using Project::save 2019-06-10 18:05:10 -07:00
Lucien Greathouse
1b0beccd3d Update Changelog 2019-06-10 17:52:44 -07:00
Lucien Greathouse
abb5a72fc4 Update Changelog 2019-06-10 17:47:04 -07:00
Lucien Greathouse
bf706f7586 plugin: Upgrade Roact and rbx-dom 2019-06-10 17:29:03 -07:00
Lucien Greathouse
4459663510 Upgrade rbx-dom dependencies 2019-06-10 17:26:34 -07:00
Lucien Greathouse
68a34dc28b Add a test project with unions 2019-06-10 16:46:05 -07:00
Lucien Greathouse
ba1826587c docs: Add TypeScript section to 'Why Rojo?' 2019-06-07 20:45:59 -07:00
Lucien Greathouse
2e7a8d50b0 Add a warning when trying to load 0.4.x projects 2019-06-07 18:45:30 -07:00
Lucien Greathouse
2a4ca21050 Substantial documentation improvements 2019-06-07 18:29:09 -07:00
boyned//Kampfkarren
0ed6c57c7f init.meta.json support (#183)
* A minimum viable product for init.meta.json

* Properties support

* Add ignoreUnknownChildren support

* Apply requested changes

* Use reflection guiding

* Add a script to the test

* Change to ignoreUnknownInstances

* Apply requested changes
2019-06-06 16:58:58 -07:00
Lucien Greathouse
983d44947e Upgrade rbx-dom 2019-05-31 13:34:54 -07:00
Lucien Greathouse
5bd88dc82f plugin: Switch to Roact refactored bindings branch, with real joinBindings! 2019-05-31 13:23:17 -07:00
Lucien Greathouse
51bbab803f Update CHANGELOG 2019-05-30 23:59:14 -07:00
Lucien Greathouse
a587ba4558 Add warning for rojo build to rbxl 2019-05-30 23:57:35 -07:00
Lucien Greathouse
075b6cca30 Use new rbx_dom_lua API 2019-05-30 18:37:56 -07:00
Lucien Greathouse
4c263bbb3e plugin: Update to newer rbx-dom with better error handling 2019-05-29 18:40:58 -07:00
Lucien Greathouse
420627d892 0.5.0-alpha.11 2019-05-29 14:07:15 -07:00
Lucien Greathouse
ce3a409997 Undo 0.5.0-alpha.10 release due to regression 2019-05-29 13:38:36 -07:00
Lucien Greathouse
0f9f1782ae 0.5.0-alpha.10 2019-05-29 13:24:06 -07:00
Lucien Greathouse
d4704a02c5 Upgrade dependencies 2019-05-29 13:15:22 -07:00
Lucien Greathouse
9ca2ed2c93 plugin: upgrade Roact 2019-05-16 18:45:35 -07:00
Lucien Greathouse
ae12ffdefb Work around Roact bug 2019-05-16 18:45:00 -07:00
Lucien Greathouse
1e13097126 plugin: update rbx-dom 2019-05-16 18:33:37 -07:00
Lucien Greathouse
9b8a6b1168 Add terrain test project 2019-05-16 18:03:11 -07:00
Lucien Greathouse
8f6dda5cd3 Use rbx_xml 0.9.0's config to read unknown properties 2019-05-16 17:58:32 -07:00
Lucien Greathouse
91780f236e Update dependencies 2019-05-16 17:58:19 -07:00
Lucien Greathouse
f16474815c plugin: update rbx-dom 2019-05-15 11:19:05 -07:00
Lucien Greathouse
a8ff6d7e6e Update dependencies 2019-05-14 18:23:01 -07:00
Lucien Greathouse
8395782a2e Use Display instead of Debug for rbx_xml errors now 2019-05-14 17:55:18 -07:00
Lucien Greathouse
28ea625b01 Plugin: Port reconciler to use rbx_dom_lua 2019-05-14 14:22:55 -07:00
Lucien Greathouse
efc569f6ed Plugin: Update rbx-dom 2019-05-14 14:22:44 -07:00
Lucien Greathouse
d377e10771 Update rbx-dom 2019-05-13 17:35:55 -07:00
Lucien Greathouse
fef85877e6 Add safeguards against accidentally committing model or place files 2019-05-13 17:29:41 -07:00
Lucien Greathouse
19135bfaf4 Add RbxDom library as piece of plugin 2019-05-13 17:29:41 -07:00
Lucien Greathouse
5a147fccc2 Add rbx-dom as Git submodule to plugin 2019-05-13 17:29:41 -07:00
Lucien Greathouse
20976814ba Upgrade a bunch of small dependencies 2019-05-12 12:57:59 -07:00
Lucien Greathouse
27e2612fc9 Upgrade rbx_dom_weak, rbx_reflection, and rbx_xml 2019-05-12 12:57:24 -07:00
Lucien Greathouse
3ea432ef2d Fix up docs on model/place files a little 2019-05-09 13:29:03 -07:00
Lucien Greathouse
fe6acbc1e3 Clean up repo cruft 2019-05-04 21:01:10 -07:00
Lucien Greathouse
379b162e64 Fix dependency paths changing.
Roact 1.0 changed from lib to src!
t changed from lib/t.lua to lib/init.lua, so we just use lib
2019-05-04 19:33:08 -07:00
Lucien Greathouse
84832955dd Upgrade to Roact 1.0 and latest t 2019-05-04 00:05:45 -07:00
Lucien Greathouse
34b99a51c3 Relax debug assert in IMFS, since paths can alias now 2019-04-30 23:06:59 -07:00
Lucien Greathouse
fb5245e2af Update dependencies 2019-04-22 18:26:28 -07:00
Diego Alpízar
ff0a830e0c Minor typo fix (#156)
Fix repeated "available available"
2019-04-06 23:38:29 -07:00
eryn L. K
a365f071a4 Update installation.md (#155) 2019-04-05 17:20:53 -07:00
Lucien Greathouse
f290e7b5b2 Support implicit values in JSON models (#154)
* Support implicit values in JSON models

* Update Changelog
2019-04-05 15:17:58 -07:00
Lucien Greathouse
83a0ae673c 0.5.0-alpha.9 2019-04-04 21:20:00 -07:00
Lucien Greathouse
7de646c290 Upgrade dependencies 2019-04-04 18:35:18 -07:00
Lucien Greathouse
5d681a72ac Rewrite CSV conversion to dodge Serde (#152)
* Rewrite CSV conversion to dodge Serde

* Update CHANGELOG
2019-04-04 18:21:55 -07:00
Lucien Greathouse
d725970e6e Fix handling of CSV files with empty columns and rows (#149)
* Fix #147

* Add localization test project, fix empty rows in general

* Fill out 'normal' CSV in localization test project

* Update Changelog
2019-04-04 13:16:10 -07:00
Lucien Greathouse
54b82760cd Switch 'rojo build' to use BufWriter, magic performance increase 2019-04-01 18:02:46 -07:00
Lucien Greathouse
77f79fa913 0.5.0-alpha.8 2019-03-29 17:36:43 -07:00
Lucien Greathouse
6db714a2b1 Special-case Lighting.Technology in setCanonicalProperty, temporary fix 2019-03-29 17:25:57 -07:00
Lucien Greathouse
913ac7c9f5 Update dependencies 2019-03-28 15:44:56 -07:00
Lucien Greathouse
eecbfd29e7 Update dependencies, adding a bunch of new features 2019-03-27 13:31:12 -07:00
Lucien Greathouse
41025225b2 Rewrite message queue with oneshot futures (#139) 2019-03-27 13:27:50 -07:00
Lucien Greathouse
07c7b28c03 Fix plugin unloading 2019-03-21 22:35:30 -07:00
Lucien Greathouse
3faf3d2a56 Update Changelog for #135 2019-03-20 10:42:18 -07:00
Lucien Greathouse
be094d5b7c Make snapshot application communicative (#135)
* Add children sorting to snapshot_reconciler

* Update snapshot tests to include stable children order

* Bump dependencies, which should make this PR work
2019-03-20 10:39:53 -07:00
Lucien Greathouse
459673bd59 0.5.0-alpha.6 2019-03-19 18:24:30 -07:00
Lucien Greathouse
2968b70e6b Listen to Plugin.Unloading.
Closes #127.
2019-03-19 18:17:03 -07:00
Lucien Greathouse
b6989a18fc Add conditionally-enabled typechecking using t 2019-03-19 17:57:19 -07:00
Lucien Greathouse
4d6a504836 Remove Rodux and Roact-Rodux, add t dependency 2019-03-19 16:34:53 -07:00
Lucien Greathouse
6c3737df68 Update Changelog 2019-03-19 16:31:34 -07:00
Lucien Greathouse
9f382ed9bd Iterate on plugin reconciler
- Renamed setProperty to setCanonicalProperty, which is more usefully
  descriptive. Also added a detailed comment.
- Fixed reconciler behavior with regards to removing known instances
  when $ignoreUnknownInstances is set
2019-03-19 16:30:06 -07:00
Lucien Greathouse
f9e86e58d6 Add InstanceMap:destroyInstance for forgetting and destroying in one step 2019-03-19 16:29:56 -07:00
Lucien Greathouse
469f9c927f Improve plugin place project for testing 2019-03-19 16:29:31 -07:00
Lucien Greathouse
312724189b Remove ignore from old doc generator script 2019-03-14 14:20:38 -07:00
Lucien Greathouse
ec0a1f1ce4 New snapshot tests (#134)
* Changes project-related structures to use `BTreeMap` instead of `HashMap` for children to aid determiniusm
* Changes imfs-related structures to have total ordering and use `BTreeSet` instead of `HashSet`
* Upgrades dependencies to `bx_dom_weak`1.2.0 and rbx_xml 0.5.0 to aid in more determinism stuff
* Re-exposes the `RbxSession`'s root project via `root_project()`
* Implements `Default` for a couple things
* Tweaks visualization code to support visualizing trees not attached to an `RbxSession`
* Adds an ID-invariant comparison method for `rbx_tree` relying on previous determinism changes
* Adds a (disabled) test to start finding issues in the reconciler with regards to communicativity of snapshot application
* Adds a snapshot testing system that operates on `RbxTree` and associated metadata, which are committed in this change
2019-03-14 14:20:03 -07:00
Lucien Greathouse
ad93631ef8 Port to futures channel instead of std one.
Fixes #133.
2019-03-12 11:45:39 -07:00
Lucien Greathouse
3b6238ff93 Add more types to plugin 2019-03-11 16:55:42 -07:00
Lucien Greathouse
5b9facee00 Fix up variable naming in serialize_unresolved_minimal 2019-03-11 16:35:54 -07:00
Lucien Greathouse
376f2a554a Better default project, including minimal property types 2019-03-11 16:28:40 -07:00
Lucien Greathouse
5fd0bd3db9 Update/prune dependencies with help of cargo-outdated 2019-03-11 14:12:49 -07:00
Lucien Greathouse
2deb3bbf23 Add notable feature from dependency upgrade 2019-03-11 13:48:02 -07:00
Lucien Greathouse
01bef0c2b8 Update dependencies 2019-03-11 13:47:33 -07:00
Lucien Greathouse
b65a8ce680 0.5.0-alpha.5 2019-03-01 15:40:30 -08:00
Lucien Greathouse
5fc4f63238 Upgrade dependencies 2019-03-01 15:34:16 -08:00
Lucien Greathouse
9b0e0c175b Add missing CHANGELOG note 2019-02-27 17:32:36 -08:00
Lucien Greathouse
eb97e925e6 Flip LiveSession::session_id private, add getter 2019-02-27 14:54:05 -08:00
Lucien Greathouse
16f8975b18 Flip project field of LiveSession private to prepare for multi-project future 2019-02-27 14:51:53 -08:00
Lucien Greathouse
5073fce2f7 Implement LiveSession::restart_with_new_project as foundation for reloading 2019-02-27 14:42:41 -08:00
Lucien Greathouse
cf5036eec6 Fix warnings compiling server 2019-02-27 00:49:38 -08:00
Lucien Greathouse
20be37dd8b Improve error messages from bad snapshots 2019-02-27 00:47:02 -08:00
Lucien Greathouse
93349ae2dc Use rbx_reflection to allow type inference on projects (#130)
* Start dependency on rbx_reflection

* Alive and working, all tests pass

* Update CHANGELOG
2019-02-26 22:51:21 -08:00
Lucien Greathouse
be81de74cd Disable Lua tests for now, since they need features Lemur doesn't have 2019-02-24 00:58:02 -08:00
Lucien Greathouse
88e739090d WIP: Server plugins via rlua (Lua 5.3) (#125)
* Add 'plugins' field to project and add rlua

* Scaffold out new SnapshotContext type (again) with plugin state

* Almost functional snapshot system with rlua proof-of-concept

* Gate plugin config on 'plugins-enabled' feature, tell Travis to test all features

* Guard remaining plugin setup code behind feature

* Bump minimum version to 1.33, should've caught this before

* Whoops, latest Rust is 1.32, not 1.33
2019-02-24 00:31:58 -08:00
Lucien Greathouse
7f324f1957 Update CHANGELOG 2019-02-22 15:57:46 -08:00
Lucien Greathouse
4f31c9e72f Fix /api/read and /api/subscribe, re-add debug output 2019-02-22 15:56:24 -08:00
Lucien Greathouse
c9a663ed39 Remove Rouille and port everything to Hyper 2019-02-22 15:11:27 -08:00
Lucien Greathouse
105d8aeb6b Start to stub out sub-services 2019-02-22 13:08:07 -08:00
Lucien Greathouse
6ea1211bc5 It's alive! 2019-02-22 10:50:14 -08:00
Lucien Greathouse
c13291a598 Break apart web interface between UI and API 2019-02-19 11:44:24 -08:00
Lucien Greathouse
aaa78c618c Move diagnostics page to use Ritz, show server version 2019-02-19 11:27:22 -08:00
Lucien Greathouse
2890c677d4 Bump dependency from rbx_tree 0.2.0 to rbx_dom_weak 0.3.0 2019-02-14 17:22:44 -08:00
Lucien Greathouse
51a010de00 Update CHANGELOG 2019-02-11 13:48:20 -08:00
Lucien Greathouse
ca0aabd814 Preload plugin assets at start.
Closes #121.
2019-02-11 13:47:49 -08:00
Lucien Greathouse
91d1ba1910 Add test for rojoValueToRobloxValue, fails Lemur because of missing APIs right now 2019-02-11 11:43:17 -08:00
Lucien Greathouse
c7c739dc00 Fix test bootstrap script for testing in Studio 2019-02-11 11:43:06 -08:00
Lucien Greathouse
7a8389bf11 Update CHANGELOG 2019-02-11 11:42:40 -08:00
Lucien Greathouse
5f062b8ea3 Make the plugin support non-primitive types 2019-02-11 10:55:03 -08:00
Lucien Greathouse
b9ee14a0f9 Remove unused Cargo features section 2019-02-11 10:27:09 -08:00
Lucien Greathouse
c3baf73455 Update documentation for alpha 4 2019-02-08 18:29:23 -08:00
146 changed files with 6713 additions and 2399 deletions

6
.gitignore vendored
View File

@@ -2,4 +2,8 @@
/target
/scratch-project
**/*.rs.bk
/generate-docs.run
/server/failed-snapshots/
/*.rbxm
/*.rbxmx
/*.rbxl
/*.rbxlx

12
.gitmodules vendored
View File

@@ -1,12 +1,6 @@
[submodule "plugin/modules/roact"]
path = plugin/modules/roact
url = https://github.com/Roblox/roact.git
[submodule "plugin/modules/rodux"]
path = plugin/modules/rodux
url = https://github.com/Roblox/rodux.git
[submodule "plugin/modules/roact-rodux"]
path = plugin/modules/roact-rodux
url = https://github.com/Roblox/roact-rodux.git
[submodule "plugin/modules/testez"]
path = plugin/modules/testez
url = https://github.com/Roblox/testez.git
@@ -16,3 +10,9 @@
[submodule "plugin/modules/promise"]
path = plugin/modules/promise
url = https://github.com/LPGhatguy/roblox-lua-promise.git
[submodule "plugin/modules/t"]
path = plugin/modules/t
url = https://github.com/osyrisrblx/t.git
[submodule "plugin/modules/rbx-dom"]
path = plugin/modules/rbx-dom
url = http://github.com/LPGhatguy/rbx-dom

View File

@@ -1,36 +1,41 @@
matrix:
include:
- language: python
env:
- LUA="lua=5.1"
# Lua tests are currently disabled because of holes in Lemur that are pretty
# tedious to fix. It should be fixed by either adding missing features to
# Lemur or by migrating to a CI system based on real Roblox instead.
before_install:
- pip install hererocks
- hererocks lua_install -r^ --$LUA
- export PATH=$PATH:$PWD/lua_install/bin
# - language: python
# env:
# - LUA="lua=5.1"
install:
- luarocks install luafilesystem
- luarocks install busted
- luarocks install luacov
- luarocks install luacov-coveralls
- luarocks install luacheck
# before_install:
# - pip install hererocks
# - hererocks lua_install -r^ --$LUA
# - export PATH=$PATH:$PWD/lua_install/bin
script:
- cd plugin
- luacheck src
- lua -lluacov spec.lua
# install:
# - luarocks install luafilesystem
# - luarocks install busted
# - luarocks install luacov
# - luarocks install luacov-coveralls
# - luarocks install luacheck
after_success:
- cd plugin
- luacov-coveralls -e $TRAVIS_BUILD_DIR/lua_install
# script:
# - cd plugin
# - luacheck src
# - lua -lluacov spec.lua
# after_success:
# - cd plugin
# - luacov-coveralls -e $TRAVIS_BUILD_DIR/lua_install
- language: rust
rust: 1.31.1
rust: 1.32.0
cache: cargo
script:
- cargo test --verbose
- cargo test --verbose --all-features
- language: rust
rust: stable
@@ -38,10 +43,12 @@ matrix:
script:
- cargo test --verbose
- cargo test --verbose --all-features
- language: rust
rust: beta
cache: cargo
script:
- cargo test --verbose
- cargo test --verbose
- cargo test --verbose --all-features

View File

@@ -1,29 +1,104 @@
# Rojo Changelog
## [Unreleased]
## [0.5.0 Alpha 12](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.12) (July 2, 2019)
* Added `.meta.json` files
* `init.meta.json` files replace `init.model.json` files from Rojo 0.4.x ([#183](https://github.com/rojo-rbx/rojo/pull/183))
* Other `.meta.json` files allow attaching extra data to other files ([#189](https://github.com/rojo-rbx/rojo/pull/189))
* Added support for infinite and NaN values in types like `Vector2` when building models and places.
* These types aren't supported for live-syncing yet due to limitations around JSON encoding.
* Added support for using `SharedString` values when building XML models and places.
* Added support for live-syncing `CollectionService` tags.
* Added a warning when building binary place files, since they're still experimental and have bugs.
* Added a warning when trying to use Rojo 0.5.x with a Rojo 0.4.x-only project.
* Added a warning when a Rojo project contains keys that start with `$`, which are reserved names. ([#191](https://github.com/rojo-rbx/rojo/issues/191))
* Rojo now throws an error if unknown keys are found most files.
* Added an icon to the plugin's toolbar button
* Changed the plugin to use a docking widget for all UI.
* Changed the plugin to ignore unknown properties when live-syncing.
* Rojo's approach to this problem might change later, like with a strict model mode ([#190](https://github.com/rojo-rbx/rojo/issues/190)) or another approach.
* Upgraded to reflection database from client release 388.
* Updated Rojo's branding to shift the color palette to make it work better on dark backgrounds
## [0.5.0 Alpha 4](https://github.com/LPGhatguy/rojo/releases/tag/v0.5.0-alpha.4) (February 8, 2019)
* Added support for nested partitions ([#102](https://github.com/LPGhatguy/rojo/issues/102))
* Added support for 'transmuting' partitions ([#112](https://github.com/LPGhatguy/rojo/issues/112))
* Added support for aliasing filesystem paths ([#105](https://github.com/LPGhatguy/rojo/issues/105))
* Changed Windows builds to statically link the CRT ([#89](https://github.com/LPGhatguy/rojo/issues/89))
## [0.5.0 Alpha 11](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.11) (May 29, 2019)
* Added support for implicit property values in JSON model files ([#154](https://github.com/rojo-rbx/rojo/pull/154))
* `Content` propertyes can now be specified in projects and model files as regular string literals.
* Added support for `BrickColor` properties.
* Added support for properties added in client release 384, like `Lighting.Technology` being set to `"ShadowMap"`.
* Improved performance when working with XML models and places
* Fixed serializing empty `Content` properties as XML
* Fixed serializing infinite and NaN floating point properties in XML
* Improved compatibility with XML models
* Plugin should now be able to live-sync more properties, and ignore ones it can't, like `Lighting.Technology`.
## [0.5.0 Alpha 3](https://github.com/LPGhatguy/rojo/releases/tag/v0.5.0-alpha.3) (February 1, 2019)
* Changed default project file name from `roblox-project.json` to `default.project.json` ([#120](https://github.com/LPGhatguy/rojo/pull/120))
## 0.5.0 Alpha 10
* This release was a dud due to [issue #176](https://github.com/rojo-rbx/rojo/issues/176) and was rolled back.
## [0.5.0 Alpha 9](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.9) (April 4, 2019)
* Changed `rojo build` to use buffered I/O, which can make it up to 2x faster in some cases.
* Building [*Road Not Taken*](https://github.com/rojo-rbx/roads) to an `rbxlx` file dropped from 150ms to 70ms on my machine
* Fixed `LocalizationTable` instances being made from `csv` files incorrectly interpreting empty rows and columns. ([#149](https://github.com/rojo-rbx/rojo/pull/149))
* Fixed CSV files with entries that parse as numbers causing Rojo to panic. ([#152](https://github.com/rojo-rbx/rojo/pull/152))
* Improved error messages when malformed CSV files are found in a Rojo project.
## [0.5.0 Alpha 8](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.8) (March 29, 2019)
* Added support for a bunch of new types when dealing with XML model/place files:
* `ColorSequence`
* `Float64`
* `Int64`
* `NumberRange`
* `NumberSequence`
* `PhysicalProperties`
* `Ray`
* `Rect`
* `Ref`
* Improved server instance ordering behavior when files are added during a live session ([#135](https://github.com/rojo-rbx/rojo/pull/135))
* Fixed error being thrown when trying to unload the Rojo plugin.
* Added partial fix for [issue #141](https://github.com/rojo-rbx/rojo/issues/141) for `Lighting.Technology`, which should restore live sync functionality for the default project file.
## [0.5.0 Alpha 6](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.6) (March 19, 2019)
* Fixed `rojo init` giving unexpected results by upgrading to `rbx_dom_weak` 1.1.0
* Fixed live server not responding when the Rojo plugin is connected ([#133](https://github.com/rojo-rbx/rojo/issues/133))
* Updated default place file:
* Improved default properties to be closer to Studio's built-in 'Baseplate' template
* Added a baseplate to the project file (Thanks, [@AmaranthineCodices](https://github.com/AmaranthineCodices/)!)
* Added more type support to Rojo plugin
* Fixed some cases where the Rojo plugin would leave around objects that it knows should be deleted
* Updated plugin to correctly listen to `Plugin.Unloading` when installing or uninstalling new plugins
## [0.5.0 Alpha 5](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.5) (March 1, 2019)
* Upgraded core dependencies, which improves compatibility for lots of instance types
* Upgraded from `rbx_tree` 0.2.0 to `rbx_dom_weak` 1.0.0
* Upgraded from `rbx_xml` 0.2.0 to `rbx_xml` 0.4.0
* Upgraded from `rbx_binary` 0.2.0 to `rbx_binary` 0.4.0
* Added support for non-primitive types in the Rojo plugin.
* Types like `Color3` and `CFrame` can now be updated live!
* Fixed plugin assets flashing in on first load ([#121](https://github.com/rojo-rbx/rojo/issues/121))
* Changed Rojo's HTTP server from Rouille to Hyper, which reduced the release size by around a megabyte.
* Added property type inference to projects, which makes specifying services a lot easier ([#130](https://github.com/rojo-rbx/rojo/pull/130))
* Made error messages from invalid and missing files more user-friendly
## [0.5.0 Alpha 4](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.4) (February 8, 2019)
* Added support for nested partitions ([#102](https://github.com/rojo-rbx/rojo/issues/102))
* Added support for 'transmuting' partitions ([#112](https://github.com/rojo-rbx/rojo/issues/112))
* Added support for aliasing filesystem paths ([#105](https://github.com/rojo-rbx/rojo/issues/105))
* Changed Windows builds to statically link the CRT ([#89](https://github.com/rojo-rbx/rojo/issues/89))
## [0.5.0 Alpha 3](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.3) (February 1, 2019)
* Changed default project file name from `roblox-project.json` to `default.project.json` ([#120](https://github.com/rojo-rbx/rojo/pull/120))
* The old file name will still be supported until 0.5.0 is fully released.
* Added warning when loading project files that don't end in `.project.json`
* This new extension enables Rojo to distinguish project files from random JSON files, which is necessary to support nested projects.
* Added new (empty) diagnostic page served from the server
* Added better error messages for when a file is missing that's referenced by a Rojo project
* Added support for visualization endpoints returning GraphViz source when Dot is not available
* Fixed an in-memory filesystem regression introduced recently ([#119](https://github.com/LPGhatguy/rojo/pull/119))
* Fixed an in-memory filesystem regression introduced recently ([#119](https://github.com/rojo-rbx/rojo/pull/119))
## [0.5.0 Alpha 2](https://github.com/LPGhatguy/rojo/releases/tag/v0.5.0-alpha.2) (January 28, 2019)
## [0.5.0 Alpha 2](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.2) (January 28, 2019)
* Added support for `.model.json` files, compatible with 0.4.x
* Fixed in-memory filesystem not handling out-of-order filesystem change events
* Fixed long-polling error caused by a promise mixup ([#110](https://github.com/LPGhatguy/rojo/issues/110))
* Fixed long-polling error caused by a promise mixup ([#110](https://github.com/rojo-rbx/rojo/issues/110))
## [0.5.0 Alpha 1](https://github.com/LPGhatguy/rojo/releases/tag/v0.5.0-alpha.1) (January 25, 2019)
## [0.5.0 Alpha 1](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.1) (January 25, 2019)
* Changed plugin UI to be way prettier
* Thanks to [Reselim](https://github.com/Reselim) for the design!
* Changed plugin error messages to be a little more useful
@@ -31,7 +106,7 @@
* Fixed bug where bad server responses could cause the plugin to be in a bad state
* Upgraded to rbx\_tree, rbx\_xml, and rbx\_binary 0.2.0, which dramatically expands the kinds of properties that Rojo can handle, especially in XML.
## [0.5.0 Alpha 0](https://github.com/LPGhatguy/rojo/releases/tag/v0.5.0-alpha.0) (January 14, 2019)
## [0.5.0 Alpha 0](https://github.com/rojo-rbx/rojo/releases/tag/v0.5.0-alpha.0) (January 14, 2019)
* "Epiphany" rewrite, in progress since the beginning of time
* New live sync protocol
* Uses HTTP long polling to reduce request count and improve responsiveness
@@ -56,105 +131,105 @@
* Multiple places can be specified, like when building a multi-place game
* Added support for specifying properties on services in project files
## [0.4.13](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.13) (November 12, 2018)
## [0.4.13](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.13) (November 12, 2018)
* When `rojo.json` points to a file or directory that does not exist, Rojo now issues a warning instead of throwing an error and exiting
## [0.4.12](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.12) (June 21, 2018)
* Fixed obscure assertion failure when renaming or deleting files ([#78](https://github.com/LPGhatguy/rojo/issues/78))
* Added a `PluginAction` for the sync in command, which should help with some automation scripts ([#80](https://github.com/LPGhatguy/rojo/pull/80))
## [0.4.12](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.12) (June 21, 2018)
* Fixed obscure assertion failure when renaming or deleting files ([#78](https://github.com/rojo-rbx/rojo/issues/78))
* Added a `PluginAction` for the sync in command, which should help with some automation scripts ([#80](https://github.com/rojo-rbx/rojo/pull/80))
## [0.4.11](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.11) (June 10, 2018)
## [0.4.11](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.11) (June 10, 2018)
* Defensively insert existing instances into RouteMap; should fix most duplication cases when syncing into existing trees.
* Fixed incorrect synchronization from `Plugin:_pull` that would cause polling to create issues
* Fixed incorrect file routes being assigned to `init.lua` and `init.model.json` files
* Untangled route handling-internals slightly
## [0.4.10](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.10) (June 2, 2018)
* Added support for `init.model.json` files, which enable versioning `Tool` instances (among other things) with Rojo. ([#66](https://github.com/LPGhatguy/rojo/issues/66))
## [0.4.10](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.10) (June 2, 2018)
* Added support for `init.model.json` files, which enable versioning `Tool` instances (among other things) with Rojo. ([#66](https://github.com/rojo-rbx/rojo/issues/66))
* Fixed obscure error when syncing into an invalid service.
* Fixed multiple sync processes occurring when a server ID mismatch is detected.
## [0.4.9](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.9) (May 26, 2018)
* Fixed warning when renaming or removing files that would sometimes corrupt the instance cache ([#72](https://github.com/LPGhatguy/rojo/pull/72))
## [0.4.9](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.9) (May 26, 2018)
* Fixed warning when renaming or removing files that would sometimes corrupt the instance cache ([#72](https://github.com/rojo-rbx/rojo/pull/72))
* JSON models are no longer as strict -- `Children` and `Properties` are now optional.
## [0.4.8](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.8) (May 26, 2018)
## [0.4.8](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.8) (May 26, 2018)
* Hotfix to prevent errors from being thrown when objects managed by Rojo are deleted
## [0.4.7](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.7) (May 25, 2018)
* Added icons to the Rojo plugin, made by [@Vorlias](https://github.com/Vorlias)! ([#70](https://github.com/LPGhatguy/rojo/pull/70))
* Server will now issue a warning if no partitions are specified in `rojo serve` ([#40](https://github.com/LPGhatguy/rojo/issues/40))
## [0.4.7](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.7) (May 25, 2018)
* Added icons to the Rojo plugin, made by [@Vorlias](https://github.com/Vorlias)! ([#70](https://github.com/rojo-rbx/rojo/pull/70))
* Server will now issue a warning if no partitions are specified in `rojo serve` ([#40](https://github.com/rojo-rbx/rojo/issues/40))
## [0.4.6](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.6) (May 21, 2018)
* Rojo handles being restarted by Roblox Studio more gracefully ([#67](https://github.com/LPGhatguy/rojo/issues/67))
## [0.4.6](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.6) (May 21, 2018)
* Rojo handles being restarted by Roblox Studio more gracefully ([#67](https://github.com/rojo-rbx/rojo/issues/67))
* Folders should no longer get collapsed when syncing occurs.
* **Significant** robustness improvements with regards to caching.
* **This should catch all existing script duplication bugs.**
* If there are any bugs with script duplication or caching in the future, restarting the Rojo server process will fix them for that session.
* Fixed message in plugin not being prefixed with `Rojo: `.
## [0.4.5](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.5) (May 1, 2018)
## [0.4.5](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.5) (May 1, 2018)
* Rojo messages are now prefixed with `Rojo: ` to make them stand out in the output more.
* Fixed server to notice file changes *much* more quickly. (200ms vs 1000ms)
* Server now lists name of project when starting up.
* Rojo now throws an error if no project file is found. ([#63](https://github.com/LPGhatguy/rojo/issues/63))
* Fixed multiple sync operations occuring at the same time. ([#61](https://github.com/LPGhatguy/rojo/issues/61))
* Partitions targeting files directly now work as expected. ([#57](https://github.com/LPGhatguy/rojo/issues/57))
* Rojo now throws an error if no project file is found. ([#63](https://github.com/rojo-rbx/rojo/issues/63))
* Fixed multiple sync operations occuring at the same time. ([#61](https://github.com/rojo-rbx/rojo/issues/61))
* Partitions targeting files directly now work as expected. ([#57](https://github.com/rojo-rbx/rojo/issues/57))
## [0.4.4](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.4) (April 7, 2018)
## [0.4.4](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.4) (April 7, 2018)
* Fix small regression introduced in 0.4.3
## [0.4.3](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.3) (April 7, 2018)
* Plugin now automatically selects `HttpService` if it determines that HTTP isn't enabled ([#58](https://github.com/LPGhatguy/rojo/pull/58))
## [0.4.3](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.3) (April 7, 2018)
* Plugin now automatically selects `HttpService` if it determines that HTTP isn't enabled ([#58](https://github.com/rojo-rbx/rojo/pull/58))
* Plugin now has much more robust handling and will wipe all state when the server changes.
* This should fix issues that would otherwise be solved by restarting Roblox Studio.
## [0.4.2](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.2) (April 4, 2018)
## [0.4.2](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.2) (April 4, 2018)
* Fixed final case of duplicated instance insertion, caused by reconciled instances not being inserted into `RouteMap`.
* The reconciler is still not a perfect solution, especially if script instances get moved around without being destroyed. I don't think this can be fixed before a big refactor.
## [0.4.1](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.1) (April 1, 2018)
## [0.4.1](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.1) (April 1, 2018)
* Merged plugin repository into main Rojo repository for easier tracking.
* Improved `RouteMap` object tracking; this should fix some cases of duplicated instances being synced into the tree.
## [0.4.0](https://github.com/LPGhatguy/rojo/releases/tag/v0.4.0) (March 27, 2018)
## [0.4.0](https://github.com/rojo-rbx/rojo/releases/tag/v0.4.0) (March 27, 2018)
* Protocol version 1, which shifts more responsibility onto the server
* This is a **major breaking** change!
* The server now has a content of 'filter plugins', which transform data at various stages in the pipeline
* The server now exposes Roblox instance objects instead of file contents, which lines up with how `rojo pack` will work, and paves the way for more robust syncing.
* Added `*.model.json` files, which let you embed small Roblox objects into your Rojo tree.
* Improved error messages in some cases ([#46](https://github.com/LPGhatguy/rojo/issues/46))
* Improved error messages in some cases ([#46](https://github.com/rojo-rbx/rojo/issues/46))
## [0.3.2](https://github.com/LPGhatguy/rojo/releases/tag/v0.3.2) (December 20, 2017)
## [0.3.2](https://github.com/rojo-rbx/rojo/releases/tag/v0.3.2) (December 20, 2017)
* Fixed `rojo serve` failing to correctly construct an absolute root path when passed as an argument
* Fixed intense CPU usage when running `rojo serve`
## [0.3.1](https://github.com/LPGhatguy/rojo/releases/tag/v0.3.1) (December 14, 2017)
## [0.3.1](https://github.com/rojo-rbx/rojo/releases/tag/v0.3.1) (December 14, 2017)
* Improved error reporting when invalid JSON is found in a `rojo.json` project
* These messages are passed on from Serde
## [0.3.0](https://github.com/LPGhatguy/rojo/releases/tag/v0.3.0) (December 12, 2017)
## [0.3.0](https://github.com/rojo-rbx/rojo/releases/tag/v0.3.0) (December 12, 2017)
* Factored out the plugin into a separate repository
* Fixed server when using a file as a partition
* Previously, trailing slashes were put on the end of a partition even if the read request was an empty string. This broke file reading on Windows when a partition pointed to a file instead of a directory!
* Started running automatic tests on Travis CI (#9)
## [0.2.3](https://github.com/LPGhatguy/rojo/releases/tag/v0.2.3) (December 4, 2017)
## [0.2.3](https://github.com/rojo-rbx/rojo/releases/tag/v0.2.3) (December 4, 2017)
* Plugin only release
* Tightened `init` file rules to only match script files
* Previously, Rojo would sometimes pick up the wrong file when syncing
## [0.2.2](https://github.com/LPGhatguy/rojo/releases/tag/v0.2.2) (December 1, 2017)
## [0.2.2](https://github.com/rojo-rbx/rojo/releases/tag/v0.2.2) (December 1, 2017)
* Plugin only release
* Fixed broken reconciliation behavior with `init` files
## [0.2.1](https://github.com/LPGhatguy/rojo/releases/tag/v0.2.1) (December 1, 2017)
## [0.2.1](https://github.com/rojo-rbx/rojo/releases/tag/v0.2.1) (December 1, 2017)
* Plugin only release
* Changes default port to 8000
## [0.2.0](https://github.com/LPGhatguy/rojo/releases/tag/v0.2.0) (December 1, 2017)
## [0.2.0](https://github.com/rojo-rbx/rojo/releases/tag/v0.2.0) (December 1, 2017)
* Support for `init.lua` like rbxfs and rbxpacker
* More robust syncing with a new reconciler
## [0.1.0](https://github.com/LPGhatguy/rojo/releases/tag/v0.1.0) (November 29, 2017)
* Initial release, functionally very similar to [rbxfs](https://github.com/LPGhatguy/rbxfs)
## [0.1.0](https://github.com/rojo-rbx/rojo/releases/tag/v0.1.0) (November 29, 2017)
* Initial release, functionally very similar to [rbxfs](https://github.com/rojo-rbx/rbxfs)

1669
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,7 @@
[workspace]
members = [
"server",
"rojo-e2e",
]
]
[profile.dev]
opt-level = 1

View File

@@ -1,68 +1,56 @@
<div align="center">
<img src="assets/rojo-logo.png" alt="Rojo" height="217" />
<a href="https://rojo.space">
<img src="assets/rojo-logo.png" alt="Rojo" height="217" />
</a>
</div>
<div>&nbsp;</div>
<div align="center">
<a href="https://travis-ci.org/LPGhatguy/rojo">
<img src="https://api.travis-ci.org/LPGhatguy/rojo.svg?branch=master" alt="Travis-CI Build Status" />
<a href="https://travis-ci.org/rojo-rbx/rojo">
<img src="https://api.travis-ci.org/rojo-rbx/rojo.svg?branch=master" alt="Travis-CI Build Status" />
</a>
<a href="https://crates.io/crates/rojo">
<img src="https://img.shields.io/crates/v/rojo.svg?label=version" alt="Latest server version" />
</a>
<a href="https://lpghatguy.github.io/rojo/0.4.x">
<img src="https://img.shields.io/badge/docs-0.4.x-brightgreen.svg" alt="Rojo Documentation" />
<a href="https://rojo.space/docs/0.4.x">
<img src="https://img.shields.io/badge/docs-0.4.x-brightgreen.svg" alt="Rojo 0.4.x Documentation" />
</a>
<a href="https://lpghatguy.github.io/rojo/0.5.x">
<img src="https://img.shields.io/badge/docs-0.5.x-brightgreen.svg" alt="Rojo Documentation" />
<a href="https://rojo.space/docs/0.5.x">
<img src="https://img.shields.io/badge/docs-0.5.x-brightgreen.svg" alt="Rojo 0.5.x Documentation" />
</a>
</div>
<hr />
**Rojo** is a flexible multi-tool designed for creating robust Roblox projects.
**Rojo** is a tool designed to enable Roblox developers to use professional-grade software engineering tools.
It lets Roblox developers use industry-leading tools like Git and VS Code, and crucial utilities like Luacheck.
With Rojo, it's possible to use industry-leading tools like **Visual Studio Code** and **Git**.
Rojo is designed for **power users** who want to use the **best tools available** for building games, libraries, and plugins.
Rojo is designed for power users who want to use the best tools available for building games, libraries, and plugins.
## Features
Rojo lets you:
Rojo enables:
* Work on scripts from the filesystem, in your favorite editor
* Version your place, model, or plugin using Git or another VCS
* Sync `rbxmx` and `rbxm` models into your game in real time
* Package and deploy your project to Roblox.com from the command line
* Working on scripts and models from the filesystem, in your favorite editor
* Versioning your game, library, or plugin using Git or another VCS
* Streaming `rbxmx` and `rbxm` models into your game in real time
* Packaging and deploying your project to Roblox.com from the command line
Soon, Rojo will be able to:
* Automatically convert your existing game to work with Rojo
* Sync instances from Roblox Studio to the filesystem
* Compile MoonScript and other custom things for your project
* Automatically manage your assets on Roblox.com, like images and sounds
* Import custom instances like MoonScript code
## [Documentation](https://lpghatguy.github.io/rojo)
You can also view the documentation by browsing the [docs](https://github.com/LPGhatguy/rojo/tree/master/docs) folder of the repository, but because it uses a number of Markdown extensions, it may not be very readable.
## Inspiration and Alternatives
There are lots of other tools that sync scripts into Roblox or provide other tools for working with Roblox places.
Here are a few, if you're looking for alternatives or supplements to Rojo:
* [rbxmk by Anaminus](https://github.com/anaminus/rbxmk)
* [Rofresh by Osyris](https://github.com/osyrisrblx/rofresh)
* [RbxRefresh by Osyris](https://github.com/osyrisrblx/RbxRefresh)
* [Studio Bridge by Vocksel](https://github.com/vocksel/studio-bridge)
* [Elixir by Vocksel](https://github.com/vocksel/elixir)
* [RbxSync by evaera](https://github.com/evaera/RbxSync)
* [CodeSync by MemoryPenguin](https://github.com/MemoryPenguin/CodeSync)
* [rbx-exteditor by MemoryPenguin](https://github.com/MemoryPenguin/rbx-exteditor)
If you use a plugin that _isn't_ Rojo for syncing code, open an issue and let me know why! I'd like Rojo to be the end-all tool so that people stop reinventing solutions to this problem.
## [Documentation](https://rojo.space/docs/latest)
If you find any mistakes, feel free to make changes in the [docs](https://github.com/rojo-rbx/rojo/tree/master/docs) folder of this repository and submit a pull request!
## Contributing
Pull requests are welcome!
Rojo supports Rust 1.31.1 and newer. Any changes to the minimum required compiler version require a _minor_ version bump.
Rojo supports Rust 1.32 and newer.
## License
Rojo is available under the terms of the Mozilla Public License, Version 2.0. See [LICENSE.txt](LICENSE.txt) for details.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 430 B

View File

@@ -1,39 +0,0 @@
digraph G {
graph [
ranksep = "0.7",
nodesep = "1.0",
];
node [
fontname = "Hack",
shape = "record",
];
roblox_studio -> plugin [dir = "both"];
plugin -> web_server [style = "dashed", dir = "both"];
web_server -> session;
session -> rbx_session;
session -> fs_watcher;
session -> message_queue;
fs_watcher -> imfs [weight = "10"];
fs_watcher -> rbx_session [constraint = "false"];
imfs -> fs;
rbx_session -> imfs;
rbx_session -> middlewares [weight = "10"];
rbx_session -> message_queue [constraint = "false"];
plugin [label = "Studio Plugin"];
roblox_studio [label = "Roblox Studio"];
fs [label = "Filesystem"];
fs_watcher [label = "Filesystem Watcher"];
session [label = "Session"];
web_server [label = "Web API"];
imfs [label = "In-Memory Filesystem"];
rbx_session [label = "RbxSession"];
message_queue [label = "MessageQueue"];
middlewares [label = "Middlewares"];
}

View File

@@ -1,68 +0,0 @@
[TOC]
## Creating the Rojo Project
To use Rojo to build a place, you'll need to create a new project file, which tells Rojo how your project is structured on-disk and in Roblox.
Create a new folder, then run `rojo init` inside that folder to initialize an empty project.
```sh
mkdir my-new-project
cd my-new-project
rojo init
```
Rojo will make a small project file in your directory, named `default.project.json`. It'll make sure that any code in the directory `src` will get put into `ReplicatedStorage.Source`.
Speaking of, let's make sure we create a directory named `src`, and maybe a Lua file inside of it:
```sh
mkdir src
echo 'print("Hello, world!")' > src/hello.lua
```
## Building Your Place
Now that we have a project, one thing we can do is build a Roblox place file for our project. This is a great way to get started with a project quickly with no fuss.
All we have to do is call `rojo build`:
```sh
rojo build -o MyNewProject.rbxl
```
If you open `MyNewProject.rbxl` in Roblox Studio now, you should see a `Folder` containing a `ModuleScript` under `ReplicatedStorage`!
!!! info
To generate an XML place file instead, like if you're checking the place file into version control, just use `rbxlx` as the extension on the output file instead.
## Live-Syncing into Studio
Building a place file is great for the initial build, but for actively working on your place, you'll want something quicker.
In Roblox Studio, make sure the Rojo plugin is installed. If you need it, check out [the installation guide](installation) to learn how to install it.
To expose your project to the plugin, you'll need to _serve_ it from the command line:
```sh
rojo serve
```
This will start up a web server that tells Roblox Studio what instances are in your project and sends notifications if any of them change.
Note the port number, then switch into Roblox Studio and press the Rojo **Connect** button in the plugins tab. Type in the port number, if necessary, and press **Start**.
If everything went well, you should now be able to change files in the `src` directory and watch them sync into Roblox Studio in real time!
## Uploading Your Place
Aimed at teams that want serious levels of automation, Rojo can upload places to Roblox.com automatically.
You'll need an existing place on Roblox.com as well as the `.ROBLOSECURITY` cookie of an account that has write access to that place.
!!! warning
It's recommended that you set up a Roblox account dedicated to deploying your place instead of your personal account in case your security cookie is compromised.
Generating and uploading your place file is as simple as:
```sh
rojo upload --asset_id [PLACE ID] --cookie "[SECURITY COOKIE]"
```

View File

@@ -1,3 +1,13 @@
.md-typeset__table {
width: 100%;
}
.feature-image img {
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2);
}
.codehilite {
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2);
}

View File

@@ -0,0 +1,11 @@
**This page is under construction!**
## Summary
* Tools to port existing games are in progress!
* [rbxlx-to-rojo](https://github.com/rojo/rbxlx-to-rojo)
* `rojo export` ([issue #208](https://github.com/rojo-rbx/rojo/issues/208))
* Can port as much or as little of your game as you like
* Rojo can manage just a slice of your game!
* Some Roblox idioms aren't very well supported
* Redundant copies of scripts don't work well with files
* Having only a couple places with scripts simplifies your project dramatically!

View File

@@ -1,7 +1,8 @@
This is this installation guide for Rojo **0.5.x**.
[TOC]
## Overview
Rojo has two components:
* The command line interface (CLI)
@@ -12,6 +13,9 @@ Rojo has two components:
The plugin will show errors in the Roblox Studio output window if there is a version mismatch.
## Visual Studio Code Extension
If you use Visual Studio Code, you can install [the Rojo VS Code extension](https://marketplace.visualstudio.com/items?itemName=evaera.vscode-rojo), which will install both halves of Rojo for you. It even has a nifty UI to sync files and start/stop the Rojo server!
## Installing the CLI
### Installing from GitHub
@@ -25,21 +29,18 @@ If you have Rust installed, the easiest way to get Rojo is with Cargo!
To install the latest 0.5.0 alpha, use:
```sh
cargo install rojo --version 0.5.0-alpha.3
cargo install rojo --version 0.5.0-alpha.12
```
## Installing the Plugin
### Installing from GitHub
The Rojo Roblox Studio plugin is available available from Rojo's [GitHub Releases page](https://github.com/LPGhatguy/rojo/releases).
The Rojo Roblox Studio plugin is available from Rojo's [GitHub Releases page](https://github.com/LPGhatguy/rojo/releases).
Download the attached `rbxm` file and put it into your Roblox Studio plugins folder. You can find that folder by pressing **Plugins Folder** from your Plugins toolbar in Roblox Studio:
!['Plugins Folder' button in Roblox Studio](images/plugins-folder-in-studio.png)
!['Plugins Folder' button in Roblox Studio](../images/plugins-folder-in-studio.png)
{: align="center" }
### Installing from Roblox.com
Visit [Rojo's Roblox.com Plugin page](https://www.roblox.com/library/1997686364/Rojo-0-5-0-alpha-3) in Roblox Studio and press **Install**.
## Visual Studio Code Extension
If you use Visual Studio Code on Windows, you can install [Evaera's unofficial Rojo extension](https://marketplace.visualstudio.com/items?itemName=evaera.vscode-rojo), which will install both halves of Rojo for you. It even has a nifty UI to add partitions and start/stop the Rojo server!
Visit [Rojo's Roblox.com Plugin page](https://www.roblox.com/library/1997686364/Rojo-0-5-0-alpha-3) in Roblox Studio and press **Install**.

View File

@@ -55,4 +55,9 @@ All other values are considered children, where the key is the instance's name,
## Migrating Unknown Files
If you used Rojo to sync in files as `StringValue` objects, you'll need to make sure those files end with the `txt` extension to preserve this in Rojo 0.5.x.
Unknown files are now ignored in Rojo instead of being converted to `StringValue` objects.
Unknown files are now ignored in Rojo instead of being converted to `StringValue` objects.
## Migrating `init.model.json` files
In Rojo 0.4.x, it's possible to create a file named `init.model.json` that lets you describe a model that becomes the container for all of the other files in the folder, just like `init.lua`.
In Rojo 0.5.x, this feature has been replaced with `init.meta.json` files. See [Sync Details](../reference/sync-details) for more information about these new files.

90
docs/guide/new-game.md Normal file
View File

@@ -0,0 +1,90 @@
[TOC]
## Creating the Rojo Project
To use Rojo to build a game, you'll need to create a new project file, which tells Rojo how to turn your files into a Roblox place.
First, create a new folder to contain the files for your game and open up a new terminal inside of it, like cmd.exe or Bash.
It's convenient to make the folder from the command line:
```sh
mkdir my-new-project
cd my-new-project
```
Inside the folder, initialize a new Rojo project:
```sh
rojo init
```
Rojo will make a small project file in your directory, named `default.project.json`. It matches the "Baseplate" template from Roblox Studio, except that it'll take any files you put in a folder called `src` and put it into `ReplicatedStorage.Source`.
Speaking of files, make sure to create a directory named `src` in this folder, or Rojo will be upset about missing files!
```sh
mkdir src
```
Let's also add a Lua file, `hello.lua` to the `src` folder, so that we can make this project our own.
```sh
echo 'return "Hello, Rojo!"' > src/hello.lua
```
## Building Your Place
Now that we have a project, one thing we can do is build a Roblox place file for our project. This is a great way to get started with a project quickly with no fuss.
All we have to do is call `rojo build`:
```sh
rojo build -o MyNewProject.rbxlx
```
If you open `MyNewProject.rbxlx` in Roblox Studio now, you should see a `Folder` containing a `ModuleScript` under `ReplicatedStorage`!
!!! info
To generate a binary place file instead, use `rbxl`. Note that support for binary model/place files (`rbxm` and `rbxl`) is very limited in Rojo presently.
## Live-Syncing into Studio
Building a place file is great for starting to work on a game, but for active iteration, you'll want something faster.
In Roblox Studio, make sure the Rojo plugin is installed. If you need it, check out [the installation guide](installation) to learn how to install it.
To expose your project to the plugin, you'll need to start a new **live sync session** from the command line:
```sh
rojo serve
```
You should see output like this in your terminal:
```sh
$ rojo serve
Rojo server listening on port 34872
```
Switch into Roblox Studio and press the **Connect** button on the Rojo plugin toolbar. A dialog should appear:
![Rojo plugin connection dialog](../images/connection-dialog.png)
{: class="feature-image" align="center" }
If the port number doesn't match the output from the command line, change it, and then press **Connect**.
If all went well, you should now be able to change files in the `src` directory and watch them sync into Roblox Studio in real time!
## Uploading Your Place
Aimed at teams that want serious levels of automation, Rojo can upload places to Roblox.com automatically.
You'll need an existing game on Roblox.com as well as the `.ROBLOSECURITY` cookie of an account that has write access to that game.
!!! warning
It's recommended that you set up a Roblox account dedicated to deploying your game instead of your personal account in case your security cookie is compromised.
Generating and publishing your game is as simple as:
```sh
rojo upload --asset_id [PLACE ID] --cookie "[SECURITY COOKIE]"
```
An example project is available on GitHub that deploys to Roblox.com from GitHub and Travis-CI automatically: [https://github.com/LPGhatguy/roads](https://github.com/LPGhatguy/roads)

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -2,10 +2,10 @@ This is the documentation home for Rojo 0.5.x.
Available versions of these docs:
* [Latest version (currently 0.5.x)](https://lpghatguy.github.io/rojo)
* [0.5.x](https://lpghatguy.github.io/rojo/0.5.x)
* [0.4.x](https://lpghatguy.github.io/rojo/0.4.x)
* [Latest version (currently 0.5.x)](https://rojo.space/docs/latest)
* [0.5.x](https://rojo.space/docs/0.5.x)
* [0.4.x](https://rojo.space/docs/0.4.x)
**Rojo** is a flexible multi-tool designed for creating robust Roblox projects.
This documentation is a continual work in progress. If you find any issues, please file an issue on [Rojo's issue tracker](https://github.com/LPGhatguy/rojo/issues)!
This documentation is a continual work in progress. If you find any issues, please file an issue on [Rojo's issue tracker](https://github.com/rojo-rbx/rojo/issues)!

View File

@@ -0,0 +1,37 @@
Rojo is designed to be adopted incrementally. How much of your project Rojo manages is up to you!
There are two primary categories of ways to use Rojo: *Fully Managed*, where everything is managed by Rojo, and *Partially Managed*, where Rojo only manages a slice of your project.
## Fully Managed
In a fully managed game project, Rojo controls every instance. A fully managed Rojo project can be built from scratch using `rojo build`.
Fully managed projects are most practical for libraries, plugins, and simple games.
Rojo's goal is to make it practical and easy for _every_ project to be fully managed, but we're not quite there yet!
### Pros
* Fully reproducible builds from scratch
* Everything checked into version control
### Cons
* Without two-way sync, models have to be saved manually
* This can be done with the 'Save to File...' menu in Roblox Studio
* This will be solved by Two-Way Sync ([issue #164](https://github.com/LPGhatguy/rojo/issues/164))
* Rojo can't manage everything yet
* Refs are currently broken ([issue #142](https://github.com/LPGhatguy/rojo/issues/142))
## Partially Managed
In a partially managed project, Rojo only handles a slice of the game. This could be as small as a couple scripts, or as large as everything except `Workspace`!
The rest of the place's content can be versioned using Team Create or checked into source control.
Partially managed projects are most practical for complicated games, or games that are migrating to use Rojo.
### Pros
* Easier to adopt gradually
* Integrates with Team Create
### Cons
* Not everything is in version control, which makes merges tougher
* Rojo can't live-sync instances like Terrain, MeshPart, or CSG operations yet
* Will be fixed with plugin escalation ([issue #169](https://github.com/LPGhatguy/rojo/issues/169))

View File

@@ -24,19 +24,70 @@ Instance Descriptions correspond one-to-one with the actual Roblox Instances in
All other fields in an Instance Description are turned into instances whose name is the key. These values should also be Instance Descriptions!
Instance Descriptions are fairly verbose and strict. In the future, it'll be possible for Rojo to infer class names for known services like `Workspace`.
Instance Descriptions are fairly verbose and strict. In the future, it'll be possible for Rojo to [infer class names for known services like `Workspace`](https://github.com/LPGhatguy/rojo/issues/179).
## Instance Property Value
The shape of Instance Property Values is defined by the [rbx_tree](https://github.com/LPGhatguy/rbx-tree) library, so it uses slightly different conventions than the rest of Rojo.
There are two kinds of property values on instances, **implicit** and **explicit**.
In the vast majority of cases, you should be able to use **implicit** property values. To use them, just use a value that's the same shape as the type that the property has:
```json
"MyPart": {
"$className": "Part",
"$properties": {
"Size": [3, 5, 3],
"Color": [0.5, 0, 0.5],
"Anchored": true,
"Material": "Granite"
}
}
```
`Vector3` and `Color3` properties can just be arrays of numbers, as can types like `Vector2`, `CFrame`, and more!
Enums can be set to a string containing the enum variant. Rojo will raise an error if the string isn't a valid variant for the enum.
There are some cases where this syntax for assigning properties _doesn't_ work. In these cases, Rojo requires you to use the **explicit** property syntax.
Some reasons why you might need to use an **explicit** property:
* Using exotic property types like `BinaryString`
* Using properties added to Roblox recently that Rojo doesn't know about yet
The shape of explicit property values is defined by the [rbx-dom](https://github.com/LPGhatguy/rbx-dom) library, so it uses slightly different conventions than the rest of Rojo.
Each value should be an object with the following required fields:
* `Type`: The type of property to represent.
* [Supported types can be found here](https://github.com/LPGhatguy/rbx-tree#property-type-coverage).
* `Value`: The value of the property.
* The shape of this field depends on which property type is being used. `Vector3` and `Color3` values are both represented as a list of numbers, for example.
* The shape of this field depends on which property type is being used. `Vector3` and `Color3` values are both represented as a list of numbers, while `BinaryString` expects a base64-encoded string, for example.
Instance Property Values are intentionally very strict. Rojo will eventually be able to infer types for you!
Here's the same object, but with explicit properties:
```json
"MyPart": {
"$className": "Part",
"$properties": {
"Size": {
"Type": "Vector3",
"Value": [3, 5, 3]
},
"Color": {
"Type": "Color3",
"Value": [0.5, 0, 0.5]
},
"Anchored": {
"Type": "Bool",
"Value": true
},
"Material": {
"Type": "Enum",
"Value": 832
}
}
}
```
## Example Projects
This project bundles up everything in the `src` directory. It'd be suitable for making a plugin or model:
@@ -61,10 +112,7 @@ This project describes the layout you might use if you were making the next hit
"HttpService": {
"$className": "HttpService",
"$properties": {
"HttpEnabled": {
"Type": "Bool",
"Value": true
}
"HttpEnabled": true
}
},
@@ -85,10 +133,7 @@ This project describes the layout you might use if you were making the next hit
"Workspace": {
"$className": "Workspace",
"$properties": {
"Gravity": {
"Type": "Float32",
"Value": 67.3
}
"Gravity": 67.3
},
"Terrain": {

View File

@@ -0,0 +1,144 @@
This page aims to describe how Rojo turns files on the filesystem into Roblox objects.
[TOC]
## Overview
| File Name | Instance Type |
| -------------- | ------------------------- |
| any directory | `Folder` |
| `*.server.lua` | `Script` |
| `*.client.lua` | `LocalScript` |
| `*.lua` | `ModuleScript` |
| `*.csv` | `LocalizationTable` |
| `*.txt` | `StringValue` |
| `*.model.json` | Any |
| `*.rbxm` | Any |
| `*.rbxmx` | Any |
| `*.meta.json` | Modifies another instance |
## Limitations
Not all property types can be synced by Rojo in real-time due to limitations of the Roblox Studio plugin API. In these cases, you can usually generate a place file and open it when you start working on a project.
Some common cases you might hit are:
* Binary data (Terrain, CSG, CollectionService tags)
* `MeshPart.MeshId`
* `HttpService.HttpEnabled`
For a list of all property types that Rojo can reason about, both when live-syncing and when building place files, look at [rbx-dom's type coverage chart](https://github.com/rojo-rbx/rbx-dom#property-type-coverage).
This limitation may be solved by [issue #205](https://github.com/rojo-rbx/rojo/issues/205) in the future.
## Folders
Any directory on the filesystem will turn into a `Folder` instance unless it contains an 'init' script, described below.
## Scripts
The default script type in Rojo projects is `ModuleScript`, since most scripts in well-structued Roblox projects will be modules.
If a directory contains a file named `init.server.lua`, `init.client.lua`, or `init.lua`, that folder will be transformed into a `*Script` instance with the contents of the 'init' file. This can be used to create scripts inside of scripts.
For example, these files:
![Tree of files on disk](../images/sync-example-files.svg)
{: align="center" }
Will turn into these instances in Roblox:
![Tree of instances in Roblox](../images/sync-example-instances.svg)
{: align="center" }
## Localization Tables
Any CSV files are transformed into `LocalizationTable` instances. Rojo expects these files to follow the same format that Roblox does when importing and exporting localization information.
## Plain Text Files
Plain text files (`.txt`) files are transformed into `StringValue` instances. This is useful for bringing in text data that can be read by scripts at runtime.
## JSON Models
Files ending in `.model.json` can be used to describe simple models. They're designed to be hand-written and are useful for instances like `RemoteEvent`.
A JSON model describing a folder containing a `Part` and a `RemoteEvent` could be described as:
```json
{
"Name": "My Cool Model",
"ClassName": "Folder",
"Children": [
{
"Name": "RootPart",
"ClassName": "Part",
"Properties": {
"Size": {
"Type": "Vector3",
"Value": [4, 4, 4]
}
}
},
{
"Name": "SendMoney",
"ClassName": "RemoteEvent"
}
]
}
```
It would turn into instances in this shape:
![Tree of instances in Roblox](../images/sync-example-json-model.svg)
{: align="center" }
## Binary and XML Models
Rojo supports both binary (`.rbxm`) and XML (`.rbxmx`) models generated by Roblox Studio or another tool.
Support for the `rbxmx` is very good, while support for `rbxm` is still very early, buggy, and lacking features.
For a rundown of supported types, check out [rbx-dom's type coverage chart](https://github.com/rojo-rbx/rbx-dom#property-type-coverage).
## Meta Files
New in Rojo 0.5.0-alpha.12 are meta files, named `.meta.json`.
Meta files allow attaching extra Rojo data to models defined in other formats, like Roblox's `rbxm` and `rbxmx` model formats, or even Lua scripts.
This can be used to set Rojo-specific settings like `ignoreUnknownInstances`, or can be used to set properties like `Disabled` on a script.
Meta files can contain:
* `className`: Changes the `className` of a containing `Folder` into something else.
* Usable only in `init.meta.json` files
* `properties`: A map of properties to set on the instance, just like projects
* Usable on anything except `.rbxmx`, `.rbxm`, and `.model.json` files, which already have properties
* `ignoreUnknownInstances`: Works just like `$ignoreUnknownInstances` in project files
### Meta Files to set Rojo metadata
Sometimes it's useful to apply properties like `ignoreUnknownInstances` on instances that are defined on the filesystem instead of within the project itself.
### Meta Files for Disabled Scripts
Meta files can be used to set properties on `Script` instances, like `Disabled`.
If your project had `foo.server.lua` and you wanted to make sure it would be disabled, you could create a `foo.meta.json` next to it with:
```json
{
"properties": {
"Disabled": true
}
}
```
### Meta Files for Tools
If you wanted to represent a tool containing a script and a model for its handle, create a directory with an `init.meta.json` file in it:
```json
{
"className": "Tool",
"properties": {
"Grip": [
0, 0, 0,
1, 0, 0,
0, 1, 0,
0, 0, 1,
]
}
}
```
Instead of a `Folder` instance, you'll end up with a `Tool` instance with the `Grip` property set!

23
docs/rojo-alternatives.md Normal file
View File

@@ -0,0 +1,23 @@
There are a number of existing plugins for Roblox that move code from the filesystem into Roblox.
Besides Rojo, you might consider:
* [rbxmk by Anaminus](https://github.com/anaminus/rbxmk)
* [Rofresh by Osyris](https://github.com/osyrisrblx/rofresh)
* [RbxRefresh by Osyris](https://github.com/osyrisrblx/RbxRefresh)
* [Studio Bridge by Vocksel](https://github.com/vocksel/studio-bridge)
* [Elixir by Vocksel](https://github.com/vocksel/elixir)
* [RbxSync by evaera](https://github.com/evaera/RbxSync)
* [CodeSync by MemoryPenguin](https://github.com/MemoryPenguin/CodeSync)
* [rbx-exteditor by MemoryPenguin](https://github.com/MemoryPenguin/rbx-exteditor)
So why did I build Rojo?
Each of these tools solves what is essentially the same problem from a few different angles. The goal of Rojo is to take all of the lessons and ideas learned from these projects and build a tool that can solve this problem for good.
Additionally:
* I think that this tool needs to be built in a compiled language without a runtime, for easy distribution and good performance.
* I think that the conventions promoted by other sync plugins (`.module.lua` for modules, as well a single sync point) are sub-optimal.
* I think that I have a good enough understanding of the problem to build something robust.
* I think that Rojo should be able to do more than just sync code.

View File

@@ -1,91 +0,0 @@
This page aims to describe how Rojo turns files on the filesystem into Roblox objects.
[TOC]
## Overview
| File Name | Instance Type |
| -------------- | ------------------- |
| any directory | `Folder` |
| `*.server.lua` | `Script` |
| `*.client.lua` | `LocalScript` |
| `*.lua` | `ModuleScript` |
| `*.csv` | `LocalizationTable` |
| `*.txt` | `StringValue` |
| `*.model.json` | Any |
| `*.rbxm` | Any |
| `*.rbxmx` | Any |
## Limitations
Not all property types can be synced by Rojo in real-time due to limitations of the Roblox Studio plugin API. In these cases, you can usually generate a place file and open it when you start working on a project.
Some common cases you might hit are:
* Binary data (Terrain, CSG, CollectionService tags)
* `MeshPart.MeshId`
* `HttpService.HttpEnabled`
For a list of all property types that Rojo can reason about, both when live-syncing and when building place files, look at [rbx_tree's type coverage chart](https://github.com/LPGhatguy/rbx-tree#property-type-coverage).
## Folders
Any directory on the filesystem will turn into a `Folder` instance unless it contains an 'init' script, described below.
## Scripts
The default script type in Rojo projects is `ModuleScript`, since most scripts in well-structued Roblox projects will be modules.
If a directory contains a file named `init.server.lua`, `init.client.lua`, or `init.lua`, that folder will be transformed into a `*Script` instance with the contents of the 'init' file. This can be used to create scripts inside of scripts.
For example, these files:
![Tree of files on disk](images/sync-example-files.svg)
{: align="center" }
Will turn into these instances in Roblox:
![Tree of instances in Roblox](images/sync-example-instances.svg)
{: align="center" }
## Localization Tables
Any CSV files are transformed into `LocalizationTable` instances. Rojo expects these files to follow the same format that Roblox does when importing and exporting localization information.
## Plain Text Files
Plain text files (`.txt`) files are transformed into `StringValue` instances. This is useful for bringing in text data that can be read by scripts at runtime.
## JSON Models
Files ending in `.model.json` can be used to describe simple models. They're designed to be hand-written and are useful for instances like `RemoteEvent`.
A JSON model describing a folder containing a `Part` and a `RemoteEvent` could be described as:
```json
{
"Name": "My Cool Model",
"ClassName": "Folder",
"Children": [
{
"Name": "RootPart",
"ClassName": "Part",
"Properties": {
"Size": {
"Type": "Vector3",
"Value": [4, 4, 4]
}
}
},
{
"Name": "SendMoney",
"ClassName": "RemoteEvent"
}
]
}
```
It would turn into instances in this shape:
![Tree of instances in Roblox](images/sync-example-json-model.svg)
{: align="center" }
## Binary and XML Models
Rojo supports both binary (`.rbxm`) and XML (`.rbxmx`) models generated by Roblox Studio or another tool.
Not all property types are supported for all formats!
For a rundown of supported types, check out [rbx_tree's type coverage chart](https://github.com/LPGhatguy/rbx-tree#property-type-coverage).

View File

@@ -1,23 +1,39 @@
There are a number of existing plugins for Roblox that move code from the filesystem into Roblox.
Adding a tool like Rojo to your Roblox workflow can be daunting, but it comes with some key advantages.
Besides Rojo, you might consider:
[TOC]
* [rbxmk by Anaminus](https://github.com/anaminus/rbxmk)
* [Rofresh by Osyris](https://github.com/osyrisrblx/rofresh)
* [RbxRefresh by Osyris](https://github.com/osyrisrblx/RbxRefresh)
* [Studio Bridge by Vocksel](https://github.com/vocksel/studio-bridge)
* [Elixir by Vocksel](https://github.com/vocksel/elixir)
* [RbxSync by evaera](https://github.com/evaera/RbxSync)
* [CodeSync by MemoryPenguin](https://github.com/MemoryPenguin/CodeSync)
* [rbx-exteditor by MemoryPenguin](https://github.com/MemoryPenguin/rbx-exteditor)
## External Text Editors
Rojo opens the door to use the absolute best text editors in the world and their rich plugin ecosystems.
So why did I build Rojo?
Some very popular editors include [Visual Studio Code](https://code.visualstudio.com) and [Sublime Text](https://www.sublimetext.com).
Each of these tools solves what is essentially the same problem from a few different angles. The goal of Rojo is to take all of the lessons and ideas learned from these projects and build a tool that can solve this problem for good.
These advanced text editors have features like multi-cursor editing, goto symbol, multi-file regex find and replace, bookmarks and much more.
Additionally:
Many Rojo VS Code users also use extensions like:
* I think that this tool needs to be built in a compiled language without a runtime, for easy distribution and good performance.
* I think that the conventions promoted by other sync plugins (`.module.lua` for modules, as well a single sync point) are sub-optimal.
* I think that I have a good enough understanding of the problem to build something robust.
* I think that Rojo should be able to do more than just sync code.
* [vscode-rbxlua](https://marketplace.visualstudio.com/items?itemName=AmaranthineCodices.vscode-rbxlua)
* [Roblox Lua Autocompletes](https://marketplace.visualstudio.com/items?itemName=Kampfkarren.roblox-lua-autofills)
* [TabNine](https://tabnine.com)
## Version Control
By building your game (or just the scripts) as individual files on the filesystem, it becomes easy to start using professional-grade version control tools like [Git](https://git-scm.com) and [GitHub](https://github.com).
Hundreds of thousands of companies and individual developers use Git to version their software projects. With Rojo, Roblox developers can take advantage of the best collaboration tool around.
Using a repository hosting service like GitHub or GitLab brings powerful features to Roblox developers like code reviews and issue tracking that professional engineers can't live without.
## TypeScript
TypeScript enables static type safety, which helps prevent typos and adds unparalleled autocompletion. It also brings features like arrow functions, object destructuring, functional programming methods, and more!
With Rojo, you can use [roblox-ts](https://roblox-ts.github.io) to compile TypeScript to Lua and take advantage of a huge ecosystem of TypeScript tooling.
It's also possible to use other languages that compile to Lua like [MoonScript](https://moonscript.org) and [Haxe](https://haxe.org).
## Other Tools
There are decades of excellent tools available that operate on files. With Rojo, it's possible to take advantage of any of them!
Popular tools include:
* [luacheck](https://github.com/mpeterv/luacheck), a static analysis tool to help you write better Lua
* [ripgrep](https://github.com/BurntSushi/ripgrep), an extremely fast code search tool
* [Tokei](https://github.com/XAMPPRocky/tokei), a tool for statistics like lines of code

View File

@@ -1,35 +0,0 @@
#!/bin/sh
# Kludged documentation generator to support multiple versions.
# Make sure the `site` folder is a checkout of this repository's `gh-pages`
# branch.
set -e
REMOTE=$(git remote get-url origin)
CHECKOUT="$(mktemp -d)"
OUTPUT="$(pwd)/site"
if [ -d site ]
then
cd site
git pull
else
git clone "$REMOTE" site
cd site
git checkout gh-pages
fi
git clone "$REMOTE" "$CHECKOUT"
cd "$CHECKOUT"
echo "Building master"
git checkout master
mkdocs build --site-dir "$OUTPUT"
echo "Building 0.5.x"
mkdocs build --site-dir "$OUTPUT/0.5.x"
echo "Building 0.4.x"
git checkout v0.4.x
mkdocs build --site-dir "$OUTPUT/0.4.x"

View File

@@ -1,6 +1,6 @@
site_name: Rojo Documentation
repo_name: LPGhatguy/rojo
repo_url: https://github.com/LPGhatguy/rojo
repo_name: rojo-rbx/rojo
repo_url: https://github.com/rojo-rbx/rojo
theme:
name: material
@@ -11,11 +11,16 @@ theme:
nav:
- Home: index.md
- Why Rojo?: why-rojo.md
- Installation: installation.md
- Creating a Place with Rojo: creating-a-place.md
- Migrating from 0.4.x to 0.5.x: migrating-to-epiphany.md
- Project Format: project-format.md
- Sync Details: sync-details.md
- Guide:
- Installation: guide/installation.md
- Creating a Game with Rojo: guide/new-game.md
- Porting an Existing Game to Rojo: guide/existing-game.md
- Migrating from 0.4.x to 0.5.x: guide/migrating-to-epiphany.md
- Reference:
- Fully vs Partially Managed Rojo: reference/full-vs-partial.md
- Project Format: reference/project-format.md
- Sync Details: reference/sync-details.md
- Rojo Alternatives: rojo-alternatives.md
- Rojo Internals:
- Internals Overview: internals/overview.md

View File

@@ -13,6 +13,7 @@ stds.roblox = {
-- Types
"Vector2", "Vector3",
"Vector2int16", "Vector3int16",
"Color3",
"UDim", "UDim2",
"Rect",

View File

@@ -6,16 +6,16 @@
"$path": "src"
},
"Roact": {
"$path": "modules/roact/lib"
},
"Rodux": {
"$path": "modules/rodux/lib"
},
"RoactRodux": {
"$path": "modules/roact-rodux/lib"
"$path": "modules/roact/src"
},
"Promise": {
"$path": "modules/promise/lib"
},
"t": {
"$path": "modules/t/lib"
},
"RbxDom": {
"$path": "modules/rbx-dom/rbx_dom_lua/src"
}
}
}

1
plugin/modules/t Submodule

Submodule plugin/modules/t added at f643b50682

View File

@@ -13,16 +13,13 @@
"$path": "src"
},
"Roact": {
"$path": "modules/roact/lib"
},
"Rodux": {
"$path": "modules/rodux/lib"
},
"RoactRodux": {
"$path": "modules/roact-rodux/lib"
"$path": "modules/roact/src"
},
"Promise": {
"$path": "modules/promise/lib"
},
"t": {
"$path": "modules/t/lib"
}
},
"TestEZ": {
@@ -40,8 +37,8 @@
}
},
"TestService": {
"$className": "TestService",
"ServerScriptService": {
"$className": "ServerScriptService",
"TestBootstrap": {
"$path": "testBootstrap.server.lua"

View File

@@ -1,34 +0,0 @@
{
"name": "rojo",
"servePort": 8000,
"partitions": {
"plugin": {
"path": "src",
"target": "ReplicatedStorage.Rojo.Plugin"
},
"modules/roact": {
"path": "modules/roact/lib",
"target": "ReplicatedStorage.Rojo.Roact"
},
"modules/rodux": {
"path": "modules/rodux/lib",
"target": "ReplicatedStorage.Rojo.Rodux"
},
"modules/roact-rodux": {
"path": "modules/roact-rodux/lib",
"target": "ReplicatedStorage.Rojo.RoactRodux"
},
"modules/promise": {
"path": "modules/promise/lib",
"target": "ReplicatedStorage.Rojo.Promise"
},
"modules/testez": {
"path": "modules/testez/lib",
"target": "ReplicatedStorage.TestEZ"
},
"tests": {
"path": "testBootstrap.server.lua",
"target": "TestService.testBootstrap"
}
}
}

View File

@@ -1,9 +1,7 @@
local sheetAsset = "rbxassetid://2738712459"
local Assets = {
Sprites = {
WhiteCross = {
asset = sheetAsset,
asset = "rbxassetid://2738712459",
offset = Vector2.new(190, 318),
size = Vector2.new(18, 18),
},
@@ -17,7 +15,8 @@ local Assets = {
},
},
Images = {
Logo = "rbxassetid://2773210620",
Logo = "rbxassetid://3405346157",
Icon = "rbxassetid://3405341609",
},
StartSession = "",
SessionActive = "",

View File

@@ -1,13 +1,15 @@
local Roact = require(script:FindFirstAncestor("Rojo").Roact)
local Rojo = script:FindFirstAncestor("Rojo")
local Plugin = Rojo.Plugin
local Plugin = script:FindFirstAncestor("Plugin")
local Roact = require(Rojo.Roact)
local Assets = require(Plugin.Assets)
local Session = require(Plugin.Session)
local Config = require(Plugin.Config)
local Version = require(Plugin.Version)
local Logging = require(Plugin.Logging)
local DevSettings = require(Plugin.DevSettings)
local Logging = require(Plugin.Logging)
local Session = require(Plugin.Session)
local Version = require(Plugin.Version)
local preloadAssets = require(Plugin.preloadAssets)
local ConnectPanel = require(Plugin.Components.ConnectPanel)
local ConnectionActivePanel = require(Plugin.Components.ConnectionActivePanel)
@@ -53,8 +55,6 @@ end
local SessionStatus = {
Disconnected = "Disconnected",
Connected = "Connected",
ConfiguringSession = "ConfiguringSession",
-- TODO: Error?
}
setmetatable(SessionStatus, {
@@ -70,12 +70,41 @@ function App:init()
sessionStatus = SessionStatus.Disconnected,
})
self.connectButton = nil
self.signals = {}
self.currentSession = nil
self.displayedVersion = DevSettings:isEnabled()
and Config.codename
or Version.display(Config.version)
local toolbar = self.props.plugin:CreateToolbar("Rojo " .. self.displayedVersion)
self.toggleButton = toolbar:CreateButton(
"Rojo",
"Show or hide the Rojo panel",
Assets.Images.Icon)
self.toggleButton.ClickableWhenViewportHidden = true
self.toggleButton.Click:Connect(function()
self.dockWidget.Enabled = not self.dockWidget.Enabled
end)
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Right,
false, -- Initially enabled state
false, -- Whether to override the widget's previous state
360, 190, -- Floating size
360, 190 -- Minimum size
)
self.dockWidget = self.props.plugin:CreateDockWidgetPluginGui("Rojo-0.5.x", widgetInfo)
self.dockWidget.Name = "Rojo " .. self.displayedVersion
self.dockWidget.Title = "Rojo " .. self.displayedVersion
self.dockWidget.AutoLocalize = false
self.dockWidget.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
self.signals.dockWidgetEnabled = self.dockWidget:GetPropertyChangedSignal("Enabled"):Connect(function()
self.toggleButton:SetActive(self.dockWidget.Enabled)
end)
end
function App:render()
@@ -97,7 +126,7 @@ function App:render()
end,
}),
}
elseif self.state.sessionStatus == SessionStatus.ConfiguringSession then
elseif self.state.sessionStatus == SessionStatus.Disconnected then
children = {
ConnectPanel = e(ConnectPanel, {
startSession = function(address, port)
@@ -134,61 +163,26 @@ function App:render()
}
end
return e("ScreenGui", {
AutoLocalize = false,
ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
return Roact.createElement(Roact.Portal, {
target = self.dockWidget,
}, children)
end
function App:didMount()
Logging.trace("Rojo %s initializing", self.displayedVersion)
local toolbar = self.props.plugin:CreateToolbar("Rojo " .. self.displayedVersion)
self.connectButton = toolbar:CreateButton(
"Connect",
"Connect to a running Rojo session",
Assets.StartSession)
self.connectButton.ClickableWhenViewportHidden = false
self.connectButton.Click:Connect(function()
checkUpgrade(self.props.plugin)
if self.state.sessionStatus == SessionStatus.Connected then
Logging.trace("Disconnecting session")
self.currentSession:disconnect()
self.currentSession = nil
self:setState({
sessionStatus = SessionStatus.Disconnected,
})
Logging.trace("Session terminated by user")
elseif self.state.sessionStatus == SessionStatus.Disconnected then
Logging.trace("Starting session configuration")
self:setState({
sessionStatus = SessionStatus.ConfiguringSession,
})
elseif self.state.sessionStatus == SessionStatus.ConfiguringSession then
Logging.trace("Canceling session configuration")
self:setState({
sessionStatus = SessionStatus.Disconnected,
})
end
end)
checkUpgrade(self.props.plugin)
preloadAssets()
end
function App:didUpdate()
local connectActive = self.state.sessionStatus == SessionStatus.ConfiguringSession
or self.state.sessionStatus == SessionStatus.Connected
function App:willUnmount()
if self.currentSession ~= nil then
self.currentSession:disconnect()
self.currentSession = nil
end
self.connectButton:SetActive(connectActive)
if self.state.sessionStatus == SessionStatus.Connected then
self.connectButton.Icon = Assets.SessionActive
else
self.connectButton.Icon = Assets.StartSession
for _, signal in pairs(self.signals) do
signal:Disconnect()
end
end

View File

@@ -4,39 +4,19 @@ local Plugin = Rojo.Plugin
local Roact = require(Rojo.Roact)
local Config = require(Plugin.Config)
local Version = require(Plugin.Version)
local Assets = require(Plugin.Assets)
local Theme = require(Plugin.Theme)
local joinBindings = require(Plugin.joinBindings)
local Panel = require(Plugin.Components.Panel)
local FitList = require(Plugin.Components.FitList)
local FitText = require(Plugin.Components.FitText)
local FormButton = require(Plugin.Components.FormButton)
local FormTextInput = require(Plugin.Components.FormTextInput)
local RoundBox = Assets.Slices.RoundBox
local e = Roact.createElement
local ConnectPanel = Roact.Component:extend("ConnectPanel")
function ConnectPanel:init()
self.footerSize, self.setFooterSize = Roact.createBinding(Vector2.new())
self.footerVersionSize, self.setFooterVersionSize = Roact.createBinding(Vector2.new())
-- This is constructed in init because 'joinBindings' is a hack and we'd
-- leak memory constructing it every render. When this kind of feature lands
-- in Roact properly, we can do this inline in render without fear.
self.footerRestSize = joinBindings(
{
self.footerSize,
self.footerVersionSize,
},
function(container, other)
return UDim2.new(0, container.X - other.X - 16, 0, 32)
end
)
self:setState({
address = "",
port = "",
@@ -45,24 +25,14 @@ end
function ConnectPanel:render()
local startSession = self.props.startSession
local cancel = self.props.cancel
return e(FitList, {
containerKind = "ImageLabel",
containerProps = {
Image = RoundBox.asset,
ImageRectOffset = RoundBox.offset,
ImageRectSize = RoundBox.size,
SliceCenter = RoundBox.center,
ScaleType = Enum.ScaleType.Slice,
BackgroundTransparency = 1,
Position = UDim2.new(0.5, 0, 0.5, 0),
AnchorPoint = Vector2.new(0.5, 0.5),
},
layoutProps = {
return e(Panel, nil, {
Layout = e("UIListLayout", {
SortOrder = Enum.SortOrder.LayoutOrder,
HorizontalAlignment = Enum.HorizontalAlignment.Center,
},
}, {
VerticalAlignment = Enum.VerticalAlignment.Center,
}),
Inputs = e(FitList, {
containerProps = {
BackgroundTransparency = 1,
@@ -96,7 +66,7 @@ function ConnectPanel:render()
Font = Theme.TitleFont,
TextSize = 20,
Text = "Address",
TextColor3 = Theme.AccentColor,
TextColor3 = Theme.PrimaryColor,
}),
Input = e(FormTextInput, {
@@ -129,7 +99,7 @@ function ConnectPanel:render()
Font = Theme.TitleFont,
TextSize = 20,
Text = "Port",
TextColor3 = Theme.AccentColor,
TextColor3 = Theme.PrimaryColor,
}),
Input = e(FormTextInput, {
@@ -165,17 +135,6 @@ function ConnectPanel:render()
PaddingRight = UDim.new(0, 24),
},
}, {
e(FormButton, {
layoutOrder = 1,
text = "Cancel",
onClick = function()
if cancel ~= nil then
cancel()
end
end,
secondary = true,
}),
e(FormButton, {
layoutOrder = 2,
text = "Connect",
@@ -196,65 +155,6 @@ function ConnectPanel:render()
end,
}),
}),
Footer = e(FitList, {
fitAxes = "Y",
containerKind = "ImageLabel",
containerProps = {
Image = RoundBox.asset,
ImageRectOffset = RoundBox.offset + Vector2.new(0, RoundBox.size.Y / 2),
ImageRectSize = RoundBox.size * Vector2.new(1, 0.5),
SliceCenter = RoundBox.center,
ScaleType = Enum.ScaleType.Slice,
ImageColor3 = Theme.SecondaryColor,
Size = UDim2.new(1, 0, 0, 0),
LayoutOrder = 3,
BackgroundTransparency = 1,
[Roact.Change.AbsoluteSize] = function(rbx)
self.setFooterSize(rbx.AbsoluteSize)
end,
},
layoutProps = {
FillDirection = Enum.FillDirection.Horizontal,
HorizontalAlignment = Enum.HorizontalAlignment.Center,
VerticalAlignment = Enum.VerticalAlignment.Center,
},
paddingProps = {
PaddingTop = UDim.new(0, 4),
PaddingBottom = UDim.new(0, 4),
PaddingLeft = UDim.new(0, 8),
PaddingRight = UDim.new(0, 8),
},
}, {
LogoContainer = e("Frame", {
BackgroundTransparency = 1,
Size = self.footerRestSize,
}, {
Logo = e("ImageLabel", {
Image = Assets.Images.Logo,
Size = UDim2.new(0, 80, 0, 40),
ScaleType = Enum.ScaleType.Fit,
BackgroundTransparency = 1,
Position = UDim2.new(0, 0, 1, -10),
AnchorPoint = Vector2.new(0, 1),
}),
}),
Version = e(FitText, {
Font = Theme.TitleFont,
TextSize = 18,
Text = Version.display(Config.version),
TextXAlignment = Enum.TextXAlignment.Right,
TextColor3 = Theme.LightTextColor,
BackgroundTransparency = 1,
[Roact.Change.AbsoluteSize] = function(rbx)
self.setFooterVersionSize(rbx.AbsoluteSize)
end,
}),
}),
})
end

View File

@@ -3,63 +3,42 @@ local Roact = require(script:FindFirstAncestor("Rojo").Roact)
local Plugin = script:FindFirstAncestor("Plugin")
local Theme = require(Plugin.Theme)
local Assets = require(Plugin.Assets)
local FitList = require(Plugin.Components.FitList)
local Panel = require(Plugin.Components.Panel)
local FitText = require(Plugin.Components.FitText)
local FormButton = require(Plugin.Components.FormButton)
local e = Roact.createElement
local RoundBox = Assets.Slices.RoundBox
local WhiteCross = Assets.Sprites.WhiteCross
local ConnectionActivePanel = Roact.Component:extend("ConnectionActivePanel")
local function ConnectionActivePanel(props)
local stopSession = props.stopSession
function ConnectionActivePanel:render()
local stopSession = self.props.stopSession
return e(FitList, {
containerKind = "ImageLabel",
containerProps = {
Image = RoundBox.asset,
ImageRectOffset = RoundBox.offset + Vector2.new(0, RoundBox.size.Y / 2),
ImageRectSize = RoundBox.size * Vector2.new(1, 0.5),
SliceCenter = Rect.new(4, 4, 4, 4),
ScaleType = Enum.ScaleType.Slice,
BackgroundTransparency = 1,
Position = UDim2.new(0.5, 0, 0, 0),
AnchorPoint = Vector2.new(0.5, 0),
},
layoutProps = {
FillDirection = Enum.FillDirection.Horizontal,
return e(Panel, nil, {
Layout = Roact.createElement("UIListLayout", {
HorizontalAlignment = Enum.HorizontalAlignment.Center,
VerticalAlignment = Enum.VerticalAlignment.Center,
},
}, {
SortOrder = Enum.SortOrder.LayoutOrder,
Padding = UDim.new(0, 8),
}),
Text = e(FitText, {
Padding = Vector2.new(12, 6),
Font = Theme.ButtonFont,
TextSize = 18,
Text = "Rojo Connected",
Text = "Connected to Live-Sync Server",
TextColor3 = Theme.PrimaryColor,
BackgroundTransparency = 1,
}),
CloseContainer = e("ImageButton", {
Size = UDim2.new(0, 30, 0, 30),
BackgroundTransparency = 1,
[Roact.Event.Activated] = function()
DisconnectButton = e(FormButton, {
layoutOrder = 2,
text = "Disconnect",
secondary = true,
onClick = function()
stopSession()
end,
}, {
CloseImage = e("ImageLabel", {
Size = UDim2.new(0, 16, 0, 16),
Position = UDim2.new(0.5, 0, 0.5, 0),
AnchorPoint = Vector2.new(0.5, 0.5),
Image = WhiteCross.asset,
ImageRectOffset = WhiteCross.offset,
ImageRectSize = WhiteCross.size,
ImageColor3 = Theme.PrimaryColor,
BackgroundTransparency = 1,
}),
}),
})
end

View File

@@ -57,8 +57,8 @@ function FormTextInput:render()
TextSize = TEXT_SIZE,
Text = value,
PlaceholderText = shownPlaceholder,
PlaceholderColor3 = Theme.AccentLightColor,
TextColor3 = Theme.AccentColor,
PlaceholderColor3 = Theme.LightTextColor,
TextColor3 = Theme.PrimaryColor,
[Roact.Change.Text] = function(rbx)
onValueChange(rbx.Text)

View File

@@ -0,0 +1,34 @@
local Roact = require(script:FindFirstAncestor("Rojo").Roact)
local Plugin = script:FindFirstAncestor("Plugin")
local RojoFooter = require(Plugin.Components.RojoFooter)
local e = Roact.createElement
local Panel = Roact.Component:extend("Panel")
function Panel:init()
self.footerSize, self.setFooterSize = Roact.createBinding(Vector2.new())
end
function Panel:render()
return e("Frame", {
Size = UDim2.new(1, 0, 1, 0),
BackgroundTransparency = 1,
}, {
Layout = Roact.createElement("UIListLayout", {
HorizontalAlignment = Enum.HorizontalAlignment.Center,
SortOrder = Enum.SortOrder.LayoutOrder,
}),
Body = e("Frame", {
Size = UDim2.new(0, 360, 1, -32),
BackgroundTransparency = 1,
}, self.props[Roact.Children]),
Footer = e(RojoFooter),
})
end
return Panel

View File

@@ -0,0 +1,69 @@
local Rojo = script:FindFirstAncestor("Rojo")
local Plugin = Rojo.Plugin
local Roact = require(Rojo.Roact)
local Config = require(Plugin.Config)
local Version = require(Plugin.Version)
local Assets = require(Plugin.Assets)
local Theme = require(Plugin.Theme)
local FitText = require(Plugin.Components.FitText)
local e = Roact.createElement
local RojoFooter = Roact.Component:extend("RojoFooter")
function RojoFooter:init()
self.footerSize, self.setFooterSize = Roact.createBinding(Vector2.new())
self.footerVersionSize, self.setFooterVersionSize = Roact.createBinding(Vector2.new())
end
function RojoFooter:render()
return e("Frame", {
LayoutOrder = 3,
Size = UDim2.new(1, 0, 0, 32),
BackgroundColor3 = Theme.SecondaryColor,
BorderSizePixel = 0,
}, {
Padding = e("UIPadding", {
PaddingTop = UDim.new(0, 4),
PaddingBottom = UDim.new(0, 4),
PaddingLeft = UDim.new(0, 8),
PaddingRight = UDim.new(0, 8),
}),
LogoContainer = e("Frame", {
BackgroundTransparency = 1,
Size = UDim2.new(0, 0, 0, 32),
}, {
Logo = e("ImageLabel", {
Image = Assets.Images.Logo,
Size = UDim2.new(0, 80, 0, 40),
ScaleType = Enum.ScaleType.Fit,
BackgroundTransparency = 1,
Position = UDim2.new(0, 0, 1, -10),
AnchorPoint = Vector2.new(0, 1),
}),
}),
Version = e("TextLabel", {
Position = UDim2.new(1, 0, 0, 0),
Size = UDim2.new(0, 0, 1, 0),
AnchorPoint = Vector2.new(1, 0),
Font = Theme.TitleFont,
TextSize = 18,
Text = Version.display(Config.version),
TextXAlignment = Enum.TextXAlignment.Right,
TextColor3 = Theme.LightTextColor,
BackgroundTransparency = 1,
[Roact.Change.AbsoluteSize] = function(rbx)
self.setFooterVersionSize(rbx.AbsoluteSize)
end,
}),
})
end
return RojoFooter

View File

@@ -1,6 +1,6 @@
return {
codename = "Epiphany",
version = {0, 5, 0, "-alpha.4"},
version = {0, 5, 0, "-alpha.12"},
expectedServerVersionString = "0.5.0 or newer",
protocolVersion = 2,
defaultHost = "localhost",

View File

@@ -1,10 +1,27 @@
local Config = require(script.Parent.Config)
local Environment = {
User = "User",
Dev = "Dev",
Test = "Test",
}
local VALUES = {
LogLevel = {
type = "IntValue",
defaultUserValue = 2,
defaultDevValue = 3,
values = {
[Environment.User] = 2,
[Environment.Dev] = 3,
[Environment.Test] = 3,
},
},
TypecheckingEnabled = {
type = "BoolValue",
values = {
[Environment.User] = false,
[Environment.Dev] = true,
[Environment.Test] = true,
},
},
}
@@ -42,7 +59,9 @@ local function setStoredValue(name, kind, value)
object.Value = value
end
local function createAllValues()
local function createAllValues(environment)
assert(Environment[environment] ~= nil, "Invalid environment")
valueContainer = getValueContainer()
if valueContainer == nil then
@@ -52,20 +71,57 @@ local function createAllValues()
end
for name, value in pairs(VALUES) do
setStoredValue(name, value.type, value.defaultDevValue)
setStoredValue(name, value.type, value.values[environment])
end
end
_G[("ROJO_%s_DEV_CREATE"):format(Config.codename:upper())] = createAllValues
local function getValue(name)
assert(VALUES[name] ~= nil, "Invalid DevSettings name")
local stored = getStoredValue(name)
if stored ~= nil then
return stored
end
return VALUES[name].values[Environment.User]
end
local DevSettings = {}
function DevSettings:createDevSettings()
createAllValues(Environment.Dev)
end
function DevSettings:createTestSettings()
createAllValues(Environment.Test)
end
function DevSettings:hasChangedValues()
return valueContainer ~= nil
end
function DevSettings:resetValues()
if valueContainer then
valueContainer:Destroy()
valueContainer = nil
end
end
function DevSettings:isEnabled()
return valueContainer ~= nil
end
function DevSettings:getLogLevel()
return getStoredValue("LogLevel") or VALUES.LogLevel.defaultUserValue
return getValue("LogLevel")
end
function DevSettings:shouldTypecheck()
return getValue("TypecheckingEnabled")
end
function _G.ROJO_DEV_CREATE()
DevSettings:createDevSettings()
end
return DevSettings

View File

@@ -0,0 +1,81 @@
local Logging = require(script.Parent.Logging)
--[[
A bidirectional map between instance IDs and Roblox instances. It lets us
keep track of every instance we know about.
TODO: Track ancestry to catch when stuff moves?
]]
local InstanceMap = {}
InstanceMap.__index = InstanceMap
function InstanceMap.new()
local self = {
fromIds = {},
fromInstances = {},
}
return setmetatable(self, InstanceMap)
end
function InstanceMap:insert(id, instance)
self.fromIds[id] = instance
self.fromInstances[instance] = id
end
function InstanceMap:removeId(id)
local instance = self.fromIds[id]
if instance ~= nil then
self.fromIds[id] = nil
self.fromInstances[instance] = nil
else
Logging.warn("Attempted to remove nonexistant ID %s", tostring(id))
end
end
function InstanceMap:removeInstance(instance)
local id = self.fromInstances[instance]
if id ~= nil then
self.fromInstances[instance] = nil
self.fromIds[id] = nil
else
Logging.warn("Attempted to remove nonexistant instance %s", tostring(instance))
end
end
function InstanceMap:destroyInstance(instance)
local id = self.fromInstances[instance]
if id ~= nil then
self:destroyId(id)
else
Logging.warn("Attempted to destroy untracked instance %s", tostring(instance))
end
end
function InstanceMap:destroyId(id)
local instance = self.fromIds[id]
self:removeId(id)
if instance ~= nil then
local descendantsToDestroy = {}
for otherInstance in pairs(self.fromInstances) do
if otherInstance:IsDescendantOf(instance) then
table.insert(descendantsToDestroy, otherInstance)
end
end
for _, otherInstance in ipairs(descendantsToDestroy) do
self:removeInstance(otherInstance)
end
instance:Destroy()
else
Logging.warn("Attempted to destroy nonexistant ID %s", tostring(id))
end
end
return InstanceMap

View File

@@ -1,100 +1,15 @@
local t = require(script.Parent.Parent.t)
local InstanceMap = require(script.Parent.InstanceMap)
local Logging = require(script.Parent.Logging)
local setCanonicalProperty = require(script.Parent.setCanonicalProperty)
local rojoValueToRobloxValue = require(script.Parent.rojoValueToRobloxValue)
local Types = require(script.Parent.Types)
local function makeInstanceMap()
local self = {
fromIds = {},
fromInstances = {},
}
function self:insert(id, instance)
self.fromIds[id] = instance
self.fromInstances[instance] = id
end
function self:removeId(id)
local instance = self.fromIds[id]
if instance ~= nil then
self.fromIds[id] = nil
self.fromInstances[instance] = nil
else
Logging.warn("Attempted to remove nonexistant ID %s", tostring(id))
end
end
function self:removeInstance(instance)
local id = self.fromInstances[instance]
if id ~= nil then
self.fromInstances[instance] = nil
self.fromIds[id] = nil
else
Logging.warn("Attempted to remove nonexistant instance %s", tostring(instance))
end
end
function self:destroyId(id)
local instance = self.fromIds[id]
self:removeId(id)
if instance ~= nil then
local descendantsToDestroy = {}
for otherInstance in pairs(self.fromInstances) do
if otherInstance:IsDescendantOf(instance) then
table.insert(descendantsToDestroy, otherInstance)
end
end
for _, otherInstance in ipairs(descendantsToDestroy) do
self:removeInstance(otherInstance)
end
instance:Destroy()
else
Logging.warn("Attempted to destroy nonexistant ID %s", tostring(id))
end
end
return self
end
local function setProperty(instance, key, value)
-- The 'Contents' property of LocalizationTable isn't directly exposed, but
-- has corresponding (deprecated) getters and setters.
if key == "Contents" and instance.ClassName == "LocalizationTable" then
instance:SetContents(value)
return
end
-- If we don't have permissions to access this value at all, we can skip it.
local readSuccess, existingValue = pcall(function()
return instance[key]
local function setParent(instance, newParent)
pcall(function()
instance.Parent = newParent
end)
if not readSuccess then
-- An error will be thrown if there was a permission issue or if the
-- property doesn't exist. In the latter case, we should tell the user
-- because it's probably their fault.
if existingValue:find("lacking permission") then
Logging.trace("Permission error reading property %s on class %s", tostring(key), instance.ClassName)
return
else
error(("Invalid property %s on class %s: %s"):format(tostring(key), instance.ClassName, existingValue), 2)
end
end
local writeSuccess, err = pcall(function()
if existingValue ~= value then
instance[key] = value
end
end)
if not writeSuccess then
error(("Cannot set property %s on class %s: %s"):format(tostring(key), instance.ClassName, err), 2)
end
return true
end
local Reconciler = {}
@@ -102,7 +17,7 @@ Reconciler.__index = Reconciler
function Reconciler.new()
local self = {
instanceMap = makeInstanceMap(),
instanceMap = InstanceMap.new(),
}
return setmetatable(self, Reconciler)
@@ -118,11 +33,18 @@ function Reconciler:applyUpdate(requestedIds, virtualInstancesById)
end
end
local reconcileSchema = Types.ifEnabled(t.tuple(
t.map(t.string, Types.VirtualInstance),
t.string,
t.Instance
))
--[[
Update an existing instance, including its properties and children, to match
the given information.
]]
function Reconciler:reconcile(virtualInstancesById, id, instance)
assert(reconcileSchema(virtualInstancesById, id, instance))
local virtualInstance = virtualInstancesById[id]
-- If an instance changes ClassName, we assume it's very different. That's
@@ -137,10 +59,10 @@ function Reconciler:reconcile(virtualInstancesById, id, instance)
self.instanceMap:insert(id, instance)
-- Some instances don't like being named, even if their name already matches
setProperty(instance, "Name", virtualInstance.Name)
setCanonicalProperty(instance, "Name", virtualInstance.Name)
for key, value in pairs(virtualInstance.Properties) do
setProperty(instance, key, value.Value)
setCanonicalProperty(instance, key, rojoValueToRobloxValue(value))
end
local existingChildren = instance:GetChildren()
@@ -175,10 +97,17 @@ function Reconciler:reconcile(virtualInstancesById, id, instance)
end
end
if self:__shouldClearUnknownInstances(virtualInstance) then
for existingChildInstance in pairs(unvisitedExistingChildren) do
self.instanceMap:removeInstance(existingChildInstance)
existingChildInstance:Destroy()
local shouldClearUnknown = self:__shouldClearUnknownChildren(virtualInstance)
for existingChildInstance in pairs(unvisitedExistingChildren) do
local childId = self.instanceMap.fromInstances[existingChildInstance]
if childId == nil then
if shouldClearUnknown then
existingChildInstance:Destroy()
end
else
self.instanceMap:destroyInstance(existingChildInstance)
end
end
@@ -194,16 +123,13 @@ function Reconciler:reconcile(virtualInstancesById, id, instance)
-- Some instances, like services, don't like having their Parent
-- property poked, even if we're setting it to the same value.
setProperty(instance, "Parent", parent)
if instance.Parent ~= parent then
instance.Parent = parent
end
setParent(instance, parent)
end
return instance
end
function Reconciler:__shouldClearUnknownInstances(virtualInstance)
function Reconciler:__shouldClearUnknownChildren(virtualInstance)
if virtualInstance.Metadata ~= nil then
return not virtualInstance.Metadata.ignoreUnknownInstances
else
@@ -211,29 +137,44 @@ function Reconciler:__shouldClearUnknownInstances(virtualInstance)
end
end
local reifySchema = Types.ifEnabled(t.tuple(
t.map(t.string, Types.VirtualInstance),
t.string,
t.Instance
))
function Reconciler:__reify(virtualInstancesById, id, parent)
assert(reifySchema(virtualInstancesById, id, parent))
local virtualInstance = virtualInstancesById[id]
local instance = Instance.new(virtualInstance.ClassName)
for key, value in pairs(virtualInstance.Properties) do
-- TODO: Branch on value.Type
setProperty(instance, key, value.Value)
setCanonicalProperty(instance, key, rojoValueToRobloxValue(value))
end
instance.Name = virtualInstance.Name
setCanonicalProperty(instance, "Name", virtualInstance.Name)
for _, childId in ipairs(virtualInstance.Children) do
self:__reify(virtualInstancesById, childId, instance)
end
setProperty(instance, "Parent", parent)
setParent(instance, parent)
self.instanceMap:insert(id, instance)
return instance
end
local applyUpdatePieceSchema = Types.ifEnabled(t.tuple(
t.string,
t.map(t.string, t.boolean),
t.map(t.string, Types.VirtualInstance)
))
function Reconciler:__applyUpdatePiece(id, visitedIds, virtualInstancesById)
assert(applyUpdatePieceSchema(id, visitedIds, virtualInstancesById))
if visitedIds[id] then
return
end

View File

@@ -0,0 +1,218 @@
local Reconciler = require(script.Parent.Reconciler)
return function()
it("should leave instances alone if there's nothing specified", function()
local instance = Instance.new("Folder")
instance.Name = "TestFolder"
local instanceId = "test-id"
local virtualInstancesById = {
[instanceId] = {
Name = "TestFolder",
ClassName = "Folder",
Children = {},
Properties = {},
},
}
local reconciler = Reconciler.new()
reconciler:reconcile(virtualInstancesById, instanceId, instance)
end)
it("should assign names from virtual instances", function()
local instance = Instance.new("Folder")
instance.Name = "InitialName"
local instanceId = "test-id"
local virtualInstancesById = {
[instanceId] = {
Name = "NewName",
ClassName = "Folder",
Children = {},
Properties = {},
},
}
local reconciler = Reconciler.new()
reconciler:reconcile(virtualInstancesById, instanceId, instance)
expect(instance.Name).to.equal("NewName")
end)
it("should assign properties from virtual instances", function()
local instance = Instance.new("IntValue")
instance.Name = "TestValue"
instance.Value = 5
local instanceId = "test-id"
local virtualInstancesById = {
[instanceId] = {
Name = "TestValue",
ClassName = "IntValue",
Children = {},
Properties = {
Value = {
Type = "Int32",
Value = 9
}
},
},
}
local reconciler = Reconciler.new()
reconciler:reconcile(virtualInstancesById, instanceId, instance)
expect(instance.Value).to.equal(9)
end)
it("should wipe unknown children by default", function()
local parent = Instance.new("Folder")
parent.Name = "Parent"
local child = Instance.new("Folder")
child.Name = "Child"
local parentId = "test-id"
local virtualInstancesById = {
[parentId] = {
Name = "Parent",
ClassName = "Folder",
Children = {},
Properties = {},
},
}
local reconciler = Reconciler.new()
reconciler:reconcile(virtualInstancesById, parentId, parent)
expect(#parent:GetChildren()).to.equal(0)
end)
it("should preserve unknown children if ignoreUnknownInstances is set", function()
local parent = Instance.new("Folder")
parent.Name = "Parent"
local child = Instance.new("Folder")
child.Parent = parent
child.Name = "Child"
local parentId = "test-id"
local virtualInstancesById = {
[parentId] = {
Name = "Parent",
ClassName = "Folder",
Children = {},
Properties = {},
Metadata = {
ignoreUnknownInstances = true,
},
},
}
local reconciler = Reconciler.new()
reconciler:reconcile(virtualInstancesById, parentId, parent)
expect(child.Parent).to.equal(parent)
expect(#parent:GetChildren()).to.equal(1)
end)
it("should remove known removed children", function()
local parent = Instance.new("Folder")
parent.Name = "Parent"
local child = Instance.new("Folder")
child.Parent = parent
child.Name = "Child"
local parentId = "parent-id"
local childId = "child-id"
local reconciler = Reconciler.new()
local virtualInstancesById = {
[parentId] = {
Name = "Parent",
ClassName = "Folder",
Children = {childId},
Properties = {},
},
[childId] = {
Name = "Child",
ClassName = "Folder",
Children = {},
Properties = {},
},
}
reconciler:reconcile(virtualInstancesById, parentId, parent)
expect(child.Parent).to.equal(parent)
expect(#parent:GetChildren()).to.equal(1)
local newVirtualInstances = {
[parentId] = {
Name = "Parent",
ClassName = "Folder",
Children = {},
Properties = {},
},
[childId] = nil,
}
reconciler:reconcile(newVirtualInstances, parentId, parent)
expect(child.Parent).to.equal(nil)
expect(#parent:GetChildren()).to.equal(0)
end)
it("should remove known removed children if ignoreUnknownInstances is set", function()
local parent = Instance.new("Folder")
parent.Name = "Parent"
local child = Instance.new("Folder")
child.Parent = parent
child.Name = "Child"
local parentId = "parent-id"
local childId = "child-id"
local reconciler = Reconciler.new()
local virtualInstancesById = {
[parentId] = {
Name = "Parent",
ClassName = "Folder",
Children = {childId},
Properties = {},
Metadata = {
ignoreUnknownInstances = true,
},
},
[childId] = {
Name = "Child",
ClassName = "Folder",
Children = {},
Properties = {},
},
}
reconciler:reconcile(virtualInstancesById, parentId, parent)
expect(child.Parent).to.equal(parent)
expect(#parent:GetChildren()).to.equal(1)
local newVirtualInstances = {
[parentId] = {
Name = "Parent",
ClassName = "Folder",
Children = {},
Properties = {},
Metadata = {
ignoreUnknownInstances = true,
},
},
[childId] = nil,
}
reconciler:reconcile(newVirtualInstances, parentId, parent)
expect(child.Parent).to.equal(nil)
expect(#parent:GetChildren()).to.equal(0)
end)
end

View File

@@ -4,11 +4,11 @@ local Theme = {
TitleFont = Enum.Font.GothamBold,
MainFont = Enum.Font.Gotham,
AccentColor = Color3.fromRGB(136, 0, 27),
AccentLightColor = Color3.fromRGB(210, 145, 157),
PrimaryColor = Color3.fromRGB(20, 20, 20),
AccentColor = Color3.fromRGB(225, 56, 53),
AccentLightColor = Color3.fromRGB(255, 146, 145),
PrimaryColor = Color3.fromRGB(64, 64, 64),
SecondaryColor = Color3.fromRGB(235, 235, 235),
LightTextColor = Color3.fromRGB(140, 140, 140),
LightTextColor = Color3.fromRGB(160, 160, 160),
}
setmetatable(Theme, {

36
plugin/src/Types.lua Normal file
View File

@@ -0,0 +1,36 @@
local t = require(script.Parent.Parent.t)
local DevSettings = require(script.Parent.DevSettings)
local VirtualValue = t.interface({
Type = t.string,
Value = t.optional(t.any),
})
local VirtualMetadata = t.interface({
ignoreUnknownInstances = t.optional(t.boolean),
})
local VirtualInstance = t.interface({
Name = t.string,
ClassName = t.string,
Properties = t.map(t.string, VirtualValue),
Metadata = t.optional(VirtualMetadata)
})
local function ifEnabled(innerCheck)
return function(...)
if DevSettings:shouldTypecheck() then
return innerCheck(...)
else
return true
end
end
end
return {
ifEnabled = ifEnabled,
VirtualInstance = VirtualInstance,
VirtualMetadata = VirtualMetadata,
VirtualValue = VirtualValue,
}

View File

@@ -4,16 +4,14 @@ end
local Roact = require(script.Parent.Roact)
Roact.setGlobalConfig({
elementTracing = true,
})
local App = require(script.Components.App)
local app = Roact.createElement(App, {
plugin = plugin,
})
Roact.mount(app, game:GetService("CoreGui"), "Rojo UI")
local tree = Roact.mount(app, game:GetService("CoreGui"), "Rojo UI")
-- TODO: Detect another instance of Rojo coming online and shut down this one.
plugin.Unloading:Connect(function()
Roact.unmount(tree)
end)

View File

@@ -1,34 +0,0 @@
--[[
joinBindings is a crazy hack that allows combining multiple Roact bindings
in the same spirit as `map`.
It's implemented in terms of Roact internals that will probably break at
some point; please don't do that or use this module in your own code!
]]
local Binding = require(script:FindFirstAncestor("Rojo").Roact.Binding)
local function evaluate(fun, bindings)
local input = {}
for index, binding in ipairs(bindings) do
input[index] = binding:getValue()
end
return fun(unpack(input, 1, #bindings))
end
local function joinBindings(bindings, joinFunction)
local initialValue = evaluate(joinFunction, bindings)
local binding, setValue = Binding.create(initialValue)
for _, binding in ipairs(bindings) do
Binding.subscribe(binding, function()
setValue(evaluate(joinFunction, bindings))
end)
end
return binding
end
return joinBindings

View File

@@ -0,0 +1,28 @@
local ContentProvider = game:GetService("ContentProvider")
local Logging = require(script.Parent.Logging)
local Assets = require(script.Parent.Assets)
local function preloadAssets()
local contentUrls = {}
for _, sprite in pairs(Assets.Sprites) do
table.insert(contentUrls, sprite.asset)
end
for _, slice in pairs(Assets.Slices) do
table.insert(contentUrls, slice.asset)
end
for _, url in pairs(Assets.Images) do
table.insert(contentUrls, url)
end
Logging.trace("Preloading assets: %s", table.concat(contentUrls, ", "))
coroutine.wrap(function()
ContentProvider:PreloadAsync(contentUrls)
end)()
end
return preloadAssets

View File

@@ -0,0 +1,19 @@
local RbxDom = require(script:FindFirstAncestor("Rojo").RbxDom)
local function rojoValueToRobloxValue(value)
-- TODO: Manually decode this value by looking up its GUID The Rojo server
-- doesn't give us valid ref values yet, so this isn't important yet.
if value.Type == "Ref" then
return nil
end
local success, decodedValue = RbxDom.EncodedValue.decode(value)
if not success then
error(decodedValue, 2)
end
return decodedValue
end
return rojoValueToRobloxValue

View File

@@ -0,0 +1,40 @@
local rojoValueToRobloxValue = require(script.Parent.rojoValueToRobloxValue)
return function()
it("should convert primitives", function()
local inputString = {
Type = "String",
Value = "Hello, world!",
}
local inputFloat32 = {
Type = "Float32",
Value = 12341.512,
}
expect(rojoValueToRobloxValue(inputString)).to.equal(inputString.Value)
expect(rojoValueToRobloxValue(inputFloat32)).to.equal(inputFloat32.Value)
end)
it("should convert properties with direct constructors", function()
local inputColor3 = {
Type = "Color3",
Value = {0, 1, 0.5},
}
local outputColor3 = Color3.new(0, 1, 0.5)
local inputCFrame = {
Type = "CFrame",
Value = {
1, 2, 3,
4, 5, 6,
7, 8, 9,
10, 11, 12,
},
}
local outputCFrame = CFrame.new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
expect(rojoValueToRobloxValue(inputColor3)).to.equal(outputColor3)
expect(rojoValueToRobloxValue(inputCFrame)).to.equal(outputCFrame)
end)
end

View File

@@ -0,0 +1,37 @@
local RbxDom = require(script:FindFirstAncestor("Rojo").RbxDom)
--[[
Attempts to set a property on the given instance.
]]
local function setCanonicalProperty(instance, propertyName, value)
local descriptor = RbxDom.findCanonicalPropertyDescriptor(instance.ClassName, propertyName)
-- We can skip unknown properties; they're not likely reflected to Lua.
--
-- A good example of a property like this is `Model.ModelInPrimary`, which
-- is serialized but not reflected to Lua.
if descriptor == nil then
return false, "unknown property"
end
if descriptor.scriptability == "None" or descriptor.scriptability == "Read" then
return false, "unwritable property"
end
local success, err = descriptor:write(instance, value)
if not success then
-- If we don't have permission to write a property, we just silently
-- ignore it.
if err.kind == RbxDom.Error.Kind.Roblox and err.extra:find("lacking permission") then
return false, "permission error"
end
local message = ("Invalid property %s.%s: %s"):format(descriptor.className, descriptor.name, tostring(err))
error(message, 2)
end
return true
end
return setCanonicalProperty

View File

@@ -1,2 +1,19 @@
local TestEZ = require(game.ReplicatedStorage.TestEZ)
TestEZ.TestBootstrap:run(game.ReplicatedStorage.Rojo.plugin)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TestEZ = require(ReplicatedStorage.TestEZ)
local Rojo = ReplicatedStorage.Rojo
local DevSettings = require(Rojo.Plugin.DevSettings)
local setDevSettings = not DevSettings:hasChangedValues()
if setDevSettings then
DevSettings:createTestSettings()
end
TestEZ.TestBootstrap:run({Rojo.Plugin})
if setDevSettings then
DevSettings:resetValues()
end

View File

@@ -1,6 +0,0 @@
[package]
name = "rojo-e2e"
version = "0.1.0"
authors = ["Lucien Greathouse <me@lpghatguy.com>"]
[dependencies]

View File

@@ -1,2 +0,0 @@
# Rojo End-to-End
This is a WIP test runner designed for Rojo. It will eventually start up the Rojo server and plugin and test functionality end-to-end.

View File

@@ -1,32 +0,0 @@
use std::{
path::Path,
process::Command,
thread,
time::Duration,
};
fn main() {
let plugin_path = Path::new("../plugin");
let server_path = Path::new("../server");
let tests_path = Path::new("../tests");
let server = Command::new("cargo")
.args(&["run", "--", "serve", "../test-projects/empty"])
.current_dir(server_path)
.spawn();
thread::sleep(Duration::from_millis(1000));
// TODO: Wait for server to start responding on the right port
let test_client = Command::new("lua")
.args(&["runTest.lua", "tests/empty.lua"])
.current_dir(plugin_path)
.spawn();
thread::sleep(Duration::from_millis(300));
// TODO: Collect output from the client for success/failure?
println!("Dying!");
}

View File

@@ -1,12 +1,16 @@
[package]
name = "rojo"
version = "0.5.0-alpha.4"
version = "0.5.0-alpha.12"
authors = ["Lucien Greathouse <me@lpghatguy.com>"]
description = "A tool to create robust Roblox projects"
description = "Enables professional-grade development tools for Roblox developers"
license = "MIT"
repository = "https://github.com/LPGhatguy/rojo"
repository = "https://github.com/rojo-rbx/rojo"
edition = "2018"
[features]
default = []
server-plugins = []
[lib]
name = "librojo"
path = "src/lib.rs"
@@ -15,27 +19,25 @@ path = "src/lib.rs"
name = "rojo"
path = "src/bin.rs"
[features]
default = []
bundle-plugin = []
[dependencies]
clap = "2.27"
csv = "1.0"
env_logger = "0.6"
failure = "0.1.3"
futures = "0.1"
hyper = "0.12"
log = "0.4"
maplit = "1.0.1"
notify = "4.0"
rand = "0.4"
rbx_binary = "0.2.0"
rbx_tree = "0.2.0"
rbx_xml = "0.2.0"
rbx_binary = "0.4.1"
rbx_dom_weak = "1.8.0"
rbx_xml = "0.10.0"
rbx_reflection = "3.1.388"
regex = "1.0"
reqwest = "0.9.5"
rouille = "2.1"
serde = "1.0"
serde_derive = "1.0"
rlua = "0.16"
ritz = "0.1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
uuid = { version = "0.7", features = ["v4", "serde"] }
@@ -43,5 +45,5 @@ uuid = { version = "0.7", features = ["v4", "serde"] }
tempfile = "3.0"
walkdir = "2.1"
lazy_static = "1.2"
pretty_assertions = "0.5.1"
pretty_assertions = "0.6.1"
paste = "0.1"

43
server/assets/index.css Normal file
View File

@@ -0,0 +1,43 @@
* {
margin: 0;
padding: 0;
font: inherit;
}
html {
font-family: sans-serif;
height: 100%;
}
body {
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
}
.main {
padding: 1rem;
text-align: center;
margin: 0 auto;
width: 100%;
max-width: 60rem;
background-color: #efefef;
border: 1px solid #666;
border-radius: 4px;
}
.title {
font-size: 2rem;
font-weight: bold;
}
.subtitle {
font-size: 1.5rem;
font-weight: bold;
}
.docs {
font-size: 1.3rem;
font-weight: bold;
}

View File

@@ -1,54 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Rojo</title>
<style>
* {
margin: 0;
padding: 0;
font: inherit;
}
html {
font-family: sans-serif;
height: 100%;
}
body {
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
}
.main {
padding: 1rem;
text-align: center;
margin: 0 auto;
width: 100%;
max-width: 60rem;
background-color: #efefef;
border: 1px solid #666;
border-radius: 4px;
}
.title {
font-size: 2rem;
font-weight: bold;
}
.docs {
font-size: 1.5rem;
font-weight: bold;
}
</style>
</head>
<body>
<div class="main">
<h1 class="title">Rojo Live Sync is up and running!</h1>
<a class="docs" href="https://lpghatguy.github.io/rojo">Rojo Documentation</a>
</div>
</body>
</html>

View File

@@ -0,0 +1,66 @@
{
"name": "[placeholder]",
"tree": {
"$className": "DataModel",
"HttpService": {
"$className": "HttpService",
"$properties": {
"HttpEnabled": true
}
},
"Lighting": {
"$className": "Lighting",
"$properties": {
"Ambient": [
0,
0,
0
],
"Brightness": 2,
"GlobalShadows": true,
"Outlines": false,
"Technology": "Voxel"
}
},
"ReplicatedStorage": {
"$className": "ReplicatedStorage",
"Source": {
"$path": "src"
}
},
"SoundService": {
"$className": "SoundService",
"$properties": {
"RespectFilteringEnabled": true
}
},
"Workspace": {
"$className": "Workspace",
"$properties": {
"FilteringEnabled": true
},
"Baseplate": {
"$className": "Part",
"$properties": {
"Anchored": true,
"Color": [
0.38823,
0.37254,
0.38823
],
"Locked": true,
"Position": [
0,
-10,
0
],
"Size": [
512,
20,
512
]
}
}
}
}
}

View File

@@ -1,16 +1,17 @@
use std::{
path::PathBuf,
fs::File,
io,
io::{self, Write, BufWriter},
};
use log::info;
use failure::Fail;
use crate::{
rbx_session::construct_oneoff_tree,
project::{Project, ProjectLoadFuzzyError},
imfs::{Imfs, FsError},
project::{Project, ProjectLoadError},
rbx_session::construct_oneoff_tree,
rbx_snapshot::SnapshotError,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -46,7 +47,7 @@ pub enum BuildError {
UnknownOutputKind,
#[fail(display = "Project load error: {}", _0)]
ProjectLoadError(#[fail(cause)] ProjectLoadFuzzyError),
ProjectLoadError(#[fail(cause)] ProjectLoadError),
#[fail(display = "IO error: {}", _0)]
IoError(#[fail(cause)] io::Error),
@@ -59,16 +60,25 @@ pub enum BuildError {
#[fail(display = "{}", _0)]
FsError(#[fail(cause)] FsError),
#[fail(display = "{}", _0)]
SnapshotError(#[fail(cause)] SnapshotError),
}
impl_from!(BuildError {
ProjectLoadFuzzyError => ProjectLoadError,
ProjectLoadError => ProjectLoadError,
io::Error => IoError,
rbx_xml::EncodeError => XmlModelEncodeError,
rbx_binary::EncodeError => BinaryModelEncodeError,
FsError => FsError,
SnapshotError => SnapshotError,
});
fn xml_encode_config() -> rbx_xml::EncodeOptions {
rbx_xml::EncodeOptions::new()
.property_behavior(rbx_xml::EncodePropertyBehavior::WriteUnknown)
}
pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
let output_kind = options.output_kind
.or_else(|| detect_output_kind(options))
@@ -79,15 +89,14 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
info!("Looking for project at {}", options.fuzzy_project_path.display());
let project = Project::load_fuzzy(&options.fuzzy_project_path)?;
project.check_compatibility();
info!("Found project at {}", project.file_location.display());
info!("Using project {:#?}", project);
let mut imfs = Imfs::new();
imfs.add_roots_from_project(&project)?;
let tree = construct_oneoff_tree(&project, &imfs);
let mut file = File::create(&options.output_file)?;
let tree = construct_oneoff_tree(&project, &imfs)?;
let mut file = BufWriter::new(File::create(&options.output_file)?);
match output_kind {
OutputKind::Rbxmx => {
@@ -95,7 +104,7 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
// descendants.
let root_id = tree.get_root_id();
rbx_xml::encode(&tree, &[root_id], &mut file)?;
rbx_xml::to_writer(&mut file, &tree, &[root_id], xml_encode_config())?;
},
OutputKind::Rbxlx => {
// Place files don't contain an entry for the DataModel, but our
@@ -103,18 +112,24 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
let root_id = tree.get_root_id();
let top_level_ids = tree.get_instance(root_id).unwrap().get_children_ids();
rbx_xml::encode(&tree, top_level_ids, &mut file)?;
rbx_xml::to_writer(&mut file, &tree, top_level_ids, xml_encode_config())?;
},
OutputKind::Rbxm => {
let root_id = tree.get_root_id();
rbx_binary::encode(&tree, &[root_id], &mut file)?;
},
OutputKind::Rbxl => {
log::warn!("Support for building binary places (rbxl) is still experimental.");
log::warn!("Using the XML place format (rbxlx) is recommended instead.");
log::warn!("For more info, see https://github.com/LPGhatguy/rojo/issues/180");
let root_id = tree.get_root_id();
let top_level_ids = tree.get_instance(root_id).unwrap().get_children_ids();
rbx_binary::encode(&tree, top_level_ids, &mut file)?;
},
}
file.flush()?;
Ok(())
}

View File

@@ -7,10 +7,10 @@ use log::info;
use failure::Fail;
use crate::{
project::{Project, ProjectLoadFuzzyError},
web::Server,
project::{Project, ProjectLoadError},
web::LiveServer,
imfs::FsError,
live_session::LiveSession,
live_session::{LiveSession, LiveSessionError},
};
const DEFAULT_PORT: u16 = 34872;
@@ -24,28 +24,31 @@ pub struct ServeOptions {
#[derive(Debug, Fail)]
pub enum ServeError {
#[fail(display = "Project load error: {}", _0)]
ProjectLoadError(#[fail(cause)] ProjectLoadFuzzyError),
ProjectLoadError(#[fail(cause)] ProjectLoadError),
#[fail(display = "{}", _0)]
FsError(#[fail(cause)] FsError),
#[fail(display = "{}", _0)]
LiveSessionError(#[fail(cause)] LiveSessionError),
}
impl_from!(ServeError {
ProjectLoadFuzzyError => ProjectLoadError,
ProjectLoadError => ProjectLoadError,
FsError => FsError,
LiveSessionError => LiveSessionError,
});
pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
info!("Looking for project at {}", options.fuzzy_project_path.display());
let project = Arc::new(Project::load_fuzzy(&options.fuzzy_project_path)?);
project.check_compatibility();
info!("Found project at {}", project.file_location.display());
info!("Using project {:#?}", project);
let live_session = Arc::new(LiveSession::new(Arc::clone(&project))?);
let server = Server::new(Arc::clone(&live_session));
let server = LiveServer::new(live_session);
let port = options.port
.or(project.serve_port)
@@ -53,7 +56,7 @@ pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
println!("Rojo server listening on port {}", port);
server.listen(port);
server.start(port);
Ok(())
}

View File

@@ -9,9 +9,10 @@ use failure::Fail;
use reqwest::header::{ACCEPT, USER_AGENT, CONTENT_TYPE, COOKIE};
use crate::{
rbx_session::construct_oneoff_tree,
project::{Project, ProjectLoadFuzzyError},
imfs::{Imfs, FsError},
project::{Project, ProjectLoadError},
rbx_session::construct_oneoff_tree,
rbx_snapshot::SnapshotError,
};
#[derive(Debug, Fail)]
@@ -23,7 +24,7 @@ pub enum UploadError {
InvalidKind(String),
#[fail(display = "Project load error: {}", _0)]
ProjectLoadError(#[fail(cause)] ProjectLoadFuzzyError),
ProjectLoadError(#[fail(cause)] ProjectLoadError),
#[fail(display = "IO error: {}", _0)]
IoError(#[fail(cause)] io::Error),
@@ -36,14 +37,18 @@ pub enum UploadError {
#[fail(display = "{}", _0)]
FsError(#[fail(cause)] FsError),
#[fail(display = "{}", _0)]
SnapshotError(#[fail(cause)] SnapshotError),
}
impl_from!(UploadError {
ProjectLoadFuzzyError => ProjectLoadError,
ProjectLoadError => ProjectLoadError,
io::Error => IoError,
reqwest::Error => HttpError,
rbx_xml::EncodeError => XmlModelEncodeError,
FsError => FsError,
SnapshotError => SnapshotError,
});
#[derive(Debug)]
@@ -60,14 +65,13 @@ pub fn upload(options: &UploadOptions) -> Result<(), UploadError> {
info!("Looking for project at {}", options.fuzzy_project_path.display());
let project = Project::load_fuzzy(&options.fuzzy_project_path)?;
project.check_compatibility();
info!("Found project at {}", project.file_location.display());
info!("Using project {:#?}", project);
let mut imfs = Imfs::new();
imfs.add_roots_from_project(&project)?;
let tree = construct_oneoff_tree(&project, &imfs);
let tree = construct_oneoff_tree(&project, &imfs)?;
let root_id = tree.get_root_id();
let mut contents = Vec::new();
@@ -75,10 +79,10 @@ pub fn upload(options: &UploadOptions) -> Result<(), UploadError> {
match options.kind {
Some("place") | None => {
let top_level_ids = tree.get_instance(root_id).unwrap().get_children_ids();
rbx_xml::encode(&tree, top_level_ids, &mut contents)?;
rbx_xml::to_writer_default(&mut contents, &tree, top_level_ids)?;
},
Some("model") => {
rbx_xml::encode(&tree, &[root_id], &mut contents)?;
rbx_xml::to_writer_default(&mut contents, &tree, &[root_id])?;
},
Some(invalid) => return Err(UploadError::InvalidKind(invalid.to_owned())),
}

View File

@@ -1,13 +1,14 @@
use std::{
collections::{HashMap, HashSet},
path::{self, Path, PathBuf},
cmp::Ordering,
collections::{HashMap, HashSet, BTreeSet},
fmt,
fs,
io,
path::{self, Path, PathBuf},
};
use failure::Fail;
use serde_derive::{Serialize, Deserialize};
use serde::{Serialize, Deserialize};
use crate::project::{Project, ProjectNode};
@@ -88,11 +89,13 @@ impl Imfs {
pub fn add_root(&mut self, path: &Path) -> Result<(), FsError> {
debug_assert!(path.is_absolute());
debug_assert!(!self.is_within_roots(path));
self.roots.insert(path.to_path_buf());
if !self.is_within_roots(path) {
self.roots.insert(path.to_path_buf());
self.descend_and_read_from_disk(path)?;
}
self.descend_and_read_from_disk(path)
Ok(())
}
pub fn remove_root(&mut self, path: &Path) {
@@ -237,7 +240,7 @@ impl Imfs {
} else if metadata.is_dir() {
let item = ImfsItem::Directory(ImfsDirectory {
path: path.to_path_buf(),
children: HashSet::new(),
children: BTreeSet::new(),
});
self.items.insert(path.to_path_buf(), item);
@@ -285,19 +288,43 @@ impl Imfs {
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ImfsFile {
pub path: PathBuf,
pub contents: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ImfsDirectory {
pub path: PathBuf,
pub children: HashSet<PathBuf>,
impl PartialOrd for ImfsFile {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
impl Ord for ImfsFile {
fn cmp(&self, other: &Self) -> Ordering {
self.path.cmp(&other.path)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ImfsDirectory {
pub path: PathBuf,
pub children: BTreeSet<PathBuf>,
}
impl PartialOrd for ImfsDirectory {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for ImfsDirectory {
fn cmp(&self, other: &Self) -> Ordering {
self.path.cmp(&other.path)
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum ImfsItem {
File(ImfsFile),
Directory(ImfsDirectory),

View File

@@ -1,3 +1,5 @@
#![recursion_limit="128"]
// Macros
#[macro_use]
pub mod impl_from;
@@ -16,5 +18,4 @@ pub mod rbx_snapshot;
pub mod session_id;
pub mod snapshot_reconciler;
pub mod visualize;
pub mod web;
pub mod web_util;
pub mod web;

View File

@@ -1,21 +1,40 @@
use std::{
collections::HashSet,
mem,
sync::{Arc, Mutex},
};
use failure::Fail;
use crate::{
fs_watcher::FsWatcher,
imfs::{Imfs, FsError},
message_queue::MessageQueue,
project::Project,
rbx_session::RbxSession,
rbx_snapshot::SnapshotError,
session_id::SessionId,
snapshot_reconciler::InstanceChanges,
};
#[derive(Debug, Fail)]
pub enum LiveSessionError {
#[fail(display = "{}", _0)]
Fs(#[fail(cause)] FsError),
#[fail(display = "{}", _0)]
Snapshot(#[fail(cause)] SnapshotError),
}
impl_from!(LiveSessionError {
FsError => Fs,
SnapshotError => Snapshot,
});
/// Contains all of the state for a Rojo live-sync session.
pub struct LiveSession {
pub project: Arc<Project>,
pub session_id: SessionId,
project: Arc<Project>,
session_id: SessionId,
pub message_queue: Arc<MessageQueue<InstanceChanges>>,
pub rbx_session: Arc<Mutex<RbxSession>>,
pub imfs: Arc<Mutex<Imfs>>,
@@ -23,7 +42,7 @@ pub struct LiveSession {
}
impl LiveSession {
pub fn new(project: Arc<Project>) -> Result<LiveSession, FsError> {
pub fn new(project: Arc<Project>) -> Result<LiveSession, LiveSessionError> {
let imfs = {
let mut imfs = Imfs::new();
imfs.add_roots_from_project(&project)?;
@@ -36,7 +55,7 @@ impl LiveSession {
Arc::clone(&project),
Arc::clone(&imfs),
Arc::clone(&message_queue),
)));
)?));
let fs_watcher = FsWatcher::start(
Arc::clone(&imfs),
@@ -46,8 +65,8 @@ impl LiveSession {
let session_id = SessionId::new();
Ok(LiveSession {
project,
session_id,
project,
message_queue,
rbx_session,
imfs,
@@ -55,7 +74,26 @@ impl LiveSession {
})
}
pub fn get_project(&self) -> &Project {
/// Restarts the live session using the given project while preserving the
/// internal session ID.
pub fn restart_with_new_project(&mut self, project: Arc<Project>) -> Result<(), LiveSessionError> {
let mut new_session = LiveSession::new(project)?;
new_session.session_id = self.session_id;
mem::replace(self, new_session);
Ok(())
}
pub fn root_project(&self) -> &Project {
&self.project
}
pub fn session_id(&self) -> SessionId {
self.session_id
}
pub fn serve_place_ids(&self) -> &Option<HashSet<u64>> {
&self.project.serve_place_ids
}
}

View File

@@ -1,67 +1,83 @@
use std::{
collections::HashMap,
mem,
sync::{
mpsc,
atomic::{AtomicUsize, Ordering},
RwLock,
Mutex,
},
};
/// A unique identifier, not guaranteed to be generated in any order.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ListenerId(usize);
use futures::sync::oneshot;
/// Generate a new ID, which has no defined ordering.
pub fn get_listener_id() -> ListenerId {
static LAST_ID: AtomicUsize = AtomicUsize::new(0);
struct Listener<T> {
sender: oneshot::Sender<(u32, Vec<T>)>,
cursor: u32,
}
ListenerId(LAST_ID.fetch_add(1, Ordering::SeqCst))
fn fire_listener_if_ready<T: Clone>(messages: &[T], listener: Listener<T>) -> Result<(), Listener<T>> {
let current_cursor = messages.len() as u32;
if listener.cursor < current_cursor {
let new_messages = messages[(listener.cursor as usize)..].to_vec();
let _ = listener.sender.send((current_cursor, new_messages));
Ok(())
} else {
Err(listener)
}
}
/// A message queue with persistent history that can be subscribed to.
///
/// Definitely non-optimal, but a simple design that works well for the
/// synchronous web server Rojo uses, Rouille.
/// Definitely non-optimal. This would ideally be a lockless mpmc queue.
#[derive(Default)]
pub struct MessageQueue<T> {
messages: RwLock<Vec<T>>,
message_listeners: Mutex<HashMap<ListenerId, mpsc::Sender<()>>>,
message_listeners: Mutex<Vec<Listener<T>>>,
}
impl<T: Clone> MessageQueue<T> {
pub fn new() -> MessageQueue<T> {
MessageQueue {
messages: RwLock::new(Vec::new()),
message_listeners: Mutex::new(HashMap::new()),
message_listeners: Mutex::new(Vec::new()),
}
}
pub fn push_messages(&self, new_messages: &[T]) {
let message_listeners = self.message_listeners.lock().unwrap();
let mut message_listeners = self.message_listeners.lock().unwrap();
let mut messages = self.messages.write().unwrap();
messages.extend_from_slice(new_messages);
{
let mut messages = self.messages.write().unwrap();
messages.extend_from_slice(new_messages);
let mut remaining_listeners = Vec::new();
for listener in message_listeners.drain(..) {
match fire_listener_if_ready(&messages, listener) {
Ok(_) => {}
Err(listener) => remaining_listeners.push(listener)
}
}
for listener in message_listeners.values() {
listener.send(()).unwrap();
}
// Without this annotation, Rust gets confused since the first argument
// is a MutexGuard, but the second is a Vec.
mem::replace::<Vec<_>>(&mut message_listeners, remaining_listeners);
}
pub fn subscribe(&self, sender: mpsc::Sender<()>) -> ListenerId {
let id = get_listener_id();
pub fn subscribe(&self, cursor: u32, sender: oneshot::Sender<(u32, Vec<T>)>) {
let listener = {
let listener = Listener {
sender,
cursor,
};
let messages = self.messages.read().unwrap();
match fire_listener_if_ready(&messages, listener) {
Ok(_) => return,
Err(listener) => listener
}
};
let mut message_listeners = self.message_listeners.lock().unwrap();
message_listeners.insert(id, sender);
id
}
pub fn unsubscribe(&self, id: ListenerId) {
let mut message_listeners = self.message_listeners.lock().unwrap();
message_listeners.remove(&id);
message_listeners.push(listener);
}
pub fn get_message_cursor(&self) -> u32 {

View File

@@ -3,7 +3,7 @@ use std::{
collections::{HashMap, HashSet},
};
use serde_derive::Serialize;
use serde::Serialize;
use log::warn;
#[derive(Debug, Serialize)]
@@ -20,6 +20,12 @@ pub struct PathMap<T> {
nodes: HashMap<PathBuf, PathMapNode<T>>,
}
impl<T> Default for PathMap<T> {
fn default() -> Self {
Self::new()
}
}
impl<T> PathMap<T> {
pub fn new() -> PathMap<T> {
PathMap {

View File

@@ -10,7 +10,7 @@
//!
//! ```
//! # use std::path::PathBuf;
//! # use serde_derive::{Serialize, Deserialize};
//! # use serde::{Serialize, Deserialize};
//!
//! #[derive(Serialize, Deserialize)]
//! struct Mine {

View File

@@ -1,5 +1,5 @@
use std::{
collections::{HashMap, HashSet},
collections::{HashMap, HashSet, BTreeMap},
fmt,
fs::{self, File},
io,
@@ -8,9 +8,10 @@ use std::{
use log::warn;
use failure::Fail;
use maplit::hashmap;
use rbx_tree::RbxValue;
use serde_derive::{Serialize, Deserialize};
use rbx_dom_weak::{UnresolvedRbxValue, RbxValue};
use serde::{Serialize, Serializer, Deserialize};
static DEFAULT_PLACE: &'static str = include_str!("../assets/place.project.json");
pub static PROJECT_FILENAME: &'static str = "default.project.json";
pub static COMPAT_PROJECT_FILENAME: &'static str = "roblox-project.json";
@@ -19,11 +20,15 @@ pub static COMPAT_PROJECT_FILENAME: &'static str = "roblox-project.json";
/// want to do things like transforming paths to be absolute before handing them
/// off to the rest of Rojo, we use this intermediate struct.
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
struct SourceProject {
name: String,
tree: SourceProjectNode,
#[cfg_attr(not(feature = "plugins-enabled"), serde(skip_deserializing))]
#[serde(default = "Vec::new", skip_serializing_if = "Vec::is_empty")]
plugins: Vec<SourcePlugin>,
#[serde(skip_serializing_if = "Option::is_none")]
serve_port: Option<u16>,
@@ -33,12 +38,17 @@ struct SourceProject {
impl SourceProject {
/// Consumes the SourceProject and yields a Project, ready for prime-time.
pub fn into_project(self, project_file_location: &Path) -> Project {
pub fn into_project(mut self, project_file_location: &Path) -> Project {
let tree = self.tree.into_project_node(project_file_location);
let plugins = self.plugins
.drain(..)
.map(|source_plugin| source_plugin.into_plugin(project_file_location))
.collect();
Project {
name: self.name,
tree,
plugins,
serve_port: self.serve_port,
serve_place_ids: self.serve_place_ids,
file_location: PathBuf::from(project_file_location),
@@ -46,16 +56,88 @@ impl SourceProject {
}
}
/// An alternative serializer for `UnresolvedRbxValue` that uses the minimum
/// representation of the value.
///
/// For example, the default Serialize impl might give you:
///
/// ```json
/// {
/// "Type": "Bool",
/// "Value": true
/// }
/// ```
///
/// But in reality, users are expected to write just:
///
/// ```json
/// true
/// ```
///
/// This holds true for other values that might be ambiguous or just have more
/// complicated representations like enums.
fn serialize_unresolved_minimal<S>(unresolved: &UnresolvedRbxValue, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
match unresolved {
UnresolvedRbxValue::Ambiguous(_) => unresolved.serialize(serializer),
UnresolvedRbxValue::Concrete(concrete) => {
match concrete {
RbxValue::Bool { value } => value.serialize(serializer),
RbxValue::CFrame { value } => value.serialize(serializer),
RbxValue::Color3 { value } => value.serialize(serializer),
RbxValue::Color3uint8 { value } => value.serialize(serializer),
RbxValue::Content { value } => value.serialize(serializer),
RbxValue::Float32 { value } => value.serialize(serializer),
RbxValue::Int32 { value } => value.serialize(serializer),
RbxValue::String { value } => value.serialize(serializer),
RbxValue::UDim { value } => value.serialize(serializer),
RbxValue::UDim2 { value } => value.serialize(serializer),
RbxValue::Vector2 { value } => value.serialize(serializer),
RbxValue::Vector2int16 { value } => value.serialize(serializer),
RbxValue::Vector3 { value } => value.serialize(serializer),
RbxValue::Vector3int16 { value } => value.serialize(serializer),
_ => concrete.serialize(serializer),
}
},
}
}
/// A wrapper around serialize_unresolved_minimal that handles the HashMap case.
fn serialize_unresolved_map<S>(value: &HashMap<String, UnresolvedRbxValue>, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
use serde::ser::SerializeMap;
#[derive(Serialize)]
struct Minimal<'a>(
#[serde(serialize_with = "serialize_unresolved_minimal")]
&'a UnresolvedRbxValue
);
let mut map = serializer.serialize_map(Some(value.len()))?;
for (k, v) in value {
map.serialize_key(k)?;
map.serialize_value(&Minimal(v))?;
}
map.end()
}
/// Similar to SourceProject, the structure of nodes in the project tree is
/// slightly different on-disk than how we want to handle them in the rest of
/// Rojo.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
struct SourceProjectNode {
#[serde(rename = "$className", skip_serializing_if = "Option::is_none")]
class_name: Option<String>,
#[serde(rename = "$properties", default = "HashMap::new", skip_serializing_if = "HashMap::is_empty")]
properties: HashMap<String, RbxValue>,
#[serde(
rename = "$properties",
default = "HashMap::new",
skip_serializing_if = "HashMap::is_empty",
serialize_with = "serialize_unresolved_map",
)]
properties: HashMap<String, UnresolvedRbxValue>,
#[serde(rename = "$ignoreUnknownInstances", skip_serializing_if = "Option::is_none")]
ignore_unknown_instances: Option<bool>,
@@ -64,14 +146,14 @@ struct SourceProjectNode {
path: Option<String>,
#[serde(flatten)]
children: HashMap<String, SourceProjectNode>,
children: BTreeMap<String, SourceProjectNode>,
}
impl SourceProjectNode {
/// Consumes the SourceProjectNode and turns it into a ProjectNode.
pub fn into_project_node(mut self, project_file_location: &Path) -> ProjectNode {
let children = self.children.drain()
.map(|(key, value)| (key, value.into_project_node(project_file_location)))
pub fn into_project_node(self, project_file_location: &Path) -> ProjectNode {
let children = self.children.iter()
.map(|(key, value)| (key.clone(), value.clone().into_project_node(project_file_location)))
.collect();
// Make sure that paths are absolute, transforming them by adding the
@@ -95,34 +177,57 @@ impl SourceProjectNode {
}
}
/// Error returned by Project::load_exact
#[derive(Debug, Fail)]
pub enum ProjectLoadExactError {
#[fail(display = "IO error: {}", _0)]
IoError(#[fail(cause)] io::Error),
#[fail(display = "JSON error: {}", _0)]
JsonError(#[fail(cause)] serde_json::Error),
#[derive(Debug, Serialize, Deserialize)]
struct SourcePlugin {
path: String,
}
impl SourcePlugin {
pub fn into_plugin(self, project_file_location: &Path) -> Plugin {
let path = if Path::new(&self.path).is_absolute() {
PathBuf::from(self.path)
} else {
let project_folder_location = project_file_location.parent().unwrap();
project_folder_location.join(self.path)
};
Plugin {
path,
}
}
}
/// Error returned by Project::load_fuzzy
#[derive(Debug, Fail)]
pub enum ProjectLoadFuzzyError {
#[fail(display = "Project not found")]
pub enum ProjectLoadError {
NotFound,
#[fail(display = "IO error: {}", _0)]
IoError(#[fail(cause)] io::Error),
Io {
#[fail(cause)]
inner: io::Error,
path: PathBuf,
},
#[fail(display = "JSON error: {}", _0)]
JsonError(#[fail(cause)] serde_json::Error),
Json {
#[fail(cause)]
inner: serde_json::Error,
path: PathBuf,
},
}
impl From<ProjectLoadExactError> for ProjectLoadFuzzyError {
fn from(error: ProjectLoadExactError) -> ProjectLoadFuzzyError {
match error {
ProjectLoadExactError::IoError(inner) => ProjectLoadFuzzyError::IoError(inner),
ProjectLoadExactError::JsonError(inner) => ProjectLoadFuzzyError::JsonError(inner),
impl fmt::Display for ProjectLoadError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use self::ProjectLoadError::*;
match self {
NotFound => {
write!(formatter, "Project file not found")
}
Io { inner, path } => {
write!(formatter, "I/O error: {} in path {}", inner, path.display())
}
Json { inner, path } => {
write!(formatter, "JSON error: {} in path {}", inner, path.display())
}
}
}
}
@@ -133,6 +238,7 @@ pub enum ProjectInitError {
AlreadyExists(PathBuf),
IoError(#[fail(cause)] io::Error),
SaveError(#[fail(cause)] ProjectSaveError),
JsonError(#[fail(cause)] serde_json::Error),
}
impl fmt::Display for ProjectInitError {
@@ -141,6 +247,7 @@ impl fmt::Display for ProjectInitError {
ProjectInitError::AlreadyExists(path) => write!(output, "Path {} already exists", path.display()),
ProjectInitError::IoError(inner) => write!(output, "IO error: {}", inner),
ProjectInitError::SaveError(inner) => write!(output, "{}", inner),
ProjectInitError::JsonError(inner) => write!(output, "{}", inner),
}
}
}
@@ -158,8 +265,8 @@ pub enum ProjectSaveError {
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct ProjectNode {
pub class_name: Option<String>,
pub children: HashMap<String, ProjectNode>,
pub properties: HashMap<String, RbxValue>,
pub children: BTreeMap<String, ProjectNode>,
pub properties: HashMap<String, UnresolvedRbxValue>,
pub ignore_unknown_instances: Option<bool>,
#[serde(serialize_with = "crate::path_serializer::serialize_option")]
@@ -167,6 +274,17 @@ pub struct ProjectNode {
}
impl ProjectNode {
fn validate_reserved_names(&self) {
for (name, child) in &self.children {
if name.starts_with('$') {
warn!("Keys starting with '$' are reserved by Rojo to ensure forward compatibility.");
warn!("This project uses the key '{}', which should be renamed.", name);
}
child.validate_reserved_names();
}
}
fn to_source_node(&self, project_file_location: &Path) -> SourceProjectNode {
let children = self.children.iter()
.map(|(key, value)| (key.clone(), value.to_source_node(project_file_location)))
@@ -198,10 +316,30 @@ impl ProjectNode {
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Plugin {
pub path: PathBuf,
}
impl Plugin {
fn to_source_plugin(&self, project_file_location: &Path) -> SourcePlugin {
let project_folder_location = project_file_location.parent().unwrap();
let path = match self.path.strip_prefix(project_folder_location) {
Ok(stripped) => stripped.to_str().unwrap().replace("\\", "/"),
Err(_) => format!("{}", self.path.display()),
};
SourcePlugin {
path,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Project {
pub name: String,
pub tree: ProjectNode,
pub plugins: Vec<Plugin>,
pub serve_port: Option<u16>,
pub serve_place_ids: Option<HashSet<u64>>,
pub file_location: PathBuf,
@@ -209,47 +347,23 @@ pub struct Project {
impl Project {
pub fn init_place(project_fuzzy_path: &Path) -> Result<PathBuf, ProjectInitError> {
let project_path = Project::init_pick_path(project_fuzzy_path)?;
let project_folder_path = project_path.parent().unwrap();
let project_path = Project::pick_path_for_init(project_fuzzy_path)?;
let project_name = if project_fuzzy_path == project_path {
project_fuzzy_path.parent().unwrap().file_name().unwrap().to_str().unwrap()
project_fuzzy_path
.parent().expect("Path did not have a parent directory")
.file_name().expect("Path did not have a file name")
.to_str().expect("Path had invalid Unicode")
} else {
project_fuzzy_path.file_name().unwrap().to_str().unwrap()
project_fuzzy_path
.file_name().expect("Path did not have a file name")
.to_str().expect("Path had invalid Unicode")
};
let tree = ProjectNode {
class_name: Some(String::from("DataModel")),
children: hashmap! {
String::from("ReplicatedStorage") => ProjectNode {
class_name: Some(String::from("ReplicatedStorage")),
children: hashmap! {
String::from("Source") => ProjectNode {
path: Some(project_folder_path.join("src")),
..Default::default()
},
},
..Default::default()
},
String::from("HttpService") => ProjectNode {
class_name: Some(String::from("HttpService")),
properties: hashmap! {
String::from("HttpEnabled") => RbxValue::Bool {
value: true,
},
},
..Default::default()
},
},
..Default::default()
};
let mut project = Project::load_from_str(DEFAULT_PLACE, &project_path)
.map_err(ProjectInitError::JsonError)?;
let project = Project {
name: project_name.to_string(),
tree,
serve_port: None,
serve_place_ids: None,
file_location: project_path.clone(),
};
project.name = project_name.to_owned();
project.save()
.map_err(ProjectInitError::SaveError)?;
@@ -258,14 +372,22 @@ impl Project {
}
pub fn init_model(project_fuzzy_path: &Path) -> Result<PathBuf, ProjectInitError> {
let project_path = Project::init_pick_path(project_fuzzy_path)?;
let project_folder_path = project_path.parent().unwrap();
let project_path = Project::pick_path_for_init(project_fuzzy_path)?;
let project_name = if project_fuzzy_path == project_path {
project_fuzzy_path.parent().unwrap().file_name().unwrap().to_str().unwrap()
project_fuzzy_path
.parent().expect("Path did not have a parent directory")
.file_name().expect("Path did not have a file name")
.to_str().expect("Path had invalid Unicode")
} else {
project_fuzzy_path.file_name().unwrap().to_str().unwrap()
project_fuzzy_path
.file_name().expect("Path did not have a file name")
.to_str().expect("Path had invalid Unicode")
};
let project_folder_path = project_path
.parent().expect("Path did not have a parent directory");
let tree = ProjectNode {
path: Some(project_folder_path.join("src")),
..Default::default()
@@ -274,6 +396,7 @@ impl Project {
let project = Project {
name: project_name.to_string(),
tree,
plugins: Vec::new(),
serve_port: None,
serve_place_ids: None,
file_location: project_path.clone(),
@@ -285,7 +408,7 @@ impl Project {
Ok(project_path)
}
fn init_pick_path(project_fuzzy_path: &Path) -> Result<PathBuf, ProjectInitError> {
fn pick_path_for_init(project_fuzzy_path: &Path) -> Result<PathBuf, ProjectInitError> {
let is_exact = project_fuzzy_path.extension().is_some();
let project_path = if is_exact {
@@ -305,7 +428,7 @@ impl Project {
Ok(project_path)
}
pub fn locate(start_location: &Path) -> Option<PathBuf> {
fn locate(start_location: &Path) -> Option<PathBuf> {
// TODO: Check for specific error kinds, convert 'not found' to Result.
let location_metadata = fs::metadata(start_location).ok()?;
@@ -336,23 +459,43 @@ impl Project {
}
}
pub fn load_fuzzy(fuzzy_project_location: &Path) -> Result<Project, ProjectLoadFuzzyError> {
let project_path = Self::locate(fuzzy_project_location)
.ok_or(ProjectLoadFuzzyError::NotFound)?;
Self::load_exact(&project_path).map_err(From::from)
}
pub fn load_exact(project_file_location: &Path) -> Result<Project, ProjectLoadExactError> {
let contents = fs::read_to_string(project_file_location)
.map_err(ProjectLoadExactError::IoError)?;
let parsed: SourceProject = serde_json::from_str(&contents)
.map_err(ProjectLoadExactError::JsonError)?;
fn load_from_str(contents: &str, project_file_location: &Path) -> Result<Project, serde_json::Error> {
let parsed: SourceProject = serde_json::from_str(&contents)?;
Ok(parsed.into_project(project_file_location))
}
pub fn load_fuzzy(fuzzy_project_location: &Path) -> Result<Project, ProjectLoadError> {
if let Some(project_path) = Self::locate(fuzzy_project_location) {
Self::load_exact(&project_path)
} else {
Project::warn_if_4x_project_present(fuzzy_project_location);
Err(ProjectLoadError::NotFound)
}
}
pub fn load_exact(project_file_location: &Path) -> Result<Project, ProjectLoadError> {
let contents = fs::read_to_string(project_file_location)
.map_err(|error| match error.kind() {
io::ErrorKind::NotFound => ProjectLoadError::NotFound,
_ => ProjectLoadError::Io {
inner: error,
path: project_file_location.to_path_buf(),
}
})?;
let parsed: SourceProject = serde_json::from_str(&contents)
.map_err(|error| ProjectLoadError::Json {
inner: error,
path: project_file_location.to_path_buf(),
})?;
let project = parsed.into_project(project_file_location);
project.check_compatibility();
Ok(project)
}
pub fn save(&self) -> Result<(), ProjectSaveError> {
let source_project = self.to_source_project();
let mut file = File::create(&self.file_location)
@@ -366,10 +509,10 @@ impl Project {
/// Checks if there are any compatibility issues with this project file and
/// warns the user if there are any.
pub fn check_compatibility(&self) {
fn check_compatibility(&self) {
let file_name = self.file_location
.file_name().unwrap()
.to_str().expect("Project file path was not valid Unicode!");
.file_name().expect("Project file path did not have a file name")
.to_str().expect("Project file path was not valid Unicode");
if file_name == COMPAT_PROJECT_FILENAME {
warn!("Rojo's default project file name changed in 0.5.0-alpha3.");
@@ -381,12 +524,39 @@ impl Project {
warn!(".project.json extension. This helps Rojo differentiate project files from");
warn!("other JSON files!");
}
self.tree.validate_reserved_names();
}
/// Issues a warning if no Rojo 0.5.x project is found, but there's a legacy
/// 0.4.x project in the directory.
fn warn_if_4x_project_present(folder: &Path) {
let file_path = folder.join("rojo.json");
if fs::metadata(file_path).is_ok() {
warn!("No Rojo 0.5 project file was found, but a Rojo 0.4 project was.");
warn!("Rojo 0.5.x uses 'default.project.json' files");
warn!("Rojo 0.5.x uses 'rojo.json' files");
warn!("");
warn!("For help upgrading, see:");
warn!("https://lpghatguy.github.io/rojo/guide/migrating-to-epiphany/");
}
}
pub fn folder_location(&self) -> &Path {
self.file_location.parent().unwrap()
}
fn to_source_project(&self) -> SourceProject {
let plugins = self.plugins
.iter()
.map(|plugin| plugin.to_source_plugin(&self.file_location))
.collect();
SourceProject {
name: self.name.clone(),
tree: self.tree.to_source_node(&self.file_location),
plugins,
serve_port: self.serve_port,
serve_place_ids: self.serve_place_ids.clone(),
}

View File

@@ -6,16 +6,25 @@ use std::{
sync::{Arc, Mutex},
};
use serde_derive::{Serialize, Deserialize};
use log::{info, trace};
use rbx_tree::{RbxTree, RbxId};
use rlua::Lua;
use serde::{Serialize, Deserialize};
use log::{info, trace, error};
use rbx_dom_weak::{RbxTree, RbxId};
use crate::{
project::{Project, ProjectNode},
message_queue::MessageQueue,
imfs::{Imfs, ImfsItem},
path_map::PathMap,
rbx_snapshot::{snapshot_project_tree, snapshot_project_node, snapshot_imfs_path},
rbx_snapshot::{
SnapshotError,
SnapshotContext,
SnapshotPluginContext,
SnapshotPluginEntry,
snapshot_project_tree,
snapshot_project_node,
snapshot_imfs_path,
},
snapshot_reconciler::{InstanceChanges, reify_root, reconcile_subtree},
};
@@ -58,22 +67,60 @@ impl RbxSession {
project: Arc<Project>,
imfs: Arc<Mutex<Imfs>>,
message_queue: Arc<MessageQueue<InstanceChanges>>,
) -> RbxSession {
) -> Result<RbxSession, SnapshotError> {
let mut instances_per_path = PathMap::new();
let mut metadata_per_instance = HashMap::new();
let tree = {
let temp_imfs = imfs.lock().unwrap();
reify_initial_tree(&project, &temp_imfs, &mut instances_per_path, &mut metadata_per_instance)
let plugin_context = if cfg!(feature = "server-plugins") {
let lua = Lua::new();
let mut callback_key = None;
lua.context(|context| {
let callback = context.load(r#"
return function(snapshot)
print("got my snapshot:", snapshot)
print("name:", snapshot.name, "class name:", snapshot.className)
end"#)
.set_name("a cool plugin").unwrap()
.call::<(), rlua::Function>(()).unwrap();
callback_key = Some(context.create_registry_value(callback).unwrap());
});
let plugins = vec![
SnapshotPluginEntry {
file_name_filter: String::new(),
callback: callback_key.unwrap(),
}
];
Some(SnapshotPluginContext { lua, plugins })
} else {
None
};
RbxSession {
let context = SnapshotContext {
plugin_context,
};
let tree = {
let temp_imfs = imfs.lock().unwrap();
reify_initial_tree(
&project,
&context,
&temp_imfs,
&mut instances_per_path,
&mut metadata_per_instance,
)?
};
Ok(RbxSession {
tree,
instances_per_path,
metadata_per_instance,
message_queue,
imfs,
}
})
}
fn path_created_or_updated(&mut self, path: &Path) {
@@ -104,27 +151,37 @@ impl RbxSession {
.expect("Metadata did not exist for path")
.clone();
let context = SnapshotContext {
plugin_context: None,
};
for instance_id in &instances_at_path {
let instance_metadata = self.metadata_per_instance.get(&instance_id)
.expect("Metadata for instance ID did not exist");
let maybe_snapshot = match &instance_metadata.project_definition {
Some((instance_name, project_node)) => {
snapshot_project_node(&imfs, &project_node, Cow::Owned(instance_name.clone()))
.unwrap_or_else(|_| panic!("Could not generate instance snapshot for path {}", path_to_snapshot.display()))
snapshot_project_node(&context, &imfs, &project_node, Cow::Owned(instance_name.clone()))
// .unwrap_or_else(|_| panic!("Could not generate instance snapshot for path {}", path_to_snapshot.display()))
},
None => {
snapshot_imfs_path(&imfs, &path_to_snapshot, None)
.unwrap_or_else(|_| panic!("Could not generate instance snapshot for path {}", path_to_snapshot.display()))
snapshot_imfs_path(&context, &imfs, &path_to_snapshot, None)
// .unwrap_or_else(|_| panic!("Could not generate instance snapshot for path {}", path_to_snapshot.display()))
},
};
let snapshot = match maybe_snapshot {
Some(snapshot) => snapshot,
None => {
Ok(Some(snapshot)) => snapshot,
Ok(None) => {
trace!("Path resulted in no snapshot being generated.");
return;
},
Err(err) => {
error!("Rojo couldn't turn one of the project's files into Roblox instances.");
error!("Any changes to the file have been ignored.");
error!("{}", err);
return;
},
};
trace!("Snapshot: {:#?}", snapshot);
@@ -194,29 +251,39 @@ impl RbxSession {
&self.tree
}
pub fn get_all_instance_metadata(&self) -> &HashMap<RbxId, MetadataPerInstance> {
&self.metadata_per_instance
}
pub fn get_instance_metadata(&self, id: RbxId) -> Option<&MetadataPerInstance> {
self.metadata_per_instance.get(&id)
}
}
pub fn construct_oneoff_tree(project: &Project, imfs: &Imfs) -> RbxTree {
pub fn construct_oneoff_tree(project: &Project, imfs: &Imfs) -> Result<RbxTree, SnapshotError> {
let mut instances_per_path = PathMap::new();
let mut metadata_per_instance = HashMap::new();
reify_initial_tree(project, imfs, &mut instances_per_path, &mut metadata_per_instance)
let context = SnapshotContext {
plugin_context: None,
};
reify_initial_tree(project, &context, imfs, &mut instances_per_path, &mut metadata_per_instance)
}
fn reify_initial_tree(
project: &Project,
context: &SnapshotContext,
imfs: &Imfs,
instances_per_path: &mut PathMap<HashSet<RbxId>>,
metadata_per_instance: &mut HashMap<RbxId, MetadataPerInstance>,
) -> RbxTree {
let snapshot = snapshot_project_tree(imfs, project)
.expect("Could not snapshot project tree")
.expect("Project did not produce any instances");
) -> Result<RbxTree, SnapshotError> {
let snapshot = match snapshot_project_tree(&context, imfs, project)? {
Some(snapshot) => snapshot,
None => panic!("Project did not produce any instances"),
};
let mut changes = InstanceChanges::default();
let tree = reify_root(&snapshot, instances_per_path, metadata_per_instance, &mut changes);
tree
Ok(tree)
}

View File

@@ -9,11 +9,13 @@ use std::{
str,
};
use rlua::Lua;
use failure::Fail;
use log::info;
use maplit::hashmap;
use rbx_tree::{RbxTree, RbxValue, RbxInstanceProperties};
use serde_derive::{Serialize, Deserialize};
use rbx_dom_weak::{RbxTree, RbxValue, RbxInstanceProperties, UnresolvedRbxValue};
use serde::{Serialize, Deserialize};
use rbx_reflection::{try_resolve_value, ValueResolveError};
use crate::{
imfs::{
@@ -38,6 +40,53 @@ const INIT_MODULE_NAME: &str = "init.lua";
const INIT_SERVER_NAME: &str = "init.server.lua";
const INIT_CLIENT_NAME: &str = "init.client.lua";
pub struct SnapshotContext {
pub plugin_context: Option<SnapshotPluginContext>,
}
/// Context that's only relevant to generating snapshots if there are plugins
/// associated with the project.
///
/// It's possible that this needs some sort of extra nesting/filtering to
/// support nested projects, since their plugins should only apply to
/// themselves.
pub struct SnapshotPluginContext {
pub lua: Lua,
pub plugins: Vec<SnapshotPluginEntry>,
}
pub struct SnapshotPluginEntry {
/// Simple file name suffix filter to avoid running plugins on every file
/// change.
pub file_name_filter: String,
/// A key into the Lua registry created by [`create_registry_value`] that
/// refers to a function that can be called to transform a file/instance
/// pair according to how the plugin needs to operate.
///
/// [`create_registry_value`]: https://docs.rs/rlua/0.16.2/rlua/struct.Context.html#method.create_registry_value
pub callback: rlua::RegistryKey,
}
#[derive(Debug, Clone)]
struct LuaRbxSnapshot(RbxSnapshotInstance<'static>);
impl rlua::UserData for LuaRbxSnapshot {
fn add_methods<'lua, M: rlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_meta_method(rlua::MetaMethod::Index, |_context, this, key: String| {
match key.as_str() {
"name" => Ok(this.0.name.clone().into_owned()),
"className" => Ok(this.0.class_name.clone().into_owned()),
_ => Err(rlua::Error::RuntimeError(format!("{} is not a valid member of RbxSnapshotInstance", &key))),
}
});
methods.add_meta_method(rlua::MetaMethod::ToString, |_context, _this, _args: ()| {
Ok("RbxSnapshotInstance")
});
}
}
pub type SnapshotResult<'a> = Result<Option<RbxSnapshotInstance<'a>>, SnapshotError>;
#[derive(Debug, Fail)]
@@ -56,7 +105,23 @@ pub enum SnapshotError {
path: PathBuf,
},
ExtraMetadataError {
#[fail(cause)]
inner: serde_json::Error,
path: PathBuf,
},
InvalidMetadataModelField {
field_name: String,
path: PathBuf,
},
MetadataClassNameNonInit {
path: PathBuf,
},
XmlModelDecodeError {
#[fail(cause)]
inner: rbx_xml::DecodeError,
path: PathBuf,
},
@@ -66,11 +131,30 @@ pub enum SnapshotError {
path: PathBuf,
},
CsvDecodeError {
#[fail(cause)]
inner: csv::Error,
path: PathBuf,
},
ProjectNodeUnusable,
ProjectNodeInvalidTransmute {
partition_path: PathBuf,
},
PropertyResolveError {
#[fail(cause)]
inner: ValueResolveError,
},
}
impl From<ValueResolveError> for SnapshotError {
fn from(inner: ValueResolveError) -> SnapshotError {
SnapshotError::PropertyResolveError {
inner,
}
}
}
impl fmt::Display for SnapshotError {
@@ -83,12 +167,26 @@ impl fmt::Display for SnapshotError {
SnapshotError::JsonModelDecodeError { inner, path } => {
write!(output, "Malformed .model.json model: {} in path {}", inner, path.display())
},
SnapshotError::ExtraMetadataError { inner, path } => {
write!(output, "Malformed init.meta.json: {} in path {}", inner, path.display())
},
SnapshotError::InvalidMetadataModelField { field_name, path } => {
writeln!(output, "The field '{}' cannot be specified on .meta.json files attached to models.", field_name)?;
writeln!(output, "Model path: {}", path.display())
},
SnapshotError::MetadataClassNameNonInit { path } => {
writeln!(output, "The field 'className' cannot be specified on .meta.json files besides init.meta.json")?;
writeln!(output, "Model path: {}", path.display())
},
SnapshotError::XmlModelDecodeError { inner, path } => {
write!(output, "Malformed rbxmx model: {:?} in path {}", inner, path.display())
write!(output, "Malformed rbxmx model: {} in path {}", inner, path.display())
},
SnapshotError::BinaryModelDecodeError { inner, path } => {
write!(output, "Malformed rbxm model: {:?} in path {}", inner, path.display())
},
SnapshotError::CsvDecodeError { inner, path } => {
write!(output, "Malformed csv file: {} in path {}", inner, path.display())
},
SnapshotError::ProjectNodeUnusable => {
write!(output, "Rojo project nodes must specify either $path or $className.")
},
@@ -99,24 +197,27 @@ impl fmt::Display for SnapshotError {
writeln!(output, "")?;
writeln!(output, "Partition target ($path): {}", partition_path.display())
},
SnapshotError::PropertyResolveError { inner } => write!(output, "{}", inner),
}
}
}
pub fn snapshot_project_tree<'source>(
context: &SnapshotContext,
imfs: &'source Imfs,
project: &'source Project,
) -> SnapshotResult<'source> {
snapshot_project_node(imfs, &project.tree, Cow::Borrowed(&project.name))
snapshot_project_node(context, imfs, &project.tree, Cow::Borrowed(&project.name))
}
pub fn snapshot_project_node<'source>(
context: &SnapshotContext,
imfs: &'source Imfs,
node: &ProjectNode,
instance_name: Cow<'source, str>,
) -> SnapshotResult<'source> {
let maybe_snapshot = match &node.path {
Some(path) => snapshot_imfs_path(imfs, &path, Some(instance_name.clone()))?,
Some(path) => snapshot_imfs_path(context, imfs, &path, Some(instance_name.clone()))?,
None => match &node.class_name {
Some(_class_name) => Some(RbxSnapshotInstance {
name: instance_name.clone(),
@@ -170,13 +271,14 @@ pub fn snapshot_project_node<'source>(
}
for (child_name, child_project_node) in &node.children {
if let Some(child) = snapshot_project_node(imfs, child_project_node, Cow::Owned(child_name.clone()))? {
if let Some(child) = snapshot_project_node(context, imfs, child_project_node, Cow::Owned(child_name.clone()))? {
snapshot.children.push(child);
}
}
for (key, value) in &node.properties {
snapshot.properties.insert(key.clone(), value.clone());
let resolved_value = try_resolve_value(&snapshot.class_name, key, value)?;
snapshot.properties.insert(key.clone(), resolved_value);
}
if let Some(ignore_unknown_instances) = node.ignore_unknown_instances {
@@ -189,6 +291,7 @@ pub fn snapshot_project_node<'source>(
}
pub fn snapshot_imfs_path<'source>(
context: &SnapshotContext,
imfs: &'source Imfs,
path: &Path,
instance_name: Option<Cow<'source, str>>,
@@ -196,23 +299,25 @@ pub fn snapshot_imfs_path<'source>(
// If the given path doesn't exist in the in-memory filesystem, we consider
// that an error.
match imfs.get(path) {
Some(imfs_item) => snapshot_imfs_item(imfs, imfs_item, instance_name),
Some(imfs_item) => snapshot_imfs_item(context, imfs, imfs_item, instance_name),
None => return Err(SnapshotError::DidNotExist(path.to_owned())),
}
}
fn snapshot_imfs_item<'source>(
context: &SnapshotContext,
imfs: &'source Imfs,
item: &'source ImfsItem,
instance_name: Option<Cow<'source, str>>,
) -> SnapshotResult<'source> {
match item {
ImfsItem::File(file) => snapshot_imfs_file(file, instance_name),
ImfsItem::Directory(directory) => snapshot_imfs_directory(imfs, directory, instance_name),
ImfsItem::File(file) => snapshot_imfs_file(context, imfs, file, instance_name),
ImfsItem::Directory(directory) => snapshot_imfs_directory(context, imfs, directory, instance_name),
}
}
fn snapshot_imfs_directory<'source>(
context: &SnapshotContext,
imfs: &'source Imfs,
directory: &'source ImfsDirectory,
instance_name: Option<Cow<'source, str>>,
@@ -229,11 +334,11 @@ fn snapshot_imfs_directory<'source>(
});
let mut snapshot = if directory.children.contains(&init_path) {
snapshot_imfs_path(imfs, &init_path, Some(snapshot_name))?.unwrap()
snapshot_imfs_path(context, imfs, &init_path, Some(snapshot_name))?.unwrap()
} else if directory.children.contains(&init_server_path) {
snapshot_imfs_path(imfs, &init_server_path, Some(snapshot_name))?.unwrap()
snapshot_imfs_path(context, imfs, &init_server_path, Some(snapshot_name))?.unwrap()
} else if directory.children.contains(&init_client_path) {
snapshot_imfs_path(imfs, &init_client_path, Some(snapshot_name))?.unwrap()
snapshot_imfs_path(context, imfs, &init_client_path, Some(snapshot_name))?.unwrap()
} else {
RbxSnapshotInstance {
class_name: Cow::Borrowed("Folder"),
@@ -248,6 +353,10 @@ fn snapshot_imfs_directory<'source>(
}
};
if let Some(meta) = ExtraMetadata::locate(&imfs, &directory.path.join("init"))? {
meta.apply(&mut snapshot)?;
}
snapshot.metadata.source_path = Some(directory.path.to_owned());
for child_path in &directory.children {
@@ -255,24 +364,105 @@ fn snapshot_imfs_directory<'source>(
.file_name().expect("Couldn't extract file name")
.to_str().expect("Couldn't convert file name to UTF-8");
if child_name.ends_with(".meta.json") {
// meta.json files don't turn into instances themselves, they just
// modify other instances.
continue;
}
match child_name {
INIT_MODULE_NAME | INIT_SERVER_NAME | INIT_CLIENT_NAME => {
// The existence of files with these names modifies the
// parent instance and is handled above, so we can skip
// them here.
},
_ => {
if let Some(child) = snapshot_imfs_path(imfs, child_path, None)? {
snapshot.children.push(child);
}
},
continue;
}
_ => {}
}
if let Some(child) = snapshot_imfs_path(context, imfs, child_path, None)? {
snapshot.children.push(child);
}
}
Ok(Some(snapshot))
}
#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
struct ExtraMetadata {
class_name: Option<String>,
ignore_unknown_instances: Option<bool>,
#[serde(default = "HashMap::new")]
properties: HashMap<String, UnresolvedRbxValue>,
}
impl ExtraMetadata {
fn apply(self, snapshot: &mut RbxSnapshotInstance) -> Result<(), SnapshotError> {
if let Some(meta_class) = self.class_name {
snapshot.class_name = Cow::Owned(meta_class);
}
if let Some(meta_ignore_instances) = self.ignore_unknown_instances {
snapshot.metadata.ignore_unknown_instances = meta_ignore_instances;
}
for (key, value) in self.properties {
let resolved_value = try_resolve_value(&snapshot.class_name, &key, &value)?;
snapshot.properties.insert(key, resolved_value);
}
Ok(())
}
fn locate(imfs: &Imfs, path: &Path) -> Result<Option<ExtraMetadata>, SnapshotError> {
match imfs.get(&path.with_extension("meta.json")) {
Some(ImfsItem::File(file)) => {
let meta: ExtraMetadata = serde_json::from_slice(&file.contents)
.map_err(|inner| SnapshotError::ExtraMetadataError {
inner,
path: file.path.to_path_buf(),
})?;
Ok(Some(meta))
}
_ => Ok(None)
}
}
fn validate_for_non_init(&self, path: &Path) -> Result<(), SnapshotError> {
if self.class_name.is_some() {
return Err(SnapshotError::MetadataClassNameNonInit {
path: path.to_owned(),
});
}
Ok(())
}
fn validate_for_model(&self, path: &Path) -> Result<(), SnapshotError> {
if self.class_name.is_some() {
return Err(SnapshotError::InvalidMetadataModelField {
field_name: "className".to_owned(),
path: path.to_owned(),
});
}
if !self.properties.is_empty() {
return Err(SnapshotError::InvalidMetadataModelField {
field_name: "properties".to_owned(),
path: path.to_owned(),
});
}
Ok(())
}
}
fn snapshot_imfs_file<'source>(
context: &SnapshotContext,
imfs: &'source Imfs,
file: &'source ImfsFile,
instance_name: Option<Cow<'source, str>>,
) -> SnapshotResult<'source> {
@@ -280,11 +470,11 @@ fn snapshot_imfs_file<'source>(
.map(|v| v.to_str().expect("Could not convert extension to UTF-8"));
let mut maybe_snapshot = match extension {
Some("lua") => snapshot_lua_file(file)?,
Some("csv") => snapshot_csv_file(file)?,
Some("txt") => snapshot_txt_file(file)?,
Some("rbxmx") => snapshot_xml_model_file(file)?,
Some("rbxm") => snapshot_binary_model_file(file)?,
Some("lua") => snapshot_lua_file(file, imfs)?,
Some("csv") => snapshot_csv_file(file, imfs)?,
Some("txt") => snapshot_txt_file(file, imfs)?,
Some("rbxmx") => snapshot_xml_model_file(file, imfs)?,
Some("rbxm") => snapshot_binary_model_file(file, imfs)?,
Some("json") => {
let file_stem = file.path
.file_stem().expect("Could not extract file stem")
@@ -299,7 +489,7 @@ fn snapshot_imfs_file<'source>(
Some(_) | None => None,
};
if let Some(snapshot) = maybe_snapshot.as_mut() {
if let Some(mut snapshot) = maybe_snapshot.as_mut() {
// Carefully preserve name from project manifest if present.
if let Some(snapshot_name) = instance_name {
snapshot.name = snapshot_name;
@@ -308,11 +498,26 @@ fn snapshot_imfs_file<'source>(
info!("File generated no snapshot: {}", file.path.display());
}
if let Some(snapshot) = maybe_snapshot.as_ref() {
if let Some(plugin_context) = &context.plugin_context {
for plugin in &plugin_context.plugins {
let owned_snapshot = snapshot.get_owned();
let registry_key = &plugin.callback;
plugin_context.lua.context(move |context| {
let callback: rlua::Function = context.registry_value(registry_key).unwrap();
callback.call::<_, ()>(LuaRbxSnapshot(owned_snapshot)).unwrap();
});
}
}
}
Ok(maybe_snapshot)
}
fn snapshot_lua_file<'source>(
file: &'source ImfsFile,
imfs: &'source Imfs,
) -> SnapshotResult<'source> {
let file_stem = file.path
.file_stem().expect("Could not extract file stem")
@@ -332,7 +537,7 @@ fn snapshot_lua_file<'source>(
path: file.path.to_path_buf(),
})?;
Ok(Some(RbxSnapshotInstance {
let mut snapshot = RbxSnapshotInstance {
name: Cow::Borrowed(instance_name),
class_name: Cow::Borrowed(class_name),
properties: hashmap! {
@@ -346,7 +551,14 @@ fn snapshot_lua_file<'source>(
ignore_unknown_instances: false,
project_definition: None,
},
}))
};
if let Some(meta) = ExtraMetadata::locate(&imfs, &file.path.with_file_name(instance_name))? {
meta.validate_for_non_init(&file.path)?;
meta.apply(&mut snapshot)?;
}
Ok(Some(snapshot))
}
fn match_trailing<'a>(input: &'a str, trailer: &str) -> Option<&'a str> {
@@ -360,6 +572,7 @@ fn match_trailing<'a>(input: &'a str, trailer: &str) -> Option<&'a str> {
fn snapshot_txt_file<'source>(
file: &'source ImfsFile,
imfs: &'source Imfs,
) -> SnapshotResult<'source> {
let instance_name = file.path
.file_stem().expect("Could not extract file stem")
@@ -371,7 +584,7 @@ fn snapshot_txt_file<'source>(
path: file.path.to_path_buf(),
})?;
Ok(Some(RbxSnapshotInstance {
let mut snapshot = RbxSnapshotInstance {
name: Cow::Borrowed(instance_name),
class_name: Cow::Borrowed("StringValue"),
properties: hashmap! {
@@ -385,27 +598,106 @@ fn snapshot_txt_file<'source>(
ignore_unknown_instances: false,
project_definition: None,
},
}))
};
if let Some(meta) = ExtraMetadata::locate(&imfs, &file.path)? {
meta.validate_for_non_init(&file.path)?;
meta.apply(&mut snapshot)?;
}
Ok(Some(snapshot))
}
fn snapshot_csv_file<'source>(
file: &'source ImfsFile,
imfs: &'source Imfs,
) -> SnapshotResult<'source> {
/// Struct that holds any valid row from a Roblox CSV translation table.
///
/// We manually deserialize into this table from CSV, but let JSON handle
/// serializing.
#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
struct LocalizationEntry<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
key: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
context: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
example: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
source: Option<&'a str>,
values: HashMap<&'a str, &'a str>,
}
let instance_name = file.path
.file_stem().expect("Could not extract file stem")
.to_str().expect("Could not convert path to UTF-8");
let entries: Vec<LocalizationEntryJson> = csv::Reader::from_reader(file.contents.as_slice())
.deserialize()
// TODO: Propagate error upward instead of panicking
.map(|result| result.expect("Malformed localization table found!"))
.map(LocalizationEntryCsv::to_json)
.collect();
// Normally, we'd be able to let the csv crate construct our struct for us.
//
// However, because of a limitation with Serde's 'flatten' feature, it's not
// possible presently to losslessly collect extra string values while using
// csv+Serde.
//
// https://github.com/BurntSushi/rust-csv/issues/151
let mut reader = csv::Reader::from_reader(file.contents.as_slice());
let headers = reader.headers()
.map_err(|inner| SnapshotError::CsvDecodeError {
inner,
path: file.path.to_path_buf(),
})?
.clone();
let mut records = Vec::new();
for record in reader.into_records() {
let record = record
.map_err(|inner| SnapshotError::CsvDecodeError {
inner,
path: file.path.to_path_buf(),
})?;
records.push(record);
}
let mut entries = Vec::new();
for record in &records {
let mut entry = LocalizationEntry::default();
for (header, value) in headers.iter().zip(record.into_iter()) {
if header.is_empty() || value.is_empty() {
continue;
}
match header {
"Key" => entry.key = Some(value),
"Source" => entry.source = Some(value),
"Context" => entry.context = Some(value),
"Example" => entry.example = Some(value),
_ => {
entry.values.insert(header, value);
}
}
}
if entry.key.is_none() && entry.source.is_none() {
continue;
}
entries.push(entry);
}
let table_contents = serde_json::to_string(&entries)
.expect("Could not encode JSON for localization table");
Ok(Some(RbxSnapshotInstance {
let mut snapshot = RbxSnapshotInstance {
name: Cow::Borrowed(instance_name),
class_name: Cow::Borrowed("LocalizationTable"),
properties: hashmap! {
@@ -419,40 +711,14 @@ fn snapshot_csv_file<'source>(
ignore_unknown_instances: false,
project_definition: None,
},
}))
}
};
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
struct LocalizationEntryCsv {
key: String,
context: String,
example: String,
source: String,
#[serde(flatten)]
values: HashMap<String, String>,
}
impl LocalizationEntryCsv {
fn to_json(self) -> LocalizationEntryJson {
LocalizationEntryJson {
key: self.key,
context: self.context,
example: self.example,
source: self.source,
values: self.values,
}
if let Some(meta) = ExtraMetadata::locate(&imfs, &file.path)? {
meta.validate_for_non_init(&file.path)?;
meta.apply(&mut snapshot)?;
}
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct LocalizationEntryJson {
key: String,
context: String,
example: String,
source: String,
values: HashMap<String, String>,
Ok(Some(snapshot))
}
fn snapshot_json_model_file<'source>(
@@ -470,7 +736,7 @@ fn snapshot_json_model_file<'source>(
path: file.path.to_owned(),
})?;
let mut snapshot = json_instance.into_snapshot();
let mut snapshot = json_instance.into_snapshot()?;
snapshot.metadata.source_path = Some(file.path.to_owned());
Ok(Some(snapshot))
@@ -486,47 +752,52 @@ struct JsonModelInstance {
children: Vec<JsonModelInstance>,
#[serde(default = "HashMap::new", skip_serializing_if = "HashMap::is_empty")]
properties: HashMap<String, RbxValue>,
properties: HashMap<String, UnresolvedRbxValue>,
}
impl JsonModelInstance {
fn into_snapshot(mut self) -> RbxSnapshotInstance<'static> {
let children = self.children
.drain(..)
.map(JsonModelInstance::into_snapshot)
.collect();
fn into_snapshot(self) -> Result<RbxSnapshotInstance<'static>, SnapshotError> {
let mut children = Vec::with_capacity(self.children.len());
RbxSnapshotInstance {
for child in self.children {
children.push(child.into_snapshot()?);
}
let mut properties = HashMap::with_capacity(self.properties.len());
for (key, value) in self.properties {
let resolved_value = try_resolve_value(&self.class_name, &key, &value)?;
properties.insert(key, resolved_value);
}
Ok(RbxSnapshotInstance {
name: Cow::Owned(self.name),
class_name: Cow::Owned(self.class_name),
properties: self.properties,
properties,
children,
metadata: Default::default(),
}
})
}
}
fn snapshot_xml_model_file<'source>(
file: &'source ImfsFile,
imfs: &'source Imfs,
) -> SnapshotResult<'source> {
let instance_name = file.path
.file_stem().expect("Could not extract file stem")
.to_str().expect("Could not convert path to UTF-8");
let mut temp_tree = RbxTree::new(RbxInstanceProperties {
name: "Temp".to_owned(),
class_name: "Folder".to_owned(),
properties: HashMap::new(),
});
let options = rbx_xml::DecodeOptions::new()
.property_behavior(rbx_xml::DecodePropertyBehavior::ReadUnknown);
let root_id = temp_tree.get_root_id();
rbx_xml::decode(&mut temp_tree, root_id, file.contents.as_slice())
let temp_tree = rbx_xml::from_reader(file.contents.as_slice(), options)
.map_err(|inner| SnapshotError::XmlModelDecodeError {
inner,
path: file.path.clone(),
})?;
let root_instance = temp_tree.get_instance(root_id).unwrap();
let root_instance = temp_tree.get_instance(temp_tree.get_root_id()).unwrap();
let children = root_instance.get_children_ids();
match children.len() {
@@ -534,6 +805,13 @@ fn snapshot_xml_model_file<'source>(
1 => {
let mut snapshot = snapshot_from_tree(&temp_tree, children[0]).unwrap();
snapshot.name = Cow::Borrowed(instance_name);
snapshot.metadata.source_path = Some(file.path.clone());
if let Some(meta) = ExtraMetadata::locate(&imfs, &file.path)? {
meta.validate_for_model(&file.path)?;
meta.apply(&mut snapshot)?;
}
Ok(Some(snapshot))
},
_ => panic!("Rojo doesn't have support for model files with multiple roots yet"),
@@ -542,6 +820,7 @@ fn snapshot_xml_model_file<'source>(
fn snapshot_binary_model_file<'source>(
file: &'source ImfsFile,
imfs: &'source Imfs,
) -> SnapshotResult<'source> {
let instance_name = file.path
.file_stem().expect("Could not extract file stem")
@@ -568,6 +847,13 @@ fn snapshot_binary_model_file<'source>(
1 => {
let mut snapshot = snapshot_from_tree(&temp_tree, children[0]).unwrap();
snapshot.name = Cow::Borrowed(instance_name);
snapshot.metadata.source_path = Some(file.path.clone());
if let Some(meta) = ExtraMetadata::locate(&imfs, &file.path)? {
meta.validate_for_model(&file.path)?;
meta.apply(&mut snapshot)?;
}
Ok(Some(snapshot))
},
_ => panic!("Rojo doesn't have support for model files with multiple roots yet"),

View File

@@ -1,4 +1,4 @@
use serde_derive::{Serialize, Deserialize};
use serde::{Serialize, Deserialize};
use uuid::Uuid;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]

View File

@@ -10,8 +10,8 @@ use std::{
str,
};
use rbx_tree::{RbxTree, RbxId, RbxInstanceProperties, RbxValue};
use serde_derive::{Serialize, Deserialize};
use rbx_dom_weak::{RbxTree, RbxId, RbxInstanceProperties, RbxValue};
use serde::{Serialize, Deserialize};
use crate::{
path_map::PathMap,
@@ -64,7 +64,7 @@ impl InstanceChanges {
/// A lightweight, hierarchical representation of an instance that can be
/// applied to the tree.
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RbxSnapshotInstance<'a> {
pub name: Cow<'a, str>,
pub class_name: Cow<'a, str>,
@@ -73,6 +73,22 @@ pub struct RbxSnapshotInstance<'a> {
pub metadata: MetadataPerInstance,
}
impl<'a> RbxSnapshotInstance<'a> {
pub fn get_owned(&'a self) -> RbxSnapshotInstance<'static> {
let children: Vec<RbxSnapshotInstance<'static>> = self.children.iter()
.map(RbxSnapshotInstance::get_owned)
.collect();
RbxSnapshotInstance {
name: Cow::Owned(self.name.clone().into_owned()),
class_name: Cow::Owned(self.class_name.clone().into_owned()),
properties: self.properties.clone(),
children,
metadata: self.metadata.clone(),
}
}
}
impl<'a> PartialOrd for RbxSnapshotInstance<'a> {
fn partial_cmp(&self, other: &RbxSnapshotInstance) -> Option<Ordering> {
Some(self.name.cmp(&other.name)
@@ -137,7 +153,7 @@ pub fn reify_subtree(
instance_per_path: &mut PathMap<HashSet<RbxId>>,
metadata_per_instance: &mut HashMap<RbxId, MetadataPerInstance>,
changes: &mut InstanceChanges,
) {
) -> RbxId {
let instance = reify_core(snapshot);
let id = tree.insert_instance(instance, parent_id);
@@ -148,6 +164,8 @@ pub fn reify_subtree(
for child in &snapshot.children {
reify_subtree(child, tree, id, instance_per_path, metadata_per_instance, changes);
}
id
}
fn reify_metadata(
@@ -206,6 +224,9 @@ fn reify_core(snapshot: &RbxSnapshotInstance) -> RbxInstanceProperties {
instance
}
/// Updates the given instance to match the properties defined on the snapshot.
///
/// Returns whether any changes were applied.
fn reconcile_instance_properties(instance: &mut RbxInstanceProperties, snapshot: &RbxSnapshotInstance) -> bool {
let mut has_diffs = false;
@@ -263,6 +284,8 @@ fn reconcile_instance_properties(instance: &mut RbxInstanceProperties, snapshot:
has_diffs
}
/// Updates the children of the instance in the `RbxTree` to match the children
/// of the `RbxSnapshotInstance`. Order will be updated to match.
fn reconcile_instance_children(
tree: &mut RbxTree,
id: RbxId,
@@ -271,12 +294,21 @@ fn reconcile_instance_children(
metadata_per_instance: &mut HashMap<RbxId, MetadataPerInstance>,
changes: &mut InstanceChanges,
) {
let mut visited_snapshot_indices = HashSet::new();
let mut children_to_update: Vec<(RbxId, &RbxSnapshotInstance)> = Vec::new();
let mut children_to_add: Vec<&RbxSnapshotInstance> = Vec::new();
// These lists are kept so that we can apply all the changes we figure out
let mut children_to_maybe_update: Vec<(RbxId, &RbxSnapshotInstance)> = Vec::new();
let mut children_to_add: Vec<(usize, &RbxSnapshotInstance)> = Vec::new();
let mut children_to_remove: Vec<RbxId> = Vec::new();
// This map is used once we're done mutating children to sort them according
// to the order specified in the snapshot. Without it, a snapshot with a new
// child prepended will cause the RbxTree instance to have out-of-order
// children and would make Rojo non-deterministic.
let mut ids_to_snapshot_indices = HashMap::new();
// Since we have to enumerate the children of both the RbxTree instance and
// our snapshot, we keep a set of the snapshot children we've seen.
let mut visited_snapshot_indices = vec![false; snapshot.children.len()];
let children_ids = tree.get_instance(id).unwrap().get_children_ids();
// Find all instances that were removed or updated, which we derive by
@@ -287,7 +319,7 @@ fn reconcile_instance_children(
// Locate a matching snapshot for this instance
let mut matching_snapshot = None;
for (snapshot_index, child_snapshot) in snapshot.children.iter().enumerate() {
if visited_snapshot_indices.contains(&snapshot_index) {
if visited_snapshot_indices[snapshot_index] {
continue;
}
@@ -295,7 +327,8 @@ fn reconcile_instance_children(
// similar. This heuristic is similar to React's reconciliation
// strategy.
if child_snapshot.name == child_instance.name {
visited_snapshot_indices.insert(snapshot_index);
ids_to_snapshot_indices.insert(child_id, snapshot_index);
visited_snapshot_indices[snapshot_index] = true;
matching_snapshot = Some(child_snapshot);
break;
}
@@ -303,26 +336,23 @@ fn reconcile_instance_children(
match matching_snapshot {
Some(child_snapshot) => {
children_to_update.push((child_instance.get_id(), child_snapshot));
},
children_to_maybe_update.push((child_instance.get_id(), child_snapshot));
}
None => {
children_to_remove.push(child_instance.get_id());
},
}
}
}
// Find all instancs that were added, which is just the snapshots we didn't
// match up to existing instances above.
for (snapshot_index, child_snapshot) in snapshot.children.iter().enumerate() {
if !visited_snapshot_indices.contains(&snapshot_index) {
children_to_add.push(child_snapshot);
if !visited_snapshot_indices[snapshot_index] {
children_to_add.push((snapshot_index, child_snapshot));
}
}
for child_snapshot in &children_to_add {
reify_subtree(child_snapshot, tree, id, instance_per_path, metadata_per_instance, changes);
}
// Apply all of our removals we gathered from our diff
for child_id in &children_to_remove {
if let Some(subtree) = tree.remove_instance(*child_id) {
for id in subtree.iter_all_ids() {
@@ -332,7 +362,18 @@ fn reconcile_instance_children(
}
}
for (child_id, child_snapshot) in &children_to_update {
// Apply all of our children additions
for (snapshot_index, child_snapshot) in &children_to_add {
let id = reify_subtree(child_snapshot, tree, id, instance_per_path, metadata_per_instance, changes);
ids_to_snapshot_indices.insert(id, *snapshot_index);
}
// Apply any updates that might have updates
for (child_id, child_snapshot) in &children_to_maybe_update {
reconcile_subtree(tree, *child_id, child_snapshot, instance_per_path, metadata_per_instance, changes);
}
// Apply the sort mapping defined by ids_to_snapshot_indices above
let instance = tree.get_instance_mut(id).unwrap();
instance.sort_children_unstable_by_key(|id| ids_to_snapshot_indices.get(&id).unwrap());
}

View File

@@ -1,4 +1,5 @@
use std::{
collections::HashMap,
fmt,
io::Write,
path::Path,
@@ -6,12 +7,13 @@ use std::{
};
use log::warn;
use rbx_tree::RbxId;
use rbx_dom_weak::{RbxTree, RbxId};
use crate::{
imfs::{Imfs, ImfsItem},
rbx_session::RbxSession,
web::PublicInstanceMetadata,
web::api::PublicInstanceMetadata,
rbx_session::MetadataPerInstance,
};
static GRAPHVIZ_HEADER: &str = r#"
@@ -53,42 +55,59 @@ pub fn graphviz_to_svg(source: &str) -> Option<String> {
Some(String::from_utf8(output.stdout).expect("Failed to parse stdout as UTF-8"))
}
pub struct VisualizeRbxTree<'a, 'b> {
pub tree: &'a RbxTree,
pub metadata: &'b HashMap<RbxId, MetadataPerInstance>,
}
impl<'a, 'b> fmt::Display for VisualizeRbxTree<'a, 'b> {
fn fmt(&self, output: &mut fmt::Formatter) -> fmt::Result {
writeln!(output, "{}", GRAPHVIZ_HEADER)?;
visualize_instance(&self.tree, self.tree.get_root_id(), &self.metadata, output)?;
writeln!(output, "}}")
}
}
/// A Display wrapper struct to visualize an RbxSession as SVG.
pub struct VisualizeRbxSession<'a>(pub &'a RbxSession);
impl<'a> fmt::Display for VisualizeRbxSession<'a> {
fn fmt(&self, output: &mut fmt::Formatter) -> fmt::Result {
writeln!(output, "{}", GRAPHVIZ_HEADER)?;
visualize_rbx_node(self.0, self.0.get_tree().get_root_id(), output)?;
writeln!(output, "}}")?;
Ok(())
writeln!(output, "{}", VisualizeRbxTree {
tree: self.0.get_tree(),
metadata: self.0.get_all_instance_metadata(),
})
}
}
fn visualize_rbx_node(session: &RbxSession, id: RbxId, output: &mut fmt::Formatter) -> fmt::Result {
let node = session.get_tree().get_instance(id).unwrap();
fn visualize_instance(
tree: &RbxTree,
id: RbxId,
metadata: &HashMap<RbxId, MetadataPerInstance>,
output: &mut fmt::Formatter,
) -> fmt::Result {
let instance = tree.get_instance(id).unwrap();
let mut node_label = format!("{}|{}|{}", node.name, node.class_name, id);
let mut instance_label = format!("{}|{}|{}", instance.name, instance.class_name, id);
if let Some(session_metadata) = session.get_instance_metadata(id) {
if let Some(session_metadata) = metadata.get(&id) {
let metadata = PublicInstanceMetadata::from_session_metadata(session_metadata);
node_label.push('|');
node_label.push_str(&serde_json::to_string(&metadata).unwrap());
instance_label.push('|');
instance_label.push_str(&serde_json::to_string(&metadata).unwrap());
}
node_label = node_label
instance_label = instance_label
.replace("\"", "&quot;")
.replace("{", "\\{")
.replace("}", "\\}");
writeln!(output, " \"{}\" [label=\"{}\"]", id, node_label)?;
writeln!(output, " \"{}\" [label=\"{}\"]", id, instance_label)?;
for &child_id in node.get_children_ids() {
for &child_id in instance.get_children_ids() {
writeln!(output, " \"{}\" -> \"{}\"", id, child_id)?;
visualize_rbx_node(session, child_id, output)?;
visualize_instance(tree, child_id, metadata, output)?;
}
Ok(())

View File

@@ -1,32 +1,36 @@
//! Defines Rojo's web interface that all clients use to communicate with a
//! running live-sync session.
//! Defines Rojo's HTTP API, all under /api. These endpoints generally return
//! JSON.
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
sync::{mpsc, Arc},
sync::Arc,
};
use serde_derive::{Serialize, Deserialize};
use log::trace;
use rouille::{
self,
router,
use futures::{
future::{self, IntoFuture},
Future,
sync::oneshot,
};
use hyper::{
service::Service,
header,
StatusCode,
Method,
Body,
Request,
Response,
};
use rbx_tree::{RbxId, RbxInstance};
use serde::{Serialize, Deserialize};
use rbx_dom_weak::{RbxId, RbxInstance};
use crate::{
live_session::LiveSession,
session_id::SessionId,
snapshot_reconciler::InstanceChanges,
visualize::{VisualizeRbxSession, VisualizeImfs, graphviz_to_svg},
rbx_session::{MetadataPerInstance},
};
static HOME_CONTENT: &str = include_str!("../assets/index.html");
/// Contains the instance metadata relevant to Rojo clients.
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -43,7 +47,7 @@ impl PublicInstanceMetadata {
}
/// Used to attach metadata specific to Rojo to instances, which come from the
/// rbx_tree crate.
/// rbx_dom_weak crate.
///
/// Both fields are wrapped in Cow in order to make owned-vs-borrowed simpler
/// for tests.
@@ -82,121 +86,133 @@ pub struct SubscribeResponse<'a> {
pub messages: Cow<'a, [InstanceChanges]>,
}
pub struct Server {
fn response_json<T: serde::Serialize>(value: T) -> Response<Body> {
let serialized = match serde_json::to_string(&value) {
Ok(v) => v,
Err(err) => {
return Response::builder()
.status(StatusCode::BAD_REQUEST)
.header(header::CONTENT_TYPE, "text/plain")
.body(Body::from(err.to_string()))
.unwrap();
},
};
Response::builder()
.header(header::CONTENT_TYPE, "application/json")
.body(Body::from(serialized))
.unwrap()
}
pub struct ApiService {
live_session: Arc<LiveSession>,
server_version: &'static str,
}
impl Server {
pub fn new(live_session: Arc<LiveSession>) -> Server {
Server {
impl Service for ApiService {
type ReqBody = Body;
type ResBody = Body;
type Error = hyper::Error;
type Future = Box<dyn Future<Item = hyper::Response<Self::ReqBody>, Error = Self::Error> + Send>;
fn call(&mut self, request: hyper::Request<Self::ReqBody>) -> Self::Future {
let response = match (request.method(), request.uri().path()) {
(&Method::GET, "/api/rojo") => self.handle_api_rojo(),
(&Method::GET, path) if path.starts_with("/api/read/") => self.handle_api_read(request),
(&Method::GET, path) if path.starts_with("/api/subscribe/") => {
return self.handle_api_subscribe(request);
}
_ => {
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::empty())
.unwrap()
}
};
Box::new(future::ok(response))
}
}
impl ApiService {
pub fn new(live_session: Arc<LiveSession>) -> ApiService {
ApiService {
live_session,
server_version: env!("CARGO_PKG_VERSION"),
}
}
#[allow(unreachable_code)]
pub fn handle_request(&self, request: &Request) -> Response {
trace!("Request {} {}", request.method(), request.url());
router!(request,
(GET) (/) => {
self.handle_home()
},
(GET) (/api/rojo) => {
self.handle_api_rojo()
},
(GET) (/api/subscribe/{ cursor: u32 }) => {
self.handle_api_subscribe(cursor)
},
(GET) (/api/read/{ id_list: String }) => {
let requested_ids: Option<Vec<RbxId>> = id_list
.split(',')
.map(RbxId::parse_str)
.collect();
self.handle_api_read(requested_ids)
},
(GET) (/visualize/rbx) => {
self.handle_visualize_rbx()
},
(GET) (/visualize/imfs) => {
self.handle_visualize_imfs()
},
_ => Response::empty_404()
)
}
pub fn listen(self, port: u16) {
let address = format!("0.0.0.0:{}", port);
rouille::start_server(address, move |request| self.handle_request(request));
}
fn handle_home(&self) -> Response {
Response::html(HOME_CONTENT)
}
/// Get a summary of information about the server
fn handle_api_rojo(&self) -> Response {
fn handle_api_rojo(&self) -> Response<Body> {
let rbx_session = self.live_session.rbx_session.lock().unwrap();
let tree = rbx_session.get_tree();
Response::json(&ServerInfoResponse {
response_json(&ServerInfoResponse {
server_version: self.server_version,
protocol_version: 2,
session_id: self.live_session.session_id,
expected_place_ids: self.live_session.project.serve_place_ids.clone(),
session_id: self.live_session.session_id(),
expected_place_ids: self.live_session.serve_place_ids().clone(),
root_instance_id: tree.get_root_id(),
})
}
/// Retrieve any messages past the given cursor index, and if
/// there weren't any, subscribe to receive any new messages.
fn handle_api_subscribe(&self, cursor: u32) -> Response {
fn handle_api_subscribe(&self, request: Request<Body>) -> <ApiService as Service>::Future {
let argument = &request.uri().path()["/api/subscribe/".len()..];
let cursor: u32 = match argument.parse() {
Ok(v) => v,
Err(err) => {
return Box::new(future::ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.header(header::CONTENT_TYPE, "text/plain")
.body(Body::from(err.to_string()))
.unwrap()));
},
};
let message_queue = Arc::clone(&self.live_session.message_queue);
let session_id = self.live_session.session_id();
// Did the client miss any messages since the last subscribe?
{
let (new_cursor, new_messages) = message_queue.get_messages_since(cursor);
let (tx, rx) = oneshot::channel();
message_queue.subscribe(cursor, tx);
if !new_messages.is_empty() {
return Response::json(&SubscribeResponse {
session_id: self.live_session.session_id,
messages: Cow::Borrowed(&new_messages),
let result = rx.into_future()
.and_then(move |(new_cursor, new_messages)| {
Box::new(future::ok(response_json(SubscribeResponse {
session_id: session_id,
messages: Cow::Owned(new_messages),
message_cursor: new_cursor,
})
}
}
let (tx, rx) = mpsc::channel();
let sender_id = message_queue.subscribe(tx);
match rx.recv() {
Ok(_) => (),
Err(_) => return Response::text("error!").with_status_code(500),
}
message_queue.unsubscribe(sender_id);
{
let (new_cursor, new_messages) = message_queue.get_messages_since(cursor);
return Response::json(&SubscribeResponse {
session_id: self.live_session.session_id,
messages: Cow::Owned(new_messages),
message_cursor: new_cursor,
})))
})
}
.or_else(|e| {
Box::new(future::ok(Response::builder()
.status(500)
.body(Body::from(format!("Internal Error: {:?}", e)))
.unwrap()))
});
Box::new(result)
}
fn handle_api_read(&self, requested_ids: Option<Vec<RbxId>>) -> Response {
fn handle_api_read(&self, request: Request<Body>) -> Response<Body> {
let argument = &request.uri().path()["/api/read/".len()..];
let requested_ids: Option<Vec<RbxId>> = argument
.split(',')
.map(RbxId::parse_str)
.collect();
let message_queue = Arc::clone(&self.live_session.message_queue);
let requested_ids = match requested_ids {
Some(id) => id,
None => return rouille::Response::text("Malformed ID list").with_status_code(400),
None => {
return Response::builder()
.status(StatusCode::BAD_REQUEST)
.header(header::CONTENT_TYPE, "text/plain")
.body(Body::from("Malformed ID list"))
.unwrap();
},
};
let rbx_session = self.live_session.rbx_session.lock().unwrap();
@@ -228,30 +244,10 @@ impl Server {
}
}
Response::json(&ReadResponse {
session_id: self.live_session.session_id,
response_json(&ReadResponse {
session_id: self.live_session.session_id(),
message_cursor,
instances,
})
}
fn handle_visualize_rbx(&self) -> Response {
let rbx_session = self.live_session.rbx_session.lock().unwrap();
let dot_source = format!("{}", VisualizeRbxSession(&rbx_session));
match graphviz_to_svg(&dot_source) {
Some(svg) => Response::svg(svg),
None => Response::text(dot_source),
}
}
fn handle_visualize_imfs(&self) -> Response {
let imfs = self.live_session.imfs.lock().unwrap();
let dot_source = format!("{}", VisualizeImfs(&imfs));
match graphviz_to_svg(&dot_source) {
Some(svg) => Response::svg(svg),
None => Response::text(dot_source),
}
}
}

121
server/src/web/interface.rs Normal file
View File

@@ -0,0 +1,121 @@
//! Defines the HTTP-based UI. These endpoints generally return HTML and SVG.
use std::sync::Arc;
use futures::{future, Future};
use hyper::{
service::Service,
header,
Body,
Method,
StatusCode,
Request,
Response,
};
use ritz::html;
use crate::{
live_session::LiveSession,
visualize::{VisualizeRbxSession, VisualizeImfs, graphviz_to_svg},
};
static HOME_CSS: &str = include_str!("../../assets/index.css");
pub struct InterfaceService {
live_session: Arc<LiveSession>,
server_version: &'static str,
}
impl Service for InterfaceService {
type ReqBody = Body;
type ResBody = Body;
type Error = hyper::Error;
type Future = Box<dyn Future<Item = Response<Self::ReqBody>, Error = Self::Error> + Send>;
fn call(&mut self, request: Request<Self::ReqBody>) -> Self::Future {
let response = match (request.method(), request.uri().path()) {
(&Method::GET, "/") => self.handle_home(),
(&Method::GET, "/visualize/rbx") => self.handle_visualize_rbx(),
(&Method::GET, "/visualize/imfs") => self.handle_visualize_imfs(),
_ => Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::empty())
.unwrap(),
};
Box::new(future::ok(response))
}
}
impl InterfaceService {
pub fn new(live_session: Arc<LiveSession>) -> InterfaceService {
InterfaceService {
live_session,
server_version: env!("CARGO_PKG_VERSION"),
}
}
fn handle_home(&self) -> Response<Body> {
let page = html! {
<html>
<head>
<title>"Rojo"</title>
<style>
{ ritz::UnescapedText::new(HOME_CSS) }
</style>
</head>
<body>
<div class="main">
<h1 class="title">
"Rojo Live Sync is up and running!"
</h1>
<h2 class="subtitle">
"Version " { self.server_version }
</h2>
<a class="docs" href="https://lpghatguy.github.io/rojo">
"Rojo Documentation"
</a>
</div>
</body>
</html>
};
Response::builder()
.header(header::CONTENT_TYPE, "text/html")
.body(Body::from(format!("<!DOCTYPE html>{}", page)))
.unwrap()
}
fn handle_visualize_rbx(&self) -> Response<Body> {
let rbx_session = self.live_session.rbx_session.lock().unwrap();
let dot_source = format!("{}", VisualizeRbxSession(&rbx_session));
match graphviz_to_svg(&dot_source) {
Some(svg) => Response::builder()
.header(header::CONTENT_TYPE, "image/svg+xml")
.body(Body::from(svg))
.unwrap(),
None => Response::builder()
.header(header::CONTENT_TYPE, "text/plain")
.body(Body::from(dot_source))
.unwrap(),
}
}
fn handle_visualize_imfs(&self) -> Response<Body> {
let imfs = self.live_session.imfs.lock().unwrap();
let dot_source = format!("{}", VisualizeImfs(&imfs));
match graphviz_to_svg(&dot_source) {
Some(svg) => Response::builder()
.header(header::CONTENT_TYPE, "image/svg+xml")
.body(Body::from(svg))
.unwrap(),
None => Response::builder()
.header(header::CONTENT_TYPE, "text/plain")
.body(Body::from(dot_source))
.unwrap(),
}
}
}

85
server/src/web/mod.rs Normal file
View File

@@ -0,0 +1,85 @@
// TODO: This module needs to be public for visualize, we should move
// PublicInstanceMetadata and switch this private!
pub mod api;
mod interface;
use std::sync::Arc;
use log::trace;
use futures::{
future::{self, FutureResult},
Future,
};
use hyper::{
service::Service,
Body,
Request,
Response,
Server,
};
use crate::{
live_session::LiveSession,
};
use self::{
api::ApiService,
interface::InterfaceService,
};
pub struct RootService {
api: api::ApiService,
interface: interface::InterfaceService,
}
impl Service for RootService {
type ReqBody = Body;
type ResBody = Body;
type Error = hyper::Error;
type Future = Box<dyn Future<Item = Response<Self::ReqBody>, Error = Self::Error> + Send>;
fn call(&mut self, request: Request<Self::ReqBody>) -> Self::Future {
trace!("{} {}", request.method(), request.uri().path());
if request.uri().path().starts_with("/api") {
self.api.call(request)
} else {
self.interface.call(request)
}
}
}
impl RootService {
pub fn new(live_session: Arc<LiveSession>) -> RootService {
RootService {
api: ApiService::new(Arc::clone(&live_session)),
interface: InterfaceService::new(Arc::clone(&live_session)),
}
}
}
pub struct LiveServer {
live_session: Arc<LiveSession>,
}
impl LiveServer {
pub fn new(live_session: Arc<LiveSession>) -> LiveServer {
LiveServer {
live_session,
}
}
pub fn start(self, port: u16) {
let address = ([127, 0, 0, 1], port).into();
let server = Server::bind(&address)
.serve(move || {
let service: FutureResult<_, hyper::Error> =
future::ok(RootService::new(Arc::clone(&self.live_session)));
service
})
.map_err(|e| eprintln!("Server error: {}", e));
hyper::rt::run(server);
}
}

View File

@@ -1,43 +0,0 @@
use std::io::Read;
use rouille;
use serde;
use serde_json;
static MAX_BODY_SIZE: usize = 100 * 1024 * 1024; // 100 MiB
/// Pulls text that may be JSON out of a Rouille Request object.
///
/// Doesn't do any actual parsing -- all this method does is verify the content
/// type of the request and read the request's body.
fn read_json_text(request: &rouille::Request) -> Option<String> {
// Bail out if the request body isn't marked as JSON
let content_type = request.header("Content-Type")?;
if !content_type.starts_with("application/json") {
return None;
}
let body = request.data()?;
// Allocate a buffer and read up to MAX_BODY_SIZE+1 bytes into it.
let mut out = Vec::new();
body.take(MAX_BODY_SIZE.saturating_add(1) as u64).read_to_end(&mut out).ok()?;
// If the body was too big (MAX_BODY_SIZE+1), we abort instead of trying to
// process it.
if out.len() > MAX_BODY_SIZE {
return None;
}
String::from_utf8(out).ok()
}
/// Reads the body out of a Rouille Request and attempts to turn it into JSON.
pub fn read_json<T>(request: &rouille::Request) -> Option<T>
where
T: serde::de::DeserializeOwned,
{
let body = read_json_text(&request)?;
serde_json::from_str(&body).ok()?
}

View File

@@ -1,5 +1,5 @@
use std::{
collections::{HashMap, HashSet},
collections::{HashMap, HashSet, BTreeSet},
fs,
path::PathBuf,
};
@@ -80,7 +80,7 @@ fn base_tree() -> Result<(TempDir, Imfs, ExpectedImfs, TestResources), Error> {
expected_roots.insert(root.path().to_path_buf());
let root_item = {
let mut children = HashSet::new();
let mut children = BTreeSet::new();
children.insert(foo_path.clone());
children.insert(bar_path.clone());
@@ -91,7 +91,7 @@ fn base_tree() -> Result<(TempDir, Imfs, ExpectedImfs, TestResources), Error> {
};
let foo_item = {
let mut children = HashSet::new();
let mut children = BTreeSet::new();
children.insert(baz_path.clone());
ImfsItem::Directory(ImfsDirectory {
@@ -199,7 +199,7 @@ fn adding_folder() -> Result<(), Error> {
}
let folder_item = {
let mut children = HashSet::new();
let mut children = BTreeSet::new();
children.insert(file1_path.clone());
children.insert(file2_path.clone());

View File

@@ -0,0 +1,55 @@
use std::{
path::{Path, PathBuf},
sync::Arc,
};
use librojo::{
live_session::LiveSession,
project::Project,
};
lazy_static::lazy_static! {
static ref TEST_PROJECTS_ROOT: PathBuf = {
Path::new(env!("CARGO_MANIFEST_DIR")).join("../test-projects")
};
}
#[test]
fn bad_json_model() {
let project = Project::load_fuzzy(&TEST_PROJECTS_ROOT.join("bad_json_model"))
.expect("Project file didn't load");
if LiveSession::new(Arc::new(project)).is_ok() {
panic!("Project should not have succeeded");
}
}
#[test]
fn bad_meta_lua_classname() {
let project = Project::load_fuzzy(&TEST_PROJECTS_ROOT.join("bad_meta_lua_classname"))
.expect("Project file didn't load");
if LiveSession::new(Arc::new(project)).is_ok() {
panic!("Project should not have succeeded");
}
}
#[test]
fn bad_meta_rbxmx_properties() {
let project = Project::load_fuzzy(&TEST_PROJECTS_ROOT.join("bad_meta_rbxmx_properties"))
.expect("Project file didn't load");
if LiveSession::new(Arc::new(project)).is_ok() {
panic!("Project should not have succeeded");
}
}
#[test]
fn bad_missing_files() {
let project = Project::load_fuzzy(&TEST_PROJECTS_ROOT.join("bad_missing_files"))
.expect("Project file didn't load");
if LiveSession::new(Arc::new(project)).is_ok() {
panic!("Project should not have succeeded");
}
}

View File

@@ -1,12 +1,12 @@
#[macro_use] extern crate lazy_static;
use std::{
collections::HashMap,
collections::{HashMap, BTreeMap},
path::{Path, PathBuf},
};
use pretty_assertions::assert_eq;
use rbx_tree::RbxValue;
use rbx_dom_weak::RbxValue;
use librojo::{
project::{Project, ProjectNode},
@@ -53,7 +53,7 @@ fn single_partition_game() {
..Default::default()
};
let mut replicated_storage_children = HashMap::new();
let mut replicated_storage_children = BTreeMap::new();
replicated_storage_children.insert("Foo".to_string(), foo);
let replicated_storage = ProjectNode {
@@ -65,7 +65,7 @@ fn single_partition_game() {
let mut http_service_properties = HashMap::new();
http_service_properties.insert("HttpEnabled".to_string(), RbxValue::Bool {
value: true,
});
}.into());
let http_service = ProjectNode {
class_name: Some(String::from("HttpService")),
@@ -73,7 +73,7 @@ fn single_partition_game() {
..Default::default()
};
let mut root_children = HashMap::new();
let mut root_children = BTreeMap::new();
root_children.insert("ReplicatedStorage".to_string(), replicated_storage);
root_children.insert("HttpService".to_string(), http_service);
@@ -86,6 +86,7 @@ fn single_partition_game() {
Project {
name: "single-sync-point".to_string(),
tree: root_node,
plugins: Vec::new(),
serve_port: None,
serve_place_ids: None,
file_location: project_location.join("default.project.json"),

View File

@@ -0,0 +1,112 @@
mod test_util;
use std::collections::HashMap;
use pretty_assertions::assert_eq;
use rbx_dom_weak::{RbxTree, RbxInstanceProperties};
use librojo::{
snapshot_reconciler::{RbxSnapshotInstance, reconcile_subtree},
};
use test_util::tree::trees_equal;
#[test]
fn patch_communicativity() {
let base_tree = RbxTree::new(RbxInstanceProperties {
name: "DataModel".into(),
class_name: "DataModel".into(),
properties: HashMap::new(),
});
let patch_a = RbxSnapshotInstance {
name: "DataModel".into(),
class_name: "DataModel".into(),
children: vec![
RbxSnapshotInstance {
name: "Child-A".into(),
class_name: "Folder".into(),
..Default::default()
},
],
..Default::default()
};
let patch_b = RbxSnapshotInstance {
name: "DataModel".into(),
class_name: "DataModel".into(),
children: vec![
RbxSnapshotInstance {
name: "Child-B".into(),
class_name: "Folder".into(),
..Default::default()
},
],
..Default::default()
};
let patch_combined = RbxSnapshotInstance {
name: "DataModel".into(),
class_name: "DataModel".into(),
children: vec![
RbxSnapshotInstance {
name: "Child-A".into(),
class_name: "Folder".into(),
..Default::default()
},
RbxSnapshotInstance {
name: "Child-B".into(),
class_name: "Folder".into(),
..Default::default()
},
],
..Default::default()
};
let root_id = base_tree.get_root_id();
let mut tree_a = base_tree.clone();
reconcile_subtree(
&mut tree_a,
root_id,
&patch_a,
&mut Default::default(),
&mut Default::default(),
&mut Default::default(),
);
reconcile_subtree(
&mut tree_a,
root_id,
&patch_combined,
&mut Default::default(),
&mut Default::default(),
&mut Default::default(),
);
let mut tree_b = base_tree.clone();
reconcile_subtree(
&mut tree_b,
root_id,
&patch_b,
&mut Default::default(),
&mut Default::default(),
&mut Default::default(),
);
reconcile_subtree(
&mut tree_b,
root_id,
&patch_combined,
&mut Default::default(),
&mut Default::default(),
&mut Default::default(),
);
match trees_equal(&tree_a, &tree_b) {
Ok(_) => {}
Err(e) => panic!("{}", e),
}
}

View File

@@ -0,0 +1,71 @@
mod test_util;
use std::path::Path;
use pretty_assertions::assert_eq;
use librojo::{
imfs::Imfs,
project::Project,
rbx_snapshot::{SnapshotContext, snapshot_project_tree},
};
use crate::test_util::{
snapshot::*,
};
macro_rules! generate_snapshot_tests {
($($name: ident),*) => {
$(
paste::item! {
#[test]
fn [<snapshot_ $name>]() {
let _ = env_logger::try_init();
let tests_folder = Path::new(env!("CARGO_MANIFEST_DIR")).join("../test-projects");
let project_folder = tests_folder.join(stringify!($name));
run_snapshot_test(&project_folder);
}
}
)*
};
}
generate_snapshot_tests!(
empty,
json_model,
localization,
meta_files,
multi_partition_game,
nested_partitions,
single_partition_game,
single_partition_model,
transmute_partition
);
fn run_snapshot_test(path: &Path) {
println!("Running snapshot from project: {}", path.display());
let project = Project::load_fuzzy(path)
.expect("Couldn't load project file for snapshot test");
let mut imfs = Imfs::new();
imfs.add_roots_from_project(&project)
.expect("Could not add IMFS roots to snapshot project");
let context = SnapshotContext {
plugin_context: None,
};
let mut snapshot = snapshot_project_tree(&context, &imfs, &project)
.expect("Could not generate snapshot for snapshot test");
if let Some(snapshot) = snapshot.as_mut() {
anonymize_snapshot(path, snapshot);
}
match read_expected_snapshot(path) {
Some(expected_snapshot) => assert_eq!(snapshot, expected_snapshot),
None => write_expected_snapshot(path, &snapshot),
}
}

View File

@@ -1,124 +0,0 @@
use std::{
fs::{self, File},
path::{Path, PathBuf},
};
use pretty_assertions::assert_eq;
use librojo::{
imfs::Imfs,
project::{Project, ProjectNode},
rbx_snapshot::snapshot_project_tree,
snapshot_reconciler::{RbxSnapshotInstance},
};
macro_rules! generate_snapshot_tests {
($($name: ident),*) => {
$(
paste::item! {
#[test]
fn [<snapshot_ $name>]() {
let tests_folder = Path::new(env!("CARGO_MANIFEST_DIR")).join("../test-projects");
let project_folder = tests_folder.join(stringify!($name));
run_snapshot_test(&project_folder);
}
}
)*
};
}
generate_snapshot_tests!(
empty,
nested_partitions,
single_partition_game,
single_partition_model,
transmute_partition
);
const SNAPSHOT_EXPECTED_NAME: &str = "expected-snapshot.json";
fn run_snapshot_test(path: &Path) {
println!("Running snapshot from project: {}", path.display());
let project = Project::load_fuzzy(path)
.expect("Couldn't load project file for snapshot test");
let mut imfs = Imfs::new();
imfs.add_roots_from_project(&project)
.expect("Could not add IMFS roots to snapshot project");
let mut snapshot = snapshot_project_tree(&imfs, &project)
.expect("Could not generate snapshot for snapshot test");
if let Some(snapshot) = snapshot.as_mut() {
anonymize_snapshot(path, snapshot);
}
match read_expected_snapshot(path) {
Some(expected_snapshot) => assert_eq!(snapshot, expected_snapshot),
None => write_expected_snapshot(path, &snapshot),
}
}
/// Snapshots contain absolute paths, which simplifies much of Rojo.
///
/// For saving snapshots to the disk, we should strip off the project folder
/// path to make them machine-independent. This doesn't work for paths that fall
/// outside of the project folder, but that's okay here.
///
/// We also need to sort children, since Rojo tends to enumerate the filesystem
/// in an unpredictable order.
fn anonymize_snapshot(project_folder_path: &Path, snapshot: &mut RbxSnapshotInstance) {
match snapshot.metadata.source_path.as_mut() {
Some(path) => *path = anonymize_path(project_folder_path, path),
None => {},
}
match snapshot.metadata.project_definition.as_mut() {
Some((_, project_node)) => anonymize_project_node(project_folder_path, project_node),
None => {},
}
snapshot.children.sort_by(|a, b| a.partial_cmp(b).unwrap());
for child in snapshot.children.iter_mut() {
anonymize_snapshot(project_folder_path, child);
}
}
fn anonymize_project_node(project_folder_path: &Path, project_node: &mut ProjectNode) {
match project_node.path.as_mut() {
Some(path) => *path = anonymize_path(project_folder_path, path),
None => {},
}
for child_node in project_node.children.values_mut() {
anonymize_project_node(project_folder_path, child_node);
}
}
fn anonymize_path(project_folder_path: &Path, path: &Path) -> PathBuf {
if path.is_absolute() {
path.strip_prefix(project_folder_path)
.expect("Could not anonymize absolute path")
.to_path_buf()
} else {
path.to_path_buf()
}
}
fn read_expected_snapshot(path: &Path) -> Option<Option<RbxSnapshotInstance<'static>>> {
let contents = fs::read(path.join(SNAPSHOT_EXPECTED_NAME)).ok()?;
let snapshot: Option<RbxSnapshotInstance<'static>> = serde_json::from_slice(&contents)
.expect("Could not deserialize snapshot");
Some(snapshot)
}
fn write_expected_snapshot(path: &Path, snapshot: &Option<RbxSnapshotInstance>) {
let mut file = File::create(path.join(SNAPSHOT_EXPECTED_NAME))
.expect("Could not open file to write snapshot");
serde_json::to_writer_pretty(&mut file, snapshot)
.expect("Could not serialize snapshot to file");
}

View File

@@ -1,31 +1,13 @@
#![allow(dead_code)]
use std::fs::{create_dir, copy};
use std::path::Path;
use std::io;
use rouille::Request;
use walkdir::WalkDir;
use librojo::web::Server;
pub trait HttpTestUtil {
fn get_string(&self, url: &str) -> String;
}
impl HttpTestUtil for Server {
fn get_string(&self, url: &str) -> String {
let info_request = Request::fake_http("GET", url, vec![], vec![]);
let response = self.handle_request(&info_request);
assert_eq!(response.status_code, 200);
let (mut reader, _) = response.data.into_reader_and_size();
let mut body = String::new();
reader.read_to_string(&mut body).unwrap();
body
}
}
pub mod snapshot;
pub mod tree;
pub fn copy_recursive(from: &Path, to: &Path) -> io::Result<()> {
for entry in WalkDir::new(from) {
@@ -51,4 +33,4 @@ pub fn copy_recursive(from: &Path, to: &Path) -> io::Result<()> {
}
Ok(())
}
}

View File

@@ -0,0 +1,79 @@
use std::{
fs::{self, File},
path::{Path, PathBuf},
};
use librojo::{
project::ProjectNode,
snapshot_reconciler::RbxSnapshotInstance,
rbx_session::MetadataPerInstance,
};
const SNAPSHOT_EXPECTED_NAME: &str = "expected-snapshot.json";
/// Snapshots contain absolute paths, which simplifies much of Rojo.
///
/// For saving snapshots to the disk, we should strip off the project folder
/// path to make them machine-independent. This doesn't work for paths that fall
/// outside of the project folder, but that's okay here.
///
/// We also need to sort children, since Rojo tends to enumerate the filesystem
/// in an unpredictable order.
pub fn anonymize_snapshot(project_folder_path: &Path, snapshot: &mut RbxSnapshotInstance) {
anonymize_metadata(project_folder_path, &mut snapshot.metadata);
snapshot.children.sort_by(|a, b| a.partial_cmp(b).unwrap());
for child in snapshot.children.iter_mut() {
anonymize_snapshot(project_folder_path, child);
}
}
pub fn anonymize_metadata(project_folder_path: &Path, metadata: &mut MetadataPerInstance) {
match metadata.source_path.as_mut() {
Some(path) => *path = anonymize_path(project_folder_path, path),
None => {},
}
match metadata.project_definition.as_mut() {
Some((_, project_node)) => anonymize_project_node(project_folder_path, project_node),
None => {},
}
}
pub fn anonymize_project_node(project_folder_path: &Path, project_node: &mut ProjectNode) {
match project_node.path.as_mut() {
Some(path) => *path = anonymize_path(project_folder_path, path),
None => {},
}
for child_node in project_node.children.values_mut() {
anonymize_project_node(project_folder_path, child_node);
}
}
pub fn anonymize_path(project_folder_path: &Path, path: &Path) -> PathBuf {
if path.is_absolute() {
path.strip_prefix(project_folder_path)
.expect("Could not anonymize absolute path")
.to_path_buf()
} else {
path.to_path_buf()
}
}
pub fn read_expected_snapshot(path: &Path) -> Option<Option<RbxSnapshotInstance<'static>>> {
let contents = fs::read(path.join(SNAPSHOT_EXPECTED_NAME)).ok()?;
let snapshot: Option<RbxSnapshotInstance<'static>> = serde_json::from_slice(&contents)
.expect("Could not deserialize snapshot");
Some(snapshot)
}
pub fn write_expected_snapshot(path: &Path, snapshot: &Option<RbxSnapshotInstance>) {
let mut file = File::create(path.join(SNAPSHOT_EXPECTED_NAME))
.expect("Could not open file to write snapshot");
serde_json::to_writer_pretty(&mut file, snapshot)
.expect("Could not serialize snapshot to file");
}

View File

@@ -0,0 +1,351 @@
//! Defines a mechanism to compare two RbxTree objects and generate a useful
//! diff if they aren't the same. These methods ignore IDs, which are randomly
//! generated whenever a tree is constructed anyways. This makes matching up
//! pairs of instances that should be the same potentially difficult.
//!
//! It relies on a couple different ideas:
//! - Instances with the same name and class name are matched as the same
//! instance. See basic_equal for this logic
//! - A path of period-delimited names (like Roblox's GetFullName) should be
//! enough to debug most issues. If it isn't, we can do something fun like
//! generate GraphViz graphs.
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
fmt,
fs::{self, File},
hash::Hash,
path::{Path, PathBuf},
};
use log::error;
use serde::{Serialize, Deserialize};
use rbx_dom_weak::{RbxId, RbxTree};
use librojo::{
rbx_session::MetadataPerInstance,
live_session::LiveSession,
visualize::{VisualizeRbxTree, graphviz_to_svg},
};
use super::snapshot::anonymize_metadata;
/// Marks a 'step' in the test, which will snapshot the session's current
/// RbxTree object and compare it against the saved snapshot if it exists.
pub fn tree_step(step: &str, live_session: &LiveSession, source_path: &Path) {
let rbx_session = live_session.rbx_session.lock().unwrap();
let tree = rbx_session.get_tree();
let project_folder = live_session.root_project().folder_location();
let metadata = rbx_session.get_all_instance_metadata()
.iter()
.map(|(key, meta)| {
let mut meta = meta.clone();
anonymize_metadata(project_folder, &mut meta);
(*key, meta)
})
.collect();
let tree_with_metadata = TreeWithMetadata {
tree: Cow::Borrowed(&tree),
metadata: Cow::Owned(metadata),
};
match read_tree_by_name(source_path, step) {
Some(expected) => match trees_and_metadata_equal(&expected, &tree_with_metadata) {
Ok(_) => {}
Err(e) => {
error!("Trees at step '{}' were not equal.\n{}", step, e);
let expected_gv = format!("{}", VisualizeRbxTree {
tree: &expected.tree,
metadata: &expected.metadata,
});
let actual_gv = format!("{}", VisualizeRbxTree {
tree: &tree_with_metadata.tree,
metadata: &tree_with_metadata.metadata,
});
let output_dir = PathBuf::from("failed-snapshots");
fs::create_dir_all(&output_dir)
.expect("Could not create failed-snapshots directory");
let expected_basename = format!("{}-{}-expected", live_session.root_project().name, step);
let actual_basename = format!("{}-{}-actual", live_session.root_project().name, step);
let mut expected_out = output_dir.join(expected_basename);
let mut actual_out = output_dir.join(actual_basename);
match (graphviz_to_svg(&expected_gv), graphviz_to_svg(&actual_gv)) {
(Some(expected_svg), Some(actual_svg)) => {
expected_out.set_extension("svg");
actual_out.set_extension("svg");
fs::write(&expected_out, expected_svg)
.expect("Couldn't write expected SVG");
fs::write(&actual_out, actual_svg)
.expect("Couldn't write actual SVG");
}
_ => {
expected_out.set_extension("gv");
actual_out.set_extension("gv");
fs::write(&expected_out, expected_gv)
.expect("Couldn't write expected GV");
fs::write(&actual_out, actual_gv)
.expect("Couldn't write actual GV");
}
}
error!("Output at {} and {}", expected_out.display(), actual_out.display());
panic!("Tree mismatch at step '{}'", step);
}
}
None => {
write_tree_by_name(source_path, step, &tree_with_metadata);
}
}
}
fn new_cow_map<K: Clone + Eq + Hash, V: Clone>() -> Cow<'static, HashMap<K, V>> {
Cow::Owned(HashMap::new())
}
#[derive(Debug, Serialize, Deserialize)]
struct TreeWithMetadata<'a> {
#[serde(flatten)]
pub tree: Cow<'a, RbxTree>,
#[serde(default = "new_cow_map")]
pub metadata: Cow<'a, HashMap<RbxId, MetadataPerInstance>>,
}
fn read_tree_by_name(path: &Path, identifier: &str) -> Option<TreeWithMetadata<'static>> {
let mut file_path = path.join(identifier);
file_path.set_extension("tree.json");
let contents = fs::read(&file_path).ok()?;
let tree: TreeWithMetadata = serde_json::from_slice(&contents)
.expect("Could not deserialize tree");
Some(tree)
}
fn write_tree_by_name(path: &Path, identifier: &str, tree: &TreeWithMetadata) {
let mut file_path = path.join(identifier);
file_path.set_extension("tree.json");
let mut file = File::create(file_path)
.expect("Could not open file to write tree");
serde_json::to_writer_pretty(&mut file, tree)
.expect("Could not serialize tree to file");
}
#[derive(Debug)]
pub struct TreeMismatch {
pub path: Cow<'static, str>,
pub detail: Cow<'static, str>,
}
impl TreeMismatch {
pub fn new<'a, A: Into<Cow<'a, str>>, B: Into<Cow<'a, str>>>(path: A, detail: B) -> TreeMismatch {
TreeMismatch {
path: Cow::Owned(path.into().into_owned()),
detail: Cow::Owned(detail.into().into_owned()),
}
}
fn add_parent(mut self, name: &str) -> TreeMismatch {
self.path.to_mut().insert(0, '.');
self.path.to_mut().insert_str(0, name);
TreeMismatch {
path: self.path,
detail: self.detail,
}
}
}
impl fmt::Display for TreeMismatch {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
writeln!(formatter, "Tree mismatch at path {}", self.path)?;
writeln!(formatter, "{}", self.detail)
}
}
pub fn trees_equal(
left_tree: &RbxTree,
right_tree: &RbxTree,
) -> Result<(), TreeMismatch> {
let left = TreeWithMetadata {
tree: Cow::Borrowed(left_tree),
metadata: Cow::Owned(HashMap::new()),
};
let right = TreeWithMetadata {
tree: Cow::Borrowed(right_tree),
metadata: Cow::Owned(HashMap::new()),
};
trees_and_metadata_equal(&left, &right)
}
fn trees_and_metadata_equal(
left_tree: &TreeWithMetadata,
right_tree: &TreeWithMetadata,
) -> Result<(), TreeMismatch> {
let left_id = left_tree.tree.get_root_id();
let right_id = right_tree.tree.get_root_id();
instances_equal(left_tree, left_id, right_tree, right_id)
}
fn instances_equal(
left_tree: &TreeWithMetadata,
left_id: RbxId,
right_tree: &TreeWithMetadata,
right_id: RbxId,
) -> Result<(), TreeMismatch> {
basic_equal(left_tree, left_id, right_tree, right_id)?;
properties_equal(left_tree, left_id, right_tree, right_id)?;
children_equal(left_tree, left_id, right_tree, right_id)?;
metadata_equal(left_tree, left_id, right_tree, right_id)
}
fn basic_equal(
left_tree: &TreeWithMetadata,
left_id: RbxId,
right_tree: &TreeWithMetadata,
right_id: RbxId,
) -> Result<(), TreeMismatch> {
let left_instance = left_tree.tree.get_instance(left_id)
.expect("ID did not exist in left tree");
let right_instance = right_tree.tree.get_instance(right_id)
.expect("ID did not exist in right tree");
if left_instance.name != right_instance.name {
let message = format!("Name did not match ('{}' vs '{}')", left_instance.name, right_instance.name);
return Err(TreeMismatch::new(&left_instance.name, message));
}
if left_instance.class_name != right_instance.class_name {
let message = format!("Class name did not match ('{}' vs '{}')", left_instance.class_name, right_instance.class_name);
return Err(TreeMismatch::new(&left_instance.name, message));
}
Ok(())
}
fn properties_equal(
left_tree: &TreeWithMetadata,
left_id: RbxId,
right_tree: &TreeWithMetadata,
right_id: RbxId,
) -> Result<(), TreeMismatch> {
let left_instance = left_tree.tree.get_instance(left_id)
.expect("ID did not exist in left tree");
let right_instance = right_tree.tree.get_instance(right_id)
.expect("ID did not exist in right tree");
let mut visited = HashSet::new();
for (key, left_value) in &left_instance.properties {
visited.insert(key);
let right_value = right_instance.properties.get(key);
if Some(left_value) != right_value {
let message = format!(
"Property {}:\n\tLeft: {:?}\n\tRight: {:?}",
key,
Some(left_value),
right_value,
);
return Err(TreeMismatch::new(&left_instance.name, message));
}
}
for (key, right_value) in &right_instance.properties {
if visited.contains(key) {
continue;
}
let left_value = left_instance.properties.get(key);
if left_value != Some(right_value) {
let message = format!(
"Property {}:\n\tLeft: {:?}\n\tRight: {:?}",
key,
left_value,
Some(right_value),
);
return Err(TreeMismatch::new(&left_instance.name, message));
}
}
Ok(())
}
fn children_equal(
left_tree: &TreeWithMetadata,
left_id: RbxId,
right_tree: &TreeWithMetadata,
right_id: RbxId,
) -> Result<(), TreeMismatch> {
let left_instance = left_tree.tree.get_instance(left_id)
.expect("ID did not exist in left tree");
let right_instance = right_tree.tree.get_instance(right_id)
.expect("ID did not exist in right tree");
let left_children = left_instance.get_children_ids();
let right_children = right_instance.get_children_ids();
if left_children.len() != right_children.len() {
return Err(TreeMismatch::new(&left_instance.name, "Instances had different numbers of children"));
}
for (left_child_id, right_child_id) in left_children.iter().zip(right_children) {
instances_equal(left_tree, *left_child_id, right_tree, *right_child_id)
.map_err(|e| e.add_parent(&left_instance.name))?;
}
Ok(())
}
fn metadata_equal(
left_tree: &TreeWithMetadata,
left_id: RbxId,
right_tree: &TreeWithMetadata,
right_id: RbxId,
) -> Result<(), TreeMismatch> {
let left_meta = left_tree.metadata.get(&left_id);
let right_meta = right_tree.metadata.get(&right_id);
if left_meta != right_meta {
let left_instance = left_tree.tree.get_instance(left_id)
.expect("Left instance didn't exist in tree");
let message = format!(
"Metadata mismatch:\n\tLeft: {:?}\n\tRight: {:?}",
left_meta,
right_meta,
);
return Err(TreeMismatch::new(&left_instance.name, message));
}
Ok(())
}

View File

@@ -0,0 +1,68 @@
mod test_util;
use std::{
fs,
path::{Path, PathBuf},
sync::Arc,
thread,
time::Duration,
};
use tempfile::{tempdir, TempDir};
use librojo::{
live_session::LiveSession,
project::Project,
};
use crate::test_util::{
copy_recursive,
tree::tree_step,
};
#[test]
fn multi_partition_game() {
let _ = env_logger::try_init();
let source_path = project_path("multi_partition_game");
let (dir, live_session) = start_session(&source_path);
tree_step("initial", &live_session, &source_path);
let added_path = dir.path().join("a/added");
fs::create_dir_all(&added_path)
.expect("Couldn't create directory");
thread::sleep(Duration::from_millis(250));
tree_step("with_dir", &live_session, &source_path);
let moved_path = dir.path().join("b/added");
fs::rename(&added_path, &moved_path)
.expect("Couldn't rename directory");
thread::sleep(Duration::from_millis(250));
tree_step("with_moved_dir", &live_session, &source_path);
}
/// Find the path to the given test project relative to the manifest.
fn project_path(name: &str) -> PathBuf {
let mut path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../test-projects");
path.push(name);
path
}
/// Starts a new LiveSession for the project located at the given file path.
fn start_session(source_path: &Path) -> (TempDir, LiveSession) {
let dir = tempdir()
.expect("Couldn't create temporary directory");
copy_recursive(&source_path, dir.path())
.expect("Couldn't copy project to temporary directory");
let project = Arc::new(Project::load_fuzzy(dir.path())
.expect("Couldn't load project from temp directory"));
let live_session = LiveSession::new(Arc::clone(&project))
.expect("Couldn't start live session");
(dir, live_session)
}

View File

@@ -0,0 +1,6 @@
{
"name": "bad_json_model",
"tree": {
"$path": "src"
}
}

View File

@@ -0,0 +1,2 @@
ahhh this isn't a JSON model
bamboozled again

View File

@@ -0,0 +1,6 @@
{
"name": "bad_meta_lua_classname",
"tree": {
"$path": "src"
}
}

View File

@@ -0,0 +1 @@
-- foo.lua

Some files were not shown because too many files have changed in this diff Show More