aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAge
* js: Split setting nominal and actual canvas sizeBen Harris2022-10-27
| | | | | Now zooming in and out repeatedly doesn't cause the canvas to wither away, but user resizes don't stick any more. Still more to do.
* js: Very bad attempt at making puzzles change size when zoomingBen Harris2022-10-27
| | | | | | This has the entertaining consequence that repeatedly zooming in and out causes puzzles to gradually shrink, thus demonstrating that recording the nominal size correctly will be necessary.
* js: Add a CMake variable to control whether Emscripten emits WASMBen Harris2022-10-27
| | | | | I've finally got bored of keeping (and occasionally losing) a patch that turns it off unconditionally.
* js: Make update_pixel_ratio more backward-compatibleBen Harris2022-10-26
| | | | | | | | Despite my stylistic downgrades, it still used two features not present in Firefox 48, and hence KaiOS 2.5: passing options to addEventListener, and calling addEventListener on a MediaQueryList at all. Now it uses the older addListener method and explicitly removes each listener as soon as it's called.
* js: Use String.replace() in place of .replaceAll()Ben Harris2022-10-26
| | | | | The latter turns out to be a little too new for KaiOS 2.5, but .replace() will do global replacements if fed a RegExp.
* js: Be more subtle about cancelling keydown eventsBen Harris2022-10-25
| | | | | | | | | Now we only cancel a keydown event if the C keyboard handler recognises the key and passes it on to the midend. This doesn't necessarily mean that the midend has actually done anything with it, of course. Still, this is enough to allow F12 to open the developer tools even when the input focus is on the puzzle. It also allows for tabbing out of the puzzle into the links below it.
* js: Remove keypress handlerBen Harris2022-10-25
| | | | | | | | | | | At least in modern browsers (and I suspect in all browsers), cancelling a keydown event ensures that the subsequent keypress event doesn't fire. See <https://w3c.github.io/uievents/#keys-cancelable-keys>. So there's no point in having a handler on keypress events that just tries to cancel them as well. Removing the handler doesn't do much now, but it opens the possibility of being a bit more selective about which keydown events we cancel.
* js: Add a comment explaining the two halves of the key-matching codeBen Harris2022-10-25
|
* js: Handle KeyboardEvent.key == "Spacebar"Ben Harris2022-10-25
| | | | This is apparently generated in place of " " by Internet Explorer.
* js: Recognise KeyboardEvent.key == "Escape"Ben Harris2022-10-24
|
* js: Add mapping for UI_REDO based on KeyboardEvent.keyBen Harris2022-10-24
|
* js: Use KeyboardEvent.key for ASCII keystrokesBen Harris2022-10-24
| | | | | | | | | | This requires passing in KeyboardEvent.location from JavaScript so that we can detect the numeric keypad properly. Out of caution we currently only set MOD_NUM_KEYPAD on numbers, like we always have, but we have enough information to set it on arrow keys, Enter, "+", etc. This finally gets '/' and '\' working in Slant again.
* js: Remove the charCode argument from key()Ben Harris2022-10-24
| | | | It hasn't been used in a while.
* js: Add modern "key" values for Delete and arrow keysBen Harris2022-10-24
| | | | Firefox has emitted "Delete", "ArrowDown" etc since 2015.
* js: Use KeyboardEvent.keyCode and .char only as fallbacksBen Harris2022-10-24
| | | | | | | | | | | KeyboardEvent.keyCode is a platform-dependent mess. KeyboardEvent.char is better-defined, but in my browser it's always null. KeyboardEvent.key is the right thing to use when we want to know the semantics of a key. This commit just re-organises the big "else if" chain in key() so that all the tests on "key" come first. That way at least if key and keyCode disagree, we'll use the more trustworthy one.
* js: Remove braces from big else-if chain in keyboard handlerBen Harris2022-10-24
| | | | | If there's ever a case where they're unnecessary noise, it's a long chain of "else if"s guarding single assignment statements.
* js: Use less-modern syntax in update_pixel_ratioBen Harris2022-10-23
| | | | | | | | Stealing code from the MDN has the consequence that it uses shiny ES6 features like "const", "let", and "=>". This looks a bit odd among the more conservative style of the rest of Puzzles, so I've downgraded it to "var" and "function". I'll let the template string stay because that actually helps readability.
* js: Make resizing of puzzles work properly againBen Harris2022-10-22
| | | | | | This requires looking at the CSS size of the puzzle canvas rather than its internal size, and then adjusting the new size to account for the device pixel ratio.
* js: Pay attention to changes in device pixel ratioBen Harris2022-10-22
| | | | | | | Because it's the simplest thing to do, when we notice such a change we keep the current puzzle at its existing size measured in device pixels. This has the rather odd consequence that when changing the text size in Firefox, the size of the puzzle remains constant.
* js: Pay attention to the device pixel ratioBen Harris2022-10-22
| | | | | | | | | | | | | | | | | | | | The CSS "px" unit isn't always a device pixel. On devices with high-DPI displays, there can often be multiple device pixels to a CSS px, while in particularly low-resolution displays (like feature phones), the user might zoom out to get several CSS px to a device pixel. And even on desktop browsers, text zooming controls can change the ratio. To make Puzzles' rendering look good on an arbitrary device pixel ratio, we really want the pixels of the canvas to be device pixels, not CSS px, so that the canvas doesn't have to be scaled by the browser for display. To correct this, we now control the CSS size of the puzzle canvas, via its containing <div>, to be the canvas size divided by the device pixel ratio. There is a significant gap, which is that this doesn't yet track changes to the device pixel ratio. This is slightly complicated, so I'll put it off to the next commit.
* js: Move some styling from style attributes to stylesheetBen Harris2022-10-22
| | | | For consistency as much as anything else.
* js: Map mouse co-ordinates correctly even when CSS scales our canvasBen Harris2022-10-22
| | | | | | | | | | | | Our system for mapping mouse coordinates to canvas coordinates assumed that the puzzle canvas had the same dimensions in CSS as its own internal width and height. This is true in the current wrapper HTML, but it's very easy to accidentally change and there are circumstances where we might want to deliberately change it in future. To fix this, we now inspect the CSS size of the canvas when processing mouse events, and map the coordinates through the scaling and translation necessary to convert CSS pixels into canvas pixels.
* Update Nikoli links and remove Flash warningsBen Harris2022-10-22
| | | | | | Most of the old URLs don't work any more. As far as I can see, the new pages have no Flash, and even if they did very few browsers will still support it.
* js: Percent-encode game IDs in URLs and decode them again on inputBen Harris2022-10-21
| | | | | | | | | | | | This is necessary to allow all random seeds to round-trip properly. It's probably not currently necessary for descriptive game IDs, but it won't hurt. I've deliberately gone for encoding only those characters that are not valid in fragment identifiers to minimise the ugliness of the generated URLs. For slightly interesting historical reasons, '#' is not valid in a fragment identifier, so all random seed links end up a little bit ugly.
* Build fix: take declarations out of for loops.Simon Tatham2022-10-21
| | | | The NestedVM build is still unhappy with this C99ism, unfortunately.
* js: Read save files as text rather than binary stringsBen Harris2022-10-21
| | | | If I'm going to insist they're text I should be consistent about it.
* Revert "WASM: move save file encoding from JS into C."Ben Harris2022-10-21
| | | | | | | | | | | | Now that save files are (even more) officially ASCII, it's perfectly safe to pass them to JavaScript as UTF-8 strings. This means that the form in which save files are shipped from C to JavaScript is the same is the form in which they're shipped from JavaScript to C. That allows for doing new things with them, like writing them to local storage. This reverts commit f729f51e475ff98d0caf529f0723ef810b1c88ef.
* Update comment on parameter string formats in documentationBen Harris2022-10-20
| | | | | | Net can have non-alphanumeric characters in its parameter strings. Both "5x5b0.1" and "5x5b1e-05" are valid parameter strings generated by Net. So only "most" puzzles use alphanumeric parameter strings.
* Document the asserted printable ASCII nature of many stringsBen Harris2022-10-20
| | | | | The exception is the random seed string, which we lightly document as non-ASCII.
* Assert that everything written to a save file is printable ASCIIBen Harris2022-10-20
| | | | Apart from the newlines of course.
* Hex-encode non-ASCII random seeds in save filesBen Harris2022-10-20
| | | | | | | | | | | | | The developer documentation claims that save files are long ASCII strings. This is mostly true, but there's nothing stopping a user from entering non-ASCII characters as random seeds. The ASCII property of save files is useful, so encode seeds in hex before writing them unless they consist only of printable ASCII characters. Hex-encoded seeds are written under a new key, HEXSEED, to distinguish them from unencoded seeds. This means that old versions of the code won't be able to load encoded seeds, but that's not a great loss: seeds aren't generally portable between versions anyway.
* Add assertions that game descriptions consist only of printable ASCII.Ben Harris2022-10-20
| | | | | | That they are ASCII is implied by their inclusion in save files. Nothing requires an absence of control characters, but it seems polite to make them slightly readable.
* Add an assertion to check the format of encoded parametersBen Harris2022-10-20
| | | | | | | | | | | | Whenever the midend calls encode_params, it also checks that the result is a printable ASCII string that doesn't contain '#' or ':'. Parameter strings are embedded in save files, so they have to fit within ASCII. They can't contain '#' or ':' because those delimit the parameter section of a game ID. Nothing explicitly says they can't contain control characters, but those would be a particularly egregious violation of the recommendation that parameter strings be easy to type into a shell.
* js: Make the dialogue box heading actually be an <h2>Ben Harris2022-10-18
| | | | This is semantically more correct and less ugly as well.
* js: When making a hidden element visible, just remove "display: none"Ben Harris2022-10-17
| | | | | | | | | | | This removes any assumption in the JavaScript code about precisely what "display" setting the element should have. This means that now the only places where the JavaScript manipulates elements' styles are to set the width of the puzzle container and to mark and unmark elements with "display: none". These both seem like reasonable kinds of semantic markup that just happen to be expressed as styles.
* js: Remove unnecessary setting of status bar sizeBen Harris2022-10-17
| | | | | | An element with display: block will naturally adjust to fit the width of its container, so if that's what you want there's no need to set its width explicitly.
* js: Move dialogue-box sizing and positioning from JavaScript to CSSBen Harris2022-10-17
| | | | | This has the advantage that if you resize the window while a dialogue box is active, the dialogue box adjusts itself accordingly.
* js: Move most style settings from JavaScript to CSSBen Harris2022-10-17
| | | | | | | | | Some elements (generally those created by JavaScript) had their style parameters set directly by JavaScript. Putting styles in CSS generally makes them easier to understand (and fiddle with), so I've done that. The only styles left in JavaScript are those that are calculated by JavaScript (like the status-bar size) and the random-seed permalink visibility because I wasn't quite sure how to handle it.
* Correct and enable the range check on statepos when loadingBen Harris2022-10-16
| | | | | | | statepos == 0 shouldn't ever occur in a save file because it indicates an uninitialised midend. OTOH statepos == nstates is normal. Also added an equivalent assertion when saving because Simon and I spent some time discussing whether it could happen.
* Add more validation to midend deserialisation routineBen Harris2022-10-16
| | | | | These are all pretty obvious and enforce constraints that would otherwise be enforced by segfault.
* js: Update permalinks and undo/redo buttons when loadingBen Harris2022-10-15
| | | | | | Without this, the "Undo" button ends up greyed even though it actually works. I'm not sure about whether updating the permalinks is necessary: maybe we don't need that in new_game() either.
* js: Update comment on possible future enhancementsBen Harris2022-10-13
| | | | | | Load/save has been in the JavaScript backend for a while, as have prettier controls. And JavaScript-capable touchscreens are all around us, if still poorly supported by Puzzles.
* Add a missing "const" to js_draw_poly and js_canvas_draw_polyBen Harris2022-10-13
|
* Hide some words in top-level menu items on small viewportsBen Harris2022-10-07
| | | | | | | | | | In their normal state, most of the top-level menu items are a verb and an object, like "Undo move". This is admirably clear, but on a small screen the menu can take a lot of space. In each case the verb alone is sufficient to know what the button does, so use a media query to suppress the noun is the viewport is very narrow. "Very narrow" here is roughly where the menus would overflow onto four lines in my browser.
* Make JavaScript game controls work better in small viewportsBen Harris2022-10-05
| | | | | | | | | | | | | | | | | | | | | | | | | | In the old design, when they wrapped onto multiple lines, various bad things happened. The lines overlapped one another, the lines got broken within buttons but not between buttons, and if they had got broken between buttons the left button on each line would have lacked a left border. I've made two major changes to fix this. First, I've switched from flow layout to flex layout. This has much better default behaviour, breaking lines in the right places, not overlapping lines, and even arranging line-wrapping within a button when the viewport gets really narrow. Second, I've given each button a border on all four sides and then used negative margins to overlap them. This required changing the borders from transparent black to opaque grey to make them display correctly when overlapping. The result is not quite identical to the old version on a wide viewport, but I think it's as close as I can get while keeping the new CSS pleasant. Ideally, the separator would vanish when it was adjacent to a line break, but I've not worked out how to do that yet.
* Enable Apple Silicon in the MacOS builds.Simon Tatham2022-09-12
|
* unix, gtk: Install and use HTML helpBen Hutchings2022-08-01
| | | | | | - Generate HTML pages from the manual, and install them - Add "Contents" and "Help on <name>" menu items that will open the appropriate page in a web browser
* Re-fix the GTK dark theme check.Simon Tatham2022-08-01
| | | | | | | Ben Hutchings points out that when I 'harmlessly' changed 'dark_theme' from a gboolean to a bool, it wasn't harmless, because its address is passed to g_object_get, which expects a pointer to gboolean. (And of course it's a variadic function, so it can't type-check that.)
* Update the developer documentation.Simon Tatham2022-07-31
| | | | | | | | | | | | | | | | | | | | | | | | It's got a bit out of date over the years, with some changes to the code not fully reflected in it (e.g. not all the int -> bool type changes were documented, and TRUE and FALSE were still mentioned), and quite a lot of new functions not added. (In particular, the dsf API was not documented, and it certainly should have been, if only so that people can find out what it even stands for!) As well as correcting for factual accuracy, two content changes in the advice chapter: I've reworded the definition of 'fairness' to explicitly mention that requiring the player to use Undo is cheating. That's always how I _intended_ the definition, but I didn't say it clearly enough. And I've added an entire new section describing the normal sensible way to implement redraw(), via a loop of the form 'work out what this cell should look like, check it against an array in game_drawstate of the last state we drew it in, and if they're different, call a redraw function'. That was mentioned in passing in two other sections, but I know at least one developer didn't find it, so now it's less well hidden.
* Style cleanups from the previous fixes.Simon Tatham2022-07-31
| | | | | | | | | | | | | | Reordered the statements in the fixed Unruly blank_state so that there doesn't need to be a double if statement (and I think it's more sensible in any case to put each memset of a freshly allocated array immediately after the alloc). In GTK set_window_background, the nest of #ifdefs is now complicated enough to deserve a few comments on the #else and #endif lines. And while I was there I switched the gboolean to a bool, on my general principle that platform-specific boolean types are only worth using when you're passing them to a platform API function (and perhaps not even then, if it's not passed by reference).