8 Commits

Author SHA1 Message Date
4d40fd6e08 wip 2020-11-28 14:51:43 +00:00
47a9bf5c79 explain 2020-11-09 17:48:26 +00:00
d100473542 try to check for webassembly in a different place 2020-11-09 11:55:11 +00:00
d0946d3ab5 readme; remove todo as it's now in the readme and on gitea 2020-11-09 11:54:45 +00:00
5ee1e908f1 link won't open in same iframe 2020-11-08 21:29:21 +00:00
5788baa0b8 new host for old version 2020-11-08 21:27:05 +00:00
f135e184e4 Merge branch 'Refactor3' 2020-11-08 21:19:10 +00:00
21eb632d22 add old version 2020-11-07 19:30:20 +00:00
7 changed files with 136 additions and 31 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "pixsy"
version = "0.72.7"
version = "0.72.8"
description = "convert images to Bitsy rooms"
authors = ["Max Bradbury <max@tinybird.info>"]
edition = "2018"

View File

@@ -1,3 +1,57 @@
# pixsy
convert images to rooms for use in Bitsy
a tool for [Bitsy Game Maker](http://bitsy.org).
upload any image and convert it into a room.
## credits
made by [Max Bradbury](http://tinybird.info/).
makes use of my own [bitsy parser](https://crates.io/crates/bitsy-parser) library.
uses the [Croppie](https://foliotek.github.io/Croppie/) image crop plugin
by [Foliotek](https://www.foliotek.com/)
uses [wasm-bindgen](https://crates.io/crates/wasm-bindgen) to automate WebAssembly bindings.
## thanks
to [Adam Le Doux](http://ledoux.io/) for creating the wonderful and inspiring Bitsy
to [Mark Wonnacott](https://kool.tools/) for their support, encouragement and inspiration
and to everyone in the bitsy community!
## contributing
forks and pull requests welcome!
### development prerequisites
* [rust/cargo](https://rustup.rs/)
* [pug](https://pugjs.org/)
* [less](http://lesscss.org/)
* a bash shell for the build script
## bugs
when importing images, some pixels have errors.
it seems to only happen for pixels surrounded at the top and left:
```
111 111
100 => 110
100 100
```
pixsy does not work in the Itch desktop program
because their bundled version of Chromium does not support WebAssembly.
## to do
* add alternative dithering options (Atkinson, Bayer 8×8)
* add a 'smoothing' (noise reduction?) stage to remove errant pixels
## could do
* reimplement tile reuse option
* add camera support so users can take a pic instead of uploading an image
* allow user to draw to canvas

View File

@@ -1,6 +0,0 @@
# todo
* tile reuse
* noise reduction (remove lonely pixels)
* implement Atkinson and Bayer dithering options
* fix weird problem with pixels flipping (see test::example)

View File

@@ -2,6 +2,7 @@
@page-background: #968eb5;
@accent: #ec6d7d;
@text: #464256;
@ok: #caec6d;
* {
box-sizing: border-box;
@@ -131,3 +132,13 @@ textarea {
image-rendering: pixelated;
image-rendering: crisp-edges;
}
.message {
background-color: @ok;
padding: 1em;
text-align: left;
&#game-data-errors {
background-color: @accent;
}
}

View File

@@ -14,7 +14,7 @@ html(lang="en-gb")
p.
convert images to Bitsy rooms
|
#[a(href="./old/") old version]
#[a(href="http://tinybird.info/image-to-bitsy/old/" target="_blank") old version]
|
#[a(href="mailto:max@tinybird.info") email]
|
@@ -34,6 +34,9 @@ html(lang="en-gb")
autocomplete="off"
)
p#game-data-result.message(style="display: none;")
p#game-data-errors.message(style="display: none;")
button.pagination.prev previous
button.pagination.next#game-data-next(disabled=true) next
.page.image#page-image

View File

@@ -12,10 +12,6 @@ import init, {
set_room_name,
} from './pkg/pixsy.js';
if (typeof WebAssembly !== "object") {
window.location = "./old/"
}
// stolen from https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server
function download(filename, text) {
let element = document.createElement('a');
@@ -60,6 +56,10 @@ function readFile(input, callback, type = "text") {
}
async function run() {
if (typeof WebAssembly !== "object") {
window.location = "http://tinybird.info/image-to-bitsy/old/"
}
await init();
const buttonAddImage = el("add");
@@ -78,6 +78,8 @@ async function run() {
const inputColourBackground = el("colour-background");
const inputColourForeground = el("colour-foreground");
const inputRoomName = el("room-name");
const paragraphGameResult = el("game-data-result");
const paragraphGameErrors = el("game-data-errors");
const selectPalette = el("palette");
const textareaGameDataInput = el("game-data");
const textareaGameDataOutput = el("output");
@@ -126,7 +128,6 @@ async function run() {
el("game").addEventListener("change", function() {
readFile(this, function (e) {
textareaGameDataInput.value = e.target.result;
console.log(load_game(e.target.result));
checkGameData();
}, "text");
});
@@ -153,16 +154,39 @@ async function run() {
}
function checkGameData() {
if (textareaGameDataInput.value.length > 0) {
paragraphGameResult.style.display = "none";
paragraphGameErrors.style.display = "none";
let game_data = textareaGameDataInput.value;
if (game_data.length === 0) {
buttonGameDataProceed.setAttribute("disabled", "disabled");
return;
}
let result = load_game(game_data);
console.debug(result);
let parts = result.split(". Errors: ");
result = parts[0];
let errors = parts[1];
paragraphGameResult.innerText = result;
paragraphGameResult.style.display = "block";
if (errors) {
paragraphGameErrors.innerText = errors;
paragraphGameErrors.style.display = "block";
}
if (result.startsWith("Error")) {
buttonGameDataProceed.setAttribute("disabled", "disabled");
} else {
buttonGameDataProceed.removeAttribute("disabled");
setPaletteDropdown();
} else {
buttonGameDataProceed.setAttribute("disabled", "disabled");
}
}
textareaGameDataInput.addEventListener("change", checkGameData);
textareaGameDataInput.addEventListener("keyup", checkGameData);
checkGameData();
el('image').addEventListener('change', function () {

View File

@@ -76,16 +76,21 @@ pub fn load_game(game_data: String) -> String {
let result = Game::from(game_data);
match result {
Ok((game, _errs)) => {
Ok((game, errors)) => {
let palette_id = game.palette_ids()[0].clone();
let game_name = game.name.clone();
let errors: Vec<String> = errors.iter().map(|err| format!("{}", err)).collect();
state.game = Some(game);
state.palette = SelectedPalette::Existing { id: palette_id };
format!("Loaded game")
},
format!("Loaded game: {}. Errors: {}", game_name, errors.join(", "))
}
_ => {
state.game = None;
state.palette = SelectedPalette::None;
format!("{}", result.err().unwrap())
format!("Error: {}", result.err().unwrap())
}
}
}
@@ -167,6 +172,7 @@ pub fn get_palettes() -> String {
let mut palette_objects = json::JsonValue::new_array();
if state.game.is_some() {
for palette in &state.game.as_ref().unwrap().palettes {
let mut object = json::JsonValue::new_object();
@@ -180,6 +186,7 @@ pub fn get_palettes() -> String {
palette_objects.push(object).unwrap();
}
}
json::stringify(palette_objects)
}
@@ -392,4 +399,16 @@ mod test {
// todo what? why are extraneous pixels appearing in the output tiles?
assert_eq!(output(), include_str!("test-resources/expected.bitsy"));
}
#[test]
fn palettes() {
load_default_game();
assert_eq!(crate::get_palettes(), "[{\"id\":\"0\",\"name\":\"blueprint\"}]");
}
#[test]
fn no_palettes() {
assert_eq!(crate::get_palettes(), "[]");
}
}