Skip to content
This repository has been archived by the owner on Jul 19, 2020. It is now read-only.

Commit

Permalink
v1.2 release: Cleaned up code, added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MCJack123 committed Apr 5, 2019
1 parent 267bdc1 commit 1908e14
Show file tree
Hide file tree
Showing 80 changed files with 379 additions and 447 deletions.
12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [ 1.2.0 ] - 2019-04-04
### Added
- `attach`/`detach` programs for creating and removing peripherals
- New icons for Windows (and maybe Linux?)
- Scaling on monitors now works properly
### Fixed
- Rewrote font renderer to not use images (fixes #2, #3)
- Cursor no longer disappears when resizing terminals (#4)
- `term` no longer fails to redirect to a monitor (#5)

## [ 1.2.0-rc1 ] - 2019-04-01
### Added
- Terminal and monitors are now resizeable
- HTTP server listener
### Changed
- 127.0.0.0/8 IP range is no longer blacklisted
### Fixed
- Configuration now does stuff

## [ 1.2.0-b1 ] - 2019-02-25
### Added
- New graphics mode allowing individual pixel addressing
- New `font` API
- `gfxpaint` program: Paint demo for graphics mode
- `raycast` program: Raycasting demo
- `bmpview` program: Views `ccbmp` images (see `/rom/programs/fun/advanced/images`)

## [ 1.1.0 ] - 2018-11-21
### Fixed
- Mouse actions now respect new window borders
- `term.setPaletteColor` works properly
- Fixed HTTP requests

## [ 1.1.0-b1 ] - 2018-10-16
### Added
- Peripheral emulation (`periphemu` API)
- `config` API & tool
- `mounter` API
- `mount` and `unmount` commands
### Changed
- Margins are now present at the edges
### Fixed
- Mouse drag events now send the proper mouse buttons (#1)
- General performance and stability improvements

## [ 1.0.0 ] - 2018-10-14
### Added
- First release
- Compatible with CraftOS 1.8
81 changes: 81 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# New feature documentation
This file provides documentation for the new APIs in CraftOS-PC.

## `periphemu`
Creates and removes peripherals from the registry.
### Functions
* *boolean* create(*string* side, *string* type\[, *string* path\]): Creates a new peripheral.
* side: The side of the new peripheral
* type: One of `monitor`, `speaker`, `printer`
* path: If creating a printer, the local path to the output file
* Returns: `true` on success, `false` on failure (already exists)
* *boolean* remove(*string* side): Removes a peripheral.
* side: The side to remove
* Returns: `true` on success, `false` on failure (already removed)

## `config`
Changes ComputerCraft configuration variables in ComputerCraft.cfg.
### Functions
* *any* get(*string* name): Returns the value of a configuration variable.
* name: The name of the variable
* Returns: The value of the variable
* *void* set(*string* name, *any* value): Sets the value of a configuration variable.
* name: The name of the variable
* value: The new value of the variable
* *table* list(): Returns a list of all configuration variable names.
* *number* getType(*string* name): Returns the type of a variable.
* name: The name of the variable
* Returns: 0 for boolean, 1 for string, 2 for number, 3 for table

## `mounter`
Mounts and unmounts real directories.
### Functions
* *nil* mount(*string* name, *string* path\[, *boolean* readOnly\]): Mounts a real directory to a ComputerCraft directory.
* name: The local directory to mount to
* path: The absolute directory to mount from
* *nil* unmount(*string* name): Unmounts a previously mounted directory.
* name: The local directory to unmount
* *table* list(): Returns a key-value table of all current mounts on the system.

## `term`
Graphics mode extension in the `term` API.
### Functions
* *nil* setGraphicsMode(*boolean* mode): Sets whether the terminal is in pixel-graphics mode
* mode: `true` for graphics, `false` for text
* *boolean* getGraphicsMode(): Returns the current graphics mode setting.
* *nil* setPixel(*number* x, *number* y, *color* color): Sets a pixel at a location.
* x: The X coordinate of the pixel
* y: The Y coordinate of the pixel
* color: The color of the pixel
* *color* getPixel(*number* x, *number* y): Returns the color of a pixel at a location.
* x: The X coordinate of the pixel
* y: The Y coordinate of the pixel
* Returns: The color of the pixel

## `font`
Draws bitmap character fonts in graphics mode. Implements `write`, `getCursorPos`, `setCursorPos`, and `blit` from term.

## `http`
HTTP server extension in the `http` API.
### Functions
* *nil* addListener(*number* port): Adds a listener on a port.
* port: The port to listen on
* *nil* removeListener(*number* port): Frees a port to be listened on again later.
* port: The port to stop listening on
* *nil* listen(*number* port, *function* callback): Starts a server on a port and calls a function when a request is made.
* port: The port to listen on
* callback(*table* req, *table* res): The callback to call
* req: A read file handle to the request data, with the following extra functions:
* getURL(): Returns the URI endpoint of the request
* getMethod(): Returns the HTTP method of the request
* getRequestHeaders(): Returns a table of headers sent by the client
* res: A write file handle to the response data, with the following extra functions:
* setStatusCode(*number* code): Sets the HTTP response code to send
* setResponseHeader(*string* key, *string* value): Sets a header value to send
* **ALWAYS** call `res.close()` before returning from the callback
## Events
* http_request: Sent when an HTTP request is made.
* *number*: The port the request was made on
* *table*: The request table
* *table*: The response table
* server_stop: Send this inside an `http.listen()` callback to stop the server
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@ CraftOS-PC is a port of the CraftOS operating system from the popular Minecraft

![Screenshot](image.png)
![Screenshot](image2.png)
![Screenshot](image3.png)

## What works
* Full terminal interaction (mouse/keyboard)
* Color support
* Most programs written for ComputerCraft should work out-of-the-box
* HTTP
* HTTP requests
* Peripherals (printers, speakers, monitors)
* Mountable drives
* Platform-independent (works on all systems with Java 8)

## New features in CraftOS-PC
* Shared mounts from real PC
* Pixel-based graphics mode
* Resizeable terminals
* HTTP server functionality

## What doesn't work
* Networking/multi-computer support

## How to use
Just download and run the JAR file available in the releases and the terminal will automatically start.
## Usage
Just download and run the JAR or EXE file available in the releases and the terminal will automatically start.

## How to add files
Since ComputerCraft runs sandboxed you cannot access your files normally. The root folder is located at ~/.craftos/computer/0/ or %USERHOME%\.craftos\computer\0\. Any files copied into that folder will be accessible at / inside CraftOS.
## Files
ComputerCraft's root directory is located at `<your home directory>/.craftos/computer/0`. You can place files here, and they will appear in the root directory of the computer.
You can also mount real directories with the `mount` command: `mount /CDrive C:\ `, `mount /Documents /home/user/Documents`.

## License
Since this is based on ComputerCraft it follows the same license as it does. You can read it [here](https://github.com/dan200/ComputerCraft/blob/master/LICENSE) as well as in LICENSE in this repository.
3 changes: 2 additions & 1 deletion com/jackmacwindows/craftos/CraftOSEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.core.computer.IComputerEnvironment;
import dan200.computercraft.core.filesystem.FileMount;
import dan200.computercraft.core.filesystem.JarMount;

import java.io.File;
import java.io.InputStream;
Expand Down Expand Up @@ -34,7 +35,7 @@ public IWritableMount createSaveDirMount( String subPath, long capacity ) {
return new FileMount(new File(getWorldDir().getAbsolutePath() + "/" + subPath), capacity);
}
public IMount createResourceMount( String domain, String subPath ) {
return new FileMount(new File(getClass().getResource("assets/" + domain + "/" + subPath).toString().replaceAll("file:\\\\", "").replaceAll("file:", "")), 0);/*
//return new FileMount(new File(getClass().getResource("assets/" + domain + "/" + subPath).toString().replaceAll("file:\\\\", "").replaceAll("file:", "")), 0);/*
try {
return new JarMount(new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()), "assets/" + domain + "/" + subPath);
} catch (java.io.IOException e) {
Expand Down
1 change: 0 additions & 1 deletion com/jackmacwindows/craftos/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private Main() {
ServerComputer server = new ServerComputer(0, "Computer", 0, ComputerFamily.Advanced, term.width, term.height);
ComputerCraft.instance = new ComputerCraft();
ComputerCraft.instance.preInit();
ComputerCraft.instance.init(); // does nothing right now, but it might later?
ComputerCraft.networkEventChannel.setServer(server);
comp_term = server.getTerminal();
computer = new Computer(env, comp_term, 0);
Expand Down
8 changes: 4 additions & 4 deletions com/jackmacwindows/craftos/Monitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

public class Monitor implements IMonitorProvider, ResizeListener {

private TerminalWindow window;
private Terminal terminal;
private PeriphemuAPI api;
private String side;
private final TerminalWindow window;
private final Terminal terminal;
private final PeriphemuAPI api;
private final String side;
private long lastBlink = 0;

public Monitor(PeriphemuAPI p, String s) {
Expand Down
4 changes: 2 additions & 2 deletions com/jackmacwindows/craftos/MountAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
public class MountAPI implements ILuaAPI {

private FileSystem fs;
private Map<String, IWritableMount> mounts = new HashMap<>();
private Map<String, Boolean> isReadOnly = new HashMap<>();
private final Map<String, IWritableMount> mounts = new HashMap<>();
private final Map<String, Boolean> isReadOnly = new HashMap<>();

MountAPI(FileSystem fs) {
this.fs = fs;
Expand Down
2 changes: 1 addition & 1 deletion com/jackmacwindows/craftos/PeriphemuAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class PeriphemuAPI implements ILuaAPI {

private Map<Integer, IPeripheral> peripherals = new HashMap<>();
private final Map<Integer, IPeripheral> peripherals = new HashMap<>();
private Computer computer;
private IComputerEnvironment environment;

Expand Down
2 changes: 1 addition & 1 deletion com/jackmacwindows/craftos/ResizeListener.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public interface ResizeListener {
interface ResizeListener {
void didResizeWindow(int width, int height);
void willClose();
}
10 changes: 5 additions & 5 deletions com/jackmacwindows/craftos/ResourceMount.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ public class ResourceMount implements IMount {


@Override
public boolean exists(String path) throws IOException {
public boolean exists(String path) {
return false;
}

@Override
public boolean isDirectory(String path) throws IOException {
public boolean isDirectory(String path) {
return false;
}

@Override
public void list(String path, List<String> contents) throws IOException {
public void list(String path, List<String> contents) {

}

@Override
public long getSize(String path) throws IOException {
public long getSize(String path) {
return 0;
}

@Override
public InputStream openForRead(String path) throws IOException {
public InputStream openForRead(String path) {
return null;
}
}
4 changes: 2 additions & 2 deletions com/jackmacwindows/craftos/Speaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class Speaker implements ISpeakerProvider {

private IComputerEnvironment env;
private final IComputerEnvironment env;

public Speaker(IComputerEnvironment e) {
env = e;
Expand All @@ -24,7 +24,7 @@ public Object[] playNote(Object[] arguments, ILuaContext context) throws LuaExce

@Nonnull
@Override
public Object[] playSound(Object[] arguments, ILuaContext context, boolean isNote) throws LuaException {
public Object[] playSound(Object[] arguments, ILuaContext context, boolean isNote) {
//new Thread(new Runnable() {
// The wrapper thread is unnecessary, unless it blocks on the
// Clip finishing; see comments.
Expand Down
8 changes: 4 additions & 4 deletions com/jackmacwindows/craftos/TerminalWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class TerminalWindow {
int charHeight = fontHeight * fontScale * charScale;
TestPane panel;
private TerminalFrame frame;
private Color[] colors = new Color[16];
public Palette p = Palette.DEFAULT;
private ResizeListener delegate;
private final Color[] colors = new Color[16];
public final Palette p = Palette.DEFAULT;
private final ResizeListener delegate;

TerminalWindow(ResizeListener d, String title) {
for (int i = 0; i < 16; i++) {
Expand Down Expand Up @@ -73,7 +73,7 @@ private void resize() {
delegate.didResizeWindow(this.width, this.height);
}

public class TerminalFrame extends JFrame {
class TerminalFrame extends JFrame {
TerminalFrame(String title) {
super(title);
addComponentListener(new ComponentAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ end
local function completeMonitor( shell, nIndex, sText )
if nIndex == 1 then
return completePeripheralName( sText, true )
elseif nIndex == 2 and string.find("resolution", sText) == 1 then
return string.sub("resolution ", string.len(sText))
elseif nIndex == 2 then
return shell.completeProgram( sText )
local retval = shell.completeProgram( sText )
if sText == "" then
table.insert(retval, "resolution ")
elseif string.find("resolution", sText) == 1 then
table.insert(retval, string.sub("resolution ", string.len(sText) + 1))
end
return retval
end
end
local tRedstoneOptions = { "probe", "set ", "pulse " }
Expand Down Expand Up @@ -183,7 +187,7 @@ end
local tPeripherals = {"monitor", "speaker", "printer"}
local function completeAttach(_, nIndex, sText)
if nIndex == 1 then
return completePeripheralName(sText, true)
return completeMultipleChoice(sText, {"left", "right", "top", "bottom", "front", "back"}, true)
elseif nIndex == 2 then
return completeMultipleChoice(sText, tPeripherals)
end
Expand Down
Loading

0 comments on commit 1908e14

Please sign in to comment.