Compare commits
1 Commits
52728e601b
...
game-data-
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d40fd6e08 |
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "pixsy"
|
name = "pixsy"
|
||||||
version = "0.72.7"
|
version = "0.72.8"
|
||||||
description = "convert images to Bitsy rooms"
|
description = "convert images to Bitsy rooms"
|
||||||
authors = ["Max Bradbury <max@tinybird.info>"]
|
authors = ["Max Bradbury <max@tinybird.info>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
@page-background: #968eb5;
|
@page-background: #968eb5;
|
||||||
@accent: #ec6d7d;
|
@accent: #ec6d7d;
|
||||||
@text: #464256;
|
@text: #464256;
|
||||||
|
@ok: #caec6d;
|
||||||
|
|
||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@@ -131,3 +132,13 @@ textarea {
|
|||||||
image-rendering: pixelated;
|
image-rendering: pixelated;
|
||||||
image-rendering: crisp-edges;
|
image-rendering: crisp-edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message {
|
||||||
|
background-color: @ok;
|
||||||
|
padding: 1em;
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
&#game-data-errors {
|
||||||
|
background-color: @accent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
25
index.pug
25
index.pug
@@ -12,7 +12,7 @@ html(lang="en-gb")
|
|||||||
| pixsy
|
| pixsy
|
||||||
//img(alt="pixsy" src="includes/pixsy.png")
|
//img(alt="pixsy" src="includes/pixsy.png")
|
||||||
p.
|
p.
|
||||||
version 0.72.7
|
convert images to Bitsy rooms
|
||||||
|
|
|
|
||||||
#[a(href="http://tinybird.info/image-to-bitsy/old/" target="_blank") old version]
|
#[a(href="http://tinybird.info/image-to-bitsy/old/" target="_blank") old version]
|
||||||
|
|
|
|
||||||
@@ -21,30 +21,12 @@ html(lang="en-gb")
|
|||||||
#[a(href="https://twitter.com/synth_ruiner") twitter]
|
#[a(href="https://twitter.com/synth_ruiner") twitter]
|
||||||
.pages
|
.pages
|
||||||
.page#start
|
.page#start
|
||||||
p.
|
|
||||||
#[b pixsy] is a tool for #[a(href="http://bitsy.org/") Bitsy Game Maker]
|
|
||||||
that allows you to generate a room from an image and add it to your game.
|
|
||||||
p this version is compatible with Bitsy version 7.2 and earlier.
|
|
||||||
p.
|
|
||||||
#[b pixsy] does not currently work via the Itch desktop program.
|
|
||||||
some users are also currently reporting problems.
|
|
||||||
if pixsy does not work for you, please try the
|
|
||||||
#[a(href="http://tinybird.info/image-to-bitsy/old/") old version] instead.
|
|
||||||
p.
|
|
||||||
instructions can be found on the
|
|
||||||
#[a(href="https://ruin.itch.io/pixsy/") itch.io page] -
|
|
||||||
scroll down to "how to use".
|
|
||||||
|
|
||||||
button.normal.pagination.next#new create a new bitsy game
|
button.normal.pagination.next#new create a new bitsy game
|
||||||
button.normal.pagination.next#load load an existing bitsy game
|
button.normal.pagination.next#load load an existing bitsy game
|
||||||
.page.game-data
|
.page.game-data
|
||||||
h2 game data
|
h2 game data
|
||||||
|
|
||||||
p.
|
input#game(type="file" autocomplete="off")
|
||||||
your game data is available from the #[i game data] window in bitsy,
|
|
||||||
under the #[i tools] dropdown.
|
|
||||||
|
|
||||||
input#game(type="file" accept=".bitsy,.txt" autocomplete="off")
|
|
||||||
br
|
br
|
||||||
|
|
||||||
textarea#game-data(
|
textarea#game-data(
|
||||||
@@ -52,6 +34,9 @@ html(lang="en-gb")
|
|||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
p#game-data-result.message(style="display: none;")
|
||||||
|
p#game-data-errors.message(style="display: none;")
|
||||||
|
|
||||||
button.pagination.prev previous
|
button.pagination.prev previous
|
||||||
button.pagination.next#game-data-next(disabled=true) next
|
button.pagination.next#game-data-next(disabled=true) next
|
||||||
.page.image#page-image
|
.page.image#page-image
|
||||||
|
|||||||
34
script.js
34
script.js
@@ -78,6 +78,8 @@ async function run() {
|
|||||||
const inputColourBackground = el("colour-background");
|
const inputColourBackground = el("colour-background");
|
||||||
const inputColourForeground = el("colour-foreground");
|
const inputColourForeground = el("colour-foreground");
|
||||||
const inputRoomName = el("room-name");
|
const inputRoomName = el("room-name");
|
||||||
|
const paragraphGameResult = el("game-data-result");
|
||||||
|
const paragraphGameErrors = el("game-data-errors");
|
||||||
const selectPalette = el("palette");
|
const selectPalette = el("palette");
|
||||||
const textareaGameDataInput = el("game-data");
|
const textareaGameDataInput = el("game-data");
|
||||||
const textareaGameDataOutput = el("output");
|
const textareaGameDataOutput = el("output");
|
||||||
@@ -126,7 +128,6 @@ async function run() {
|
|||||||
el("game").addEventListener("change", function() {
|
el("game").addEventListener("change", function() {
|
||||||
readFile(this, function (e) {
|
readFile(this, function (e) {
|
||||||
textareaGameDataInput.value = e.target.result;
|
textareaGameDataInput.value = e.target.result;
|
||||||
console.log(load_game(e.target.result));
|
|
||||||
checkGameData();
|
checkGameData();
|
||||||
}, "text");
|
}, "text");
|
||||||
});
|
});
|
||||||
@@ -153,16 +154,39 @@ async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkGameData() {
|
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");
|
buttonGameDataProceed.removeAttribute("disabled");
|
||||||
setPaletteDropdown();
|
setPaletteDropdown();
|
||||||
} else {
|
|
||||||
buttonGameDataProceed.setAttribute("disabled", "disabled");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textareaGameDataInput.addEventListener("change", checkGameData);
|
textareaGameDataInput.addEventListener("change", checkGameData);
|
||||||
textareaGameDataInput.addEventListener("keyup", checkGameData);
|
|
||||||
checkGameData();
|
checkGameData();
|
||||||
|
|
||||||
el('image').addEventListener('change', function () {
|
el('image').addEventListener('change', function () {
|
||||||
|
|||||||
39
src/lib.rs
39
src/lib.rs
@@ -1,3 +1,5 @@
|
|||||||
|
#![feature(clamp)]
|
||||||
|
|
||||||
use bitsy_parser::game::Game;
|
use bitsy_parser::game::Game;
|
||||||
use bitsy_parser::image::Image;
|
use bitsy_parser::image::Image;
|
||||||
use bitsy_parser::tile::Tile;
|
use bitsy_parser::tile::Tile;
|
||||||
@@ -74,16 +76,21 @@ pub fn load_game(game_data: String) -> String {
|
|||||||
let result = Game::from(game_data);
|
let result = Game::from(game_data);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok((game, _errs)) => {
|
Ok((game, errors)) => {
|
||||||
let palette_id = game.palette_ids()[0].clone();
|
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.game = Some(game);
|
||||||
state.palette = SelectedPalette::Existing { id: palette_id };
|
state.palette = SelectedPalette::Existing { id: palette_id };
|
||||||
format!("Loaded game")
|
|
||||||
},
|
format!("Loaded game: {}. Errors: {}", game_name, errors.join(", "))
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
state.game = None;
|
state.game = None;
|
||||||
state.palette = SelectedPalette::None;
|
state.palette = SelectedPalette::None;
|
||||||
format!("{}", result.err().unwrap())
|
|
||||||
|
format!("Error: {}", result.err().unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,6 +172,7 @@ pub fn get_palettes() -> String {
|
|||||||
|
|
||||||
let mut palette_objects = json::JsonValue::new_array();
|
let mut palette_objects = json::JsonValue::new_array();
|
||||||
|
|
||||||
|
if state.game.is_some() {
|
||||||
for palette in &state.game.as_ref().unwrap().palettes {
|
for palette in &state.game.as_ref().unwrap().palettes {
|
||||||
let mut object = json::JsonValue::new_object();
|
let mut object = json::JsonValue::new_object();
|
||||||
|
|
||||||
@@ -178,6 +186,7 @@ pub fn get_palettes() -> String {
|
|||||||
|
|
||||||
palette_objects.push(object).unwrap();
|
palette_objects.push(object).unwrap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
json::stringify(palette_objects)
|
json::stringify(palette_objects)
|
||||||
}
|
}
|
||||||
@@ -247,18 +256,18 @@ pub fn add_room() -> String {
|
|||||||
let mut state = STATE.lock().expect("Couldn't lock application state");
|
let mut state = STATE.lock().expect("Couldn't lock application state");
|
||||||
|
|
||||||
if state.game.is_none() {
|
if state.game.is_none() {
|
||||||
return "No game data loaded".into();
|
return "No game data loaded".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
match &state.palette {
|
match &state.palette {
|
||||||
SelectedPalette::None => { return "No palette selected".into(); },
|
SelectedPalette::None => { return "No palette selected".to_string(); },
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut game = state.game.clone().unwrap();
|
let mut game = state.game.clone().unwrap();
|
||||||
|
|
||||||
if state.image.is_none() {
|
if state.image.is_none() {
|
||||||
return "No image loaded".into();
|
return "No image loaded".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
let palette_id = Some(match &state.palette {
|
let palette_id = Some(match &state.palette {
|
||||||
@@ -290,7 +299,7 @@ pub fn add_room() -> String {
|
|||||||
|
|
||||||
fn colour_match(a: &image::Rgb<u8>, b: &bitsy_parser::Colour) -> u8 {
|
fn colour_match(a: &image::Rgb<u8>, b: &bitsy_parser::Colour) -> u8 {
|
||||||
if a[0] == b.red && a[1] == b.green && a[2] == b.blue { 1 } else { 0 }
|
if a[0] == b.red && a[1] == b.green && a[2] == b.blue { 1 } else { 0 }
|
||||||
}
|
};
|
||||||
|
|
||||||
for y in (row * SD)..((row + 1) * SD) {
|
for y in (row * SD)..((row + 1) * SD) {
|
||||||
for x in (column * SD)..((column + 1) * SD) {
|
for x in (column * SD)..((column + 1) * SD) {
|
||||||
@@ -377,7 +386,7 @@ mod test {
|
|||||||
load_default_game();
|
load_default_game();
|
||||||
load_image(include_str!("test-resources/colour_input.png.base64").trim().to_string());
|
load_image(include_str!("test-resources/colour_input.png.base64").trim().to_string());
|
||||||
let output = get_preview();
|
let output = get_preview();
|
||||||
let expected = include_str!("test-resources/colour_input.png.base64.blueprint").trim();
|
let expected = include_str!("test-resources/colour_input.png.base64.greyscale").trim();
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,4 +399,16 @@ mod test {
|
|||||||
// todo what? why are extraneous pixels appearing in the output tiles?
|
// todo what? why are extraneous pixels appearing in the output tiles?
|
||||||
assert_eq!(output(), include_str!("test-resources/expected.bitsy"));
|
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!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c839MK/VEwn3mpSavXwntqQm8EtwkAC6VWal9f9SjeV4F6BM4T5tJTJb212sIzdBS3CUCFJe1nvYd397QFZyNwPvOsk15fPK9aoX+W6QFgMRZJlZ7v6SvkM9boCJiVMJeeKvqqPfKcegTTAwAuJSyXvep7eG9Pe3A+An6DWWiLrTPI86zFHnqW6QFgEWGhI76nR8n71ugomAfMpK6a2FNlzwO9s9wiACyCyp7v4b09lZYfRc6t8Dut81Y/e9apZ5kaAJZIWCh71YM9FbJ+B59HR+Cslib2VNnzQv8sUwMALMYiaI+t8zyzViFr0KsJvVHU2cJvHDnLWuylnmVqAFgiYSF6asW++gqtZ+yljoBZwky8Knq1hWdqhf5ZpgWAhVgAhazFnlrJfqtWRa9W6I+C+cxDk1YP7KstPEs9y7QAAEtUWKrVh9ZZq5dsnXuWOgrmJcw+0gP7VSv0zzItAC7EEtSq6FXRq6KvKnq1BWej8DeYaS21p1d75Dn1CKYFAFwmYbHab/Vk6wx65/ZTR+JMVPZ8kmdZgx49y7QAsACwBLUqPV9V9FVFr7bgbBT5G8w94tUe9Rx/likBYAleHq3UfvWVd8/tq0A9CmYyDwXqLbwH3MVXTeiNYEoAIBdimfRQe/qqkj7rZK+PjoJ5ySuz67MJc/Icf4YpAXABXt4aqodWL6nn6a1V0auCHwVzmae+g8+mJvTOMiUAkMuwiN5alfRZS6tX6d2xj46Cecm7s1tzsoc/w5QAuAAvb92j3kmfdZL9rMWeCtSjYfaoucxKmEsPPcOUAAAvLyyBr5q0emBflT3fgjujyN8aNZeZzEIFf4YpAWABXhzt4bkqejXZ61lv6UiYCaPmOg+YiUfPMCUAwMsDC1BXrbzSr73qW3BnJPweM1GgPguzmIMK/gxTApAL9GAx7qlSvdR+9WCvKlCP5orZzkzOzP8HNQ0vxIkGykwAAAAASUVORK5CYII=
|
|
||||||
1
src/test-resources/colour_input.png.base64.greyscale
Normal file
1
src/test-resources/colour_input.png.base64.greyscale
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user