ComputerCraft Forums

General => General => Topic started by: SquidDev on May 20, 2019, 09:15 PM

Title: copy-cat: A ComputerCraft emulator for the web
Post by: SquidDev on May 20, 2019, 09:15 PM
One thing I've been working on for a little while now is revamping CC:Tweaked documentation situation (https://github.com/SquidDev-CC/CC-Tweaked/issues/133). As part of that, I had the fantastic idea of "could we run CC:Tweaked in the browser?", allowing people to run code samples with a click of a button.

Now, at the time, I wasn't aware of EveryOS's fantastic Mimic fork (https://forums.computercraft.cc/index.php?topic=119.0), and so I did the only thing logical and went on a long yak shaving expedition. Presenting...


copy-cat (https://copy-cat.squiddev.cc/): Another ComputerCraft emulator
(https://camo.tmpim.com/cd52cc42e0bf1f9d8b04352f8efbab7b81842c33/68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f53717569644465762d43432f636f70792d6361742f6d61737465722f696d672f737461727475702d75726c2e706e67)

As it's original aim was to be used for documentation, it aims to be as accurate and up-to-date as possible. In order to achieve this, copy-cat is built from a modified version of CC:Tweaked's source code - both the Lua VM and Java APIs behave exactly1 the same.

1. While we try to keep as close as we can, there are some elements which are impossible to emulate due to the restricted environment of a browser.

For instance, the http API has been almost entirely recreated, and some functionality (such as setting specific headers or requesting some sites) is not impossible. As with any emulator, there will be subtle differences in how input events (key presses, mouse clicks, etc...) are handled, so do not rely on our behavior.

While this is all well and good, that's not all copy-cat can do. There's all sorts of other fancy features, including:

That said, there's still lots of things missing, so if you've got suggestions, bug reports or would just like to help out, head over to the issue tracker (https://github.com/SquidDev-CC/copy-cat/issues)! I will confess the performance is a bit lacking a times, but given that this is a Lua VM written in Java running in a Javascript VM, I'll say that's pretty understandable.

One other thing worth mentioning is the ability to run arbitrary startup code via a query parameter. This allows you to create online demos of a program (assuming it doesn't require peripherals or turtles). For instance, why don't you try out mbs (https://copy-cat.squiddev.cc/?startup=ZnMuZGVsZXRlKCJtYnMubHVhIikKaWYgc2hlbGwucnVuKCJ3Z2V0IGh0dHBzOi8vcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbS9TcXVpZERldi1DQy9tYnMvbWFzdGVyL21icy5sdWEgbWJzLmx1YSIpIGFuZCBzaGVsbC5ydW4oIm1icyBpbnN0YWxsIikgdGhlbiBvcy5yZWJvb3QoKSBlbmQ=)?

If you want to try this out yourself, it's just a base64 encoded string - ideally you'd just run your installer. I'm hoping to expand on this in the future (and make it more accessible), but it's a fun POC for now.
Title: copy-cat: A ComputerCraft emulator for the web
Post by: EveryOS on May 22, 2019, 01:20 PM
I noticed that you said that scripts are passed through base64.
It would be nice if you also were able to pass a pastebin script (https://jasonthekitten.github.io/Mimic/?pastebin=2nlqrssd) or pass a URL (https://jasonthekitten.github.io/Mimic/?url=https://github.com/LDDestroier/CC/raw/master/workspace.lua).