1 Commits

Author SHA1 Message Date
63bcf8532c wip 2020-11-17 10:10:07 +00:00
5 changed files with 33 additions and 76 deletions

View File

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

View File

@@ -2,7 +2,6 @@
@page-background: #968eb5;
@accent: #ec6d7d;
@text: #464256;
@ok: #caec6d;
* {
box-sizing: border-box;
@@ -132,13 +131,3 @@ 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

@@ -34,9 +34,6 @@ 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
@@ -81,6 +78,11 @@ html(lang="en-gb")
| dither
br
label
input#filter(type="checkbox")
| filter
br
button.pagination.prev#back-to-image previous
button.pagination.next#room-next add room
.page.download

View File

@@ -8,6 +8,7 @@ import init, {
output,
set_brightness,
set_dither,
set_filter,
set_palette,
set_room_name,
} from './pkg/pixsy.js';
@@ -78,8 +79,6 @@ 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");
@@ -128,6 +127,7 @@ 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");
});
@@ -154,39 +154,16 @@ async function run() {
}
function checkGameData() {
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 {
if (textareaGameDataInput.value.length > 0) {
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

@@ -33,6 +33,7 @@ struct State {
room_name: Option<String>,
palette: SelectedPalette,
dither: bool,
filter: bool,
brightness: i32,
}
@@ -44,6 +45,7 @@ lazy_static! {
room_name: None,
palette: SelectedPalette::None,
dither: true,
filter: false,
brightness: 0,
}
);
@@ -76,21 +78,16 @@ pub fn load_game(game_data: String) -> String {
let result = Game::from(game_data);
match result {
Ok((game, errors)) => {
Ok((game, _errs)) => {
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: {}. Errors: {}", game_name, errors.join(", "))
}
format!("Loaded game")
},
_ => {
state.game = None;
state.palette = SelectedPalette::None;
format!("Error: {}", result.err().unwrap())
format!("{}", result.err().unwrap())
}
}
}
@@ -136,6 +133,12 @@ pub fn set_dither(dither: bool) {
state.dither = dither;
}
#[wasm_bindgen]
pub fn set_filter(filter: bool) {
let mut state = STATE.lock().unwrap();
state.filter = filter;
}
#[wasm_bindgen]
pub fn set_palette(palette_id: &str, background: String, foreground: String) {
let mut state = STATE.lock().unwrap();
@@ -172,20 +175,18 @@ 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();
for palette in &state.game.as_ref().unwrap().palettes {
let mut object = json::JsonValue::new_object();
object.insert("id", palette.id.clone()).unwrap();
object.insert("id", palette.id.clone()).unwrap();
object.insert(
"name",
palette.name.clone().unwrap_or(
format!("Palette {}", palette.id))
).unwrap();
object.insert(
"name",
palette.name.clone().unwrap_or(
format!("Palette {}", palette.id))
).unwrap();
palette_objects.push(object).unwrap();
}
palette_objects.push(object).unwrap();
}
json::stringify(palette_objects)
@@ -399,16 +400,4 @@ 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(), "[]");
}
}