GithubHelp home page GithubHelp logo

squiddev-cc / copy-cat Goto Github PK

View Code? Open in Web Editor NEW
39.0 3.0 7.0 1.42 MB

A ComputerCraft emulator for the web

Home Page: https://copy-cat.squiddev.cc/

License: MIT License

JavaScript 6.84% Java 22.61% HTML 7.31% CSS 5.73% TypeScript 57.51%
computercraft emulator

copy-cat's Introduction

Copy Cat

Copy Cat is a ComputerCraft emulator for the web, heavily inspired by the a similar project Mimic. However, unlike Mimic, it's built from the mod's source code - ensuring that it's always 1 as accurate as possible.

The interface is essentially the same as Cloud Catcher, but with the computer running right in your browser rather than a server!


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 entirely recreated, and some functionality (such as setting specific headers or requesting some sites) is not possible. 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 behaviour.

And yes, this disclaimer was longer than the actual description.

Screenshots

The emulator in action

Editing a file

Embedding

It's possible to embed copy-cat within another website. This may be useful if you want to show off your programs on their own site.

<!-- The div to embed your computer. Can be placed anywhere within the page. -->
<div id="embed-computer"></div>

<!-- Any requirejs-compatible loader (https://requirejs.org/) will work. -->
<script type="text/javascript" src="https://copy-cat.squiddev.cc/require.js"></script>

<script>
  // Tell requirejs to load copycat/* from the website.
  require.config({ paths: { copycat: "https://copy-cat.squiddev.cc/" } });
  // Find our #embed-computer element and inject a computer terminal into it.
  require(["copycat/embed"], setup => setup(document.getElementById("embed-computer")));
</script>

The setup function also accepts several arguments, which are demonstrated in this example.

Build it yourself

Due to the nature of this project, Copy Cat has a rather strange build setup. We take sources of [CC: Tweaked, modify them to work in a Javascript environment, and then compile them to JS. Thankfully, this is all automated by Gradle. However, it does require a bit of setup:

Before getting started, you will need the JDK (Java Development Kit), and NodeJS installed and on the path.

  • Clone Copy Cat with submodules: git clone --recursive https://github.com/SquidDev-CC/copy-cat
  • Install NodeJS packages: npm install
  • Build: ./gradlew assemble. You can also automatically build everything when a file changes using ./gradlew assemble --continuous.

The resulting website should be in build/web.

Use git submodule foreach git pull in order to update all source repositories. You will probably need to apply and then regenerate patches after doing so.

copy-cat's People

Contributors

dependabot[bot] avatar gibbo3771 avatar lupus590 avatar squiddev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

copy-cat's Issues

Cannot join on iMac and Kindle

Well, I tried accessing this project, and it seems it doesn't work on Safari or my Kindle. Only on my iPad which is weird. On my kindle it says there isn't a secure connection while my iMac says cannot connect to server. I need help.

Open a specific computer based on URL

This is a bit of a wacky idea and somewhat inspired by this CC:T issue.

I think

  • Maintaining documentation on the web as well as inside CC is a pain. It would be better to have the CC version as a canonical source of documentation with the web acting as a mirror to that.
  • Having a one-click demo/tutorial link for any program would be super awesome.

So what if you could go to the cloud catcher URL with ?computer_data=<url>, and it would use that given URL as a source for the filesystem of the emulated computer.

Some issues I'm aware of:

  • Some fs functions, notably fs.list, wouldn't really work here.
    • Have .cloud-catcher-files at root, use this to download files locally, ..., profit?
    • Limit to GitHub URLs and use the GitHub API to enumerate files?
  • I'm not sure how cloud-catcher stores files locally, but these would ideally be temporary computer instances that are thrown away after use (can warn on startup). This could be awkward to implement.
    • Temporary computer directories named with some time-dependent hash that are removed automatically every now and then?

Now, this isn't a complete solution for documentation. You don't want to load a web page, spin up a Lua VM, and start an emulator, just to see how to use a particular function. This is more for looking at the docs of a system, potentially interactively if the system lets you. I think it would open up a possibility and give an incentive to developers to give their programs really good in-game docs, which is beneficial for everyone.

Intended use:

For documentation, [run myproject help](cloud-catcher-url?computer_data=https://myproject.what/.../computer)
Alternatively, see the wiki for a reference to all functions.
...
<screenshots>
[You can also run these live](cloud-catcher-url?computer_data=https://myproject.what/.../demos)

This is very much a "feedback wanted"/"suggestion" issue... I don't know if it's feasible or even particularly useful. I just had "I wish I could do this" moment. I guess the biggest counter to this is "emulators and pastebin run ...", which I'll be honest is a pretty good alternative, just not quite as slick, easy, or accessible in my opinion.

Performance

Performance of the Lua VM is iffy at best, poor at worst. It'd be nice to do some profiling and see what, if anything can be improved.

A couple of things possibly worth trying

  • Different optimisation levels
  • Updating TeaVM to 0.6-SNAPSHOT. We may need to redo our buildscript as part of this.
  • Compiling to WebAssembly. This may make writing bindings a little bit harder.

We could also try using JSweet, JWebAssembly or Bytecoder, and see if they have any differences in performance. Not sure how production ready either of these are though...

General musings

Like SquidDev-CC/cloud-catcher#1, this is probably going to end up with a lot of unchecked items. But it's a start.

General experience

  • Credits page, with licenses of various sub-projects
  • Information page, with links to repository and the CC wiki.
  • Extend settings page to have all (relevant) CC settings.
  • Save computer label to storage.
  • Screenshot button.
  • Record button. We'd need to use something like gifshot in order to actually generate a gif, but it'd be totally possible.

Tooling

  • Produce a web-min package, with minified CSS and JS.
  • Possibly also run Javascript through Babel, though given our dependence on recent JS features, this may not be useful.
  • Include SHA/MD5 cachebusters inside index.html.

Files

  • Save filesystem to local storage. Ideally writes would be batched.
  • Filesystem browser on the LHS, like Mimic and Cloud Catcher have.
  • Monaco editor - again, can probably copy from Cloud Catcher.
  • Ability to "mount" a filesystem from a GitHub repository and/or Gist. We'd need to display a progress bar as we fetch the entire repository, and then boot the computer afterwards. I've added the ability to run arbitrary startup files via a query argument. I want to look into non-persistent filesystems first.
  • Upload / download computer mount from a ZIP

HTTP

  • Add HTTP support. We can probably do without CORS for now, but we really need a strategy for it. We can run through cors anywhere, but it's a wee bit of a bodge.
  • Add websocket support.

Move the emulator into CC:Tweaked

The problem with using copy-cat for tweaked.cc is that often the emulator doesn't support the latest documented features. For instance, we don't support cc-tweaked/CC-Tweaked@4b09887, despite that being two weeks old now!

The alternative would be to move the TeaVM patches to their "actual" project:

  • For Cobalt, we could publish a separate jar with a "teavm" classifier.
  • For CC:T, move the Java and core TS code into the the projects/web folder. tweaked.cc should then consume the output of that, rather than relying on copy-cat's embedding functionality.
  • copy-cat then just clones CC:T as a sub-module and does some build magic.

This however, does have some possible issues/caveats:

  • This does complicate CC:T dev, as anyone working on the core project now needs to worry about keeping patches in sync. This would be fine if it was just me, but that's not the case!
  • There's actually quite a lot of supporting code in copy-cat (for instance, handling @LuaFunction generation). Is that out of scope?

Other options:

  • Do nothing.

  • Update copy-cat's build process to provide the ROM as a separate bundle. tweaked.cc could then provide the "latest" ROM instead. This does mean the emulator may entirely break in some cases as the Java code lags behind - something to be careful of!

  • Refactor CC:T to avoid our reliance on patches. This should definitely be better post-cc-tweaked/CC-Tweaked#1205 and related refactors, but some things are still painful.

    That said, refactoring some bits will be hard:

    • ComputerThread and TimeoutState are pretty tightly coupled, and CobaltLuaMachine has a heavy reliance on TimeoutState - not sure how to solve that.
    • HTTPAPI is very reliant on Netty, and I don't think we can ever fix that. Maybe we're better off just replacing the whole HTTP API.

Expose config options in the embed interface

As mentioned in #24, there's no way to disable (or change) the CORS proxy. We should probably export some configure method from the embed interface which allows setting/changing the various config options.

Bundle resources separately to the Java code

Our resources make up ~700KiB of the main bundle. While they do compress well, I wonder if we should split them into a separate file (i.e. just a JSON dump of the file's contents). This might mean we can update the resources without having to recompile all of TeaVM, which might result in better caching.

Can't send special characters using HTTP

I don't know if this is known or not, but copy-cat can't receive special characters like ร— and drawing characters. I don't know what characters exactly it can't receive but at least those. They just get replaced by "?". (they work/print fine when they're backslash codes though so it's not the font)

Allow uploading files by dropping them onto the terminal

Similar to how CC:T works!

This is mostly intended for embedded copy-cat (so, tweaked.cc). On the main site, you can drag-and-drop to the sidebar instead.

Possible we can get away with implementing this on the CC:T side - worth looking into.

Rom disappeared

Okay so I'm on mobile and I'm not sure what I did but I somehow removed rom. Also it'd be great if the filesystem on the left could be turned off because 1. its in the way and 2. its probably how I removed rom.

Palette colours are not set

term.setPaletteColour does not render the modified palette. Connecting to cloud-catcher renders it as expected, so it's not an issue on the Java/Lua end.

Edit: OK, this may only be an issue with white! Not quite sure.

fs.move not working

When running fs.move("a","b") i get the error "lua[5]:1: Cannot move files", this also happens if i run "mv a b" in the shell but with the error "/rom/programs/move.lua:38: Cannot move files"

Steps to reproduce this issue:

  1. make a file named "a.lua"
  2. run "mv a.lua b.lua"

Sidebar breaks if folder is open and one above it is deleted

before delete
image

after delete
image

also, the side bar locks up completely (even the cog and i at the bottom), refreshing the page is a workaround though.

The emulator still works, until you try to interact with those folders (this is me redownloading the files)

image
the command is this wget run https://raw.githubusercontent.com/Lupus590-CC/LuaStoned/master/bootstrap.lua

here is a link to the file with the current commit (because I'm expecting that to change), the other files are not run or used in any way other than being downloaded

clean.lua for convinience

fs.delete(".luastoned")
fs.delete("startup/0_lua_stoned.lua")

os.time without "UTC" returns constant 0

This behavior may break functionality of programs such as benchmark tests, clocks, etc.

I believe that this could easily be fixed by wrapping the UTC clock with division or multiplication.

Allow resizing the terminal

It should be enough to add width/height configuration options to the CC config, and then resize whenever such options change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.