Compare commits

..

344 Commits

Author SHA1 Message Date
1f00af5741 Collision Detection Fix + Doodad CLI Fixes
Fix collision detection when an actor's hitbox is offset from 0,0:

* Actors having a hitbox that didn't begin at X,Y 0,0 used to experience
  clipping issues with level geometry: because the game tracks their Position
  (top left corner of their graphical sprite) and their target position wasn't
  being correctly offset by their hitbox offset.
* To resolve the issue, an "ActorOffset" struct is added: you give it the
  original game's Actor (with its offset hitbox) and it will record the offset
  and give a mocked Actor for collision detection purposes: where the Position
  and Target can be offset and where its Hitbox claims to begin at 0,0 matching
  its offsetted Position.
* The translation between your original Actor and Offset Actor is handled at the
  boundary of the CollidesWithGrid function, so the main algorithm didn't need
  to be messed with and the game itself doesn't need to care about the offset.

Make some fixes to the doodad CLI tool:

* Fix palette colors being duplicated/doubled when converting from an image.
* The --palette flag in `doodad convert` now actually functions: so you can
  supply an initial palette.json with colors and attributes to e.g. mark which
  colors should be solid or fire and give them names. The palette.json doesn't
  need to be comprehensive: it will be extended with new distinct colors as
  needed during the conversion.
2024-05-27 15:14:00 -07:00
90414609a9 Update doodad tool documentation 2024-05-24 21:05:54 -07:00
57b757a378 Merge pull request 'RLE Compression for File Formats' (#95) from rle-compression into master
Reviewed-on: #95
2024-05-24 23:47:59 +00:00
f35bc48c05 Code cleanup for RLE compression 2024-05-24 16:43:11 -07:00
c7a3c7a797 Remove never-used GridType accessor + documentation [PTO]
* Add documentation for the game's file formats and RLE encoding
* Remove the never-used GridType Chunk Accessor constant
2024-05-24 16:06:43 -07:00
6be2f86b58 RLE Encoding Code Cleanup [PTO]
* For the doodad tool: skip the assets embed folder, the doodad binary doesn't
  need to include all the game's doodads/levelpacks/etc. and can save on file
  size.
* In `doodad resave`, .doodad files with Vacuum() and upgrade their chunker from
  the MapAccessor to the RLEAccessor.
* Fix a rare concurrent map read/write error in OptimizeChunkerAccessors.
2024-05-24 15:03:32 -07:00
4851730ccf Fix RLE Encoding Off-by-One Errors [PTO]
Levels can now be converted to RLE encoded chunk accessors and be re-saved
continuously without any loss of information.

Off-by-one errors resolved:

* The rle.NewGrid() was adding a +1 everywhere making the 2D grids have 129
  elements to a side for a 128 chunk size.
* In rle.Decompress() the cursor value and translation to X,Y coordinates is
  fixed to avoid a pixel going missing at the end of the first row (128,0)
* The abs.X-- hack in UnmarshalBinary is no longer needed to prevent the
  chunks from scooting a pixel to the right on every save.

Doodad tool updates:

* Remove unused CLI flags in `doodad resave` (actors, chunks, script,
  attachment, verbose) and add a `--output` flag to save to a different file
  name to the original.
* Update `doodad show` to allow debugging of RLE compressed chunks:
    * CLI flag `--chunk=1,2` to specify a single chunk coordinate to debug
    * CLI flag `--visualize-rle` will Visualize() RLE compressed chunks in
      their 2D grid form in your terminal window (VERY noisy for large
      levels! Use the --chunk option to narrow to one chunk).

Bug fixes and misc changes:

* Chunk.Usage() to return a better percentage of chunk utilization.
* Chunker.ChunkFromZipfile() was split out into two functions:
    * RawChunkFromZipfile retrieves the raw bytes of the chunk as well as the
      file extension discovered (.bin or .json) so the caller can interpret
      the bytes correctly.
    * ChunkFromZipfile calls the former function and then depending on file
      extension, unmarshals from binary or json.
    * The Raw function enables the `doodad show` command to debug and visualize
      the raw contents of the RLE compressed chunks.
* Updated the Visualize() function for the RLE encoder: instead of converting
  palette indexes to hex (0-F) which would begin causing problems for palette
  indexes above 16 (as they would use two+ characters), indexes are mapped to
  a wider range of symbols (0-9A-Z) and roll over if you have more than 36
  colors on your level. This at least keeps the Visualize() grid an easy to
  read 128x128 characters in your terminal.
2024-05-24 13:54:41 -07:00
5654145fd8 (Experimental) Run Length Encoding for Levels
Finally add a second option for Chunk MapAccessor implementation besides the
MapAccessor. The RLEAccessor is basically a MapAccessor that will compress
your drawing with Run Length Encoding (RLE) in the on-disk format in the ZIP
file.

This slashes the file sizes of most levels:

* Shapeshifter: 21.8 MB -> 8.1 MB
* Jungle: 10.4 MB -> 4.1 MB
* Zoo: 2.8 MB -> 1.3 MB

Implementation details:

* The RLE binary format for Chunks is a stream of Uvarint pairs storing the
  palette index number and the number of pixels to repeat it (along the Y,X
  axis of the chunk).
    * Null colors are represented by a Uvarint that decodes to 0xFFFF
      or 65535 in decimal.
    * Gameplay logic currently limits maps to 256 colors.
* The default for newly created chunks in-game will be RLE by default.
* Its in-memory representation is still a MapAccessor (a map of absolute
  world coordinates to palette index).
* The game can still open and play legacy MapAccessor maps.
* On save in the editor, the game will upgrade/convert MapAccessor chunks over
  to RLEAccessors, improving on your level's file size with a simple re-save.

Current Bugs

* On every re-save to RLE, one pixel is lost in the bottom-right corner of
  each chunk. Each subsequent re-save loses one more pixel to the left, so what
  starts as a single pixel per chunk slowly evolves into a horizontal line.
* Some pixels smear vertically as well.
* Off-by-negative-one errors when some chunks Iter() their pixels but compute
  a relative coordinate of (-1,0)! Some mismatch between the stored world coords
  of a pixel inside the chunk vs. the chunk's assigned coordinate by the Chunker:
  certain combinations of chunk coord/abs coord.

To Do

* The `doodad touch` command should re-save existing levels to upgrade them.
2024-05-23 23:02:01 -07:00
b1d7c7a384 WIP Run Length Encoding for Levels 2024-05-23 19:15:10 -07:00
57c76de679 Remove deprecated go build -i flag for Windows 2024-05-05 16:49:11 -07:00
9dfd38ea5e Remove redundant make setup step 2024-05-05 16:34:27 -07:00
35962540e1 Fix blockers for v0.14.0 release
* Mac app: exclude the redundant copy of rtp/ folder in the .dmg disk
  image as it only needs to live inside the .app bundle.
* Fix the settings.json file to be initialized and saved to disk on
  first launch of the game, and the crosshair color default.
* Fix the chdir detection in main.go especially to locate the rtp/
  folder inside the macOS app bundle.
2024-05-05 15:59:56 -07:00
e20c694d93 Log game output to disk, update deps for 1.14.0 2024-05-04 19:32:40 -07:00
8595ad0eba Prepare v1.14.0 for release 2024-05-04 18:26:32 -07:00
866e5e7fd8 Deterministic JavaScript intervals + Code Cleanup
* Remove several unused functions in doodad.Drawing (velocity, acceleration,
  grounded, etc.) - uix.Actor is where these are actually managed.
* In the JavaScript API, setTimeout() and setInterval() will translate the
  milliseconds from wallclock time into a fixed number of game ticks to match
  the target frame rate for better deterministic timing.
2024-04-27 00:10:28 -07:00
c4456ac51b Scripting: Bring Self API up to Actor API parity
Updates the Self API to expose more uix.Actor fields:

* Doodad()
* GetBoundingRect()
* HasGravity()
* IsFrozen()
* IsMobile()
* LayerCount()
* ListItems()
* SetGrounded()
* SetWet()
* Velocity() - note: it was Self.GetVelocity() before.

Self.GetVelocity is deprecated and made an alias to Velocity.
2024-04-26 22:34:13 -07:00
21847f5e57 Code cleanup for TouchScreenMode 2024-04-19 23:13:32 -07:00
b8665c8b8d TouchScreenMode Fix
Made some fixes to touchscreen control detection:

* TouchScreenMode is activated on the first SDL2 FingerDown
* TouchScreenMode deactivates after the last finger is removed, and a
  mouse event happens at least 5 ticks later.
2024-04-19 22:42:47 -07:00
5b3121171e Fix touchscreen mode detection
* Touchscreen mode used to be detected based on SDL2 GetNumTouchDevices
  but on a Macbook, the trackpad registers as a touch device - worse,
  GetNumTouchDevices will only start returning 1 the first time some
  devices are touched.
* The result was that on macOS the custom mouse cursor was drawn by
  default, but on the first trackpad touch, would disappear in favor of
  assuming the game is running on a touch screen device (which is not
  the case).
* New method: the render engine has an IsFingerDown boolean which will
  be true as long as at least one finger has registered a FingerDown
  event, but not yet a FingerUp event.
* So as long as one finger is down, the mouse cursor can disappear and
  then it comes back on release. This isn't perfectly ideal for pure
  touch devices (ideally the cursor remains hidden until a mouse
  movement without touch occurs).
2024-04-19 22:01:33 -07:00
f2a20808ea Fix bootstrap.py script 2024-04-18 23:07:25 -07:00
9e90ea4c6c Update Go dependencies 2024-04-18 22:50:18 -07:00
3cdd56424a Merge pull request 'WIP Doodle++' (#93) from dpp into master
Reviewed-on: #93
2024-04-19 05:49:40 +00:00
33dc17bb19 Doodle++ Code Cleanup 2024-04-18 22:49:12 -07:00
a79601f983 D++ Default Author and Embedded Doodads Error
* Update native.DefaultAuthor to get the name registered from the user's JWT
  license in a way that avoids cyclic dependency errors.
* When plus_dpp.go#GetRegistration succeeds, it updates DefaultAuthor to the
  registered name. The main.go now gets and prints the registered owner to
  ensure this is populated on startup.
* Return correct ErrRegisteredFeature error when the FOSS version fails
  to load embedded doodads.
2024-04-18 22:31:11 -07:00
a06787411d Resolve circular import errors for Doodle++ plugin
* pkg/plus/dpp is the main plugin bridge, and defines nothing but an interface
  that defines the Doodle++ surface area (referring to internal game types such
  as doodad.Doodad or level.Level), but not their implementations.
  * dpp.Driver (an interface) is the main API that other parts of the game will
    call, for example "dpp.Driver.IsLevelSigned()"
  * plus_dpp.go and plus_foss.go provide the dpp.Driver implementation for their
    build; with plus_dpp.go generally forwarding function calls directly to the
    proprietary dpp package and plus_foss.go generally returning false/errors.
  * The bootstrap package simply assigns the above stub function to dpp.Driver
* pkg/plus/bootstrap is a package directly imported by main (in the doodle and
  doodad programs) and it works around circular dependency issues: this package
  simply assigns dpp.Driver to the DPP or FOSS version.

Miscellaneous fixes:

* File->Open in the editor and PlayScene will use the new Open Level window
  instead of loading the legacy GotoLoadMenu scene.
* Deprecated legacy scenes: d.GotoLoadMenu() and d.GotoPlayMenu().
* The doodle-admin program depends on the private dpp package, so can not be
  compiled in FOSS mode.
2024-04-18 22:12:56 -07:00
7eb7f6148c WIP Doodle++ 2024-04-18 20:23:07 -07:00
f4ef0f8d8f Fix doodad properties button hitbox 2024-02-11 17:00:19 -08:00
6def8f7625 Walk up slopes smoothly, texture freeing improvement
* Fix collision detection to allow actors to walk up slopes smoothly, without
  losing any horizontal velocity.
* Fix scrolling a level canvas so that chunks near the right or bottom edge
  of the viewpoint were getting culled prematurely.
* Centralize JavaScript exception catching logic to attach Go and JS stack
  traces where possible to be more useful for debugging.
* Performance: flush all SDL2 textures from memory between scene transitions
  in the app. Also add a `flush-textures` dev console command to flush the
  textures at any time - they all should regenerate if still needed based on
  underlying go.Images which can be garbage collected.
2024-02-07 22:14:48 -08:00
85523d8311 Coyote time 2024-02-06 20:56:07 -08:00
8216e5863b Tweak gravity and player physics 2024-02-06 19:04:47 -08:00
6fc5900131 Update Go dependencies 2023-12-21 21:09:25 -08:00
bb28b990e6 Winres config 2023-12-21 20:17:49 -08:00
1a9706c09f Level Thumbnails on Story Mode Select
* Rework the Story Mode UI to display level thumbnails.
  * Responsive UI: defaults to wide screen mode and shows 3 levels horizontally
    but on narrow/mobile display, shows 2 levels per page in portrait.
  * Add "Tiny" screenshot size (224x126) to fit the Story Mode UI.
  * Make the pager buttons bigger and more touchable.
* Maximize the game window on startup unless the -w option with a specific
  window resolution is provided.
2023-12-09 14:59:31 -08:00
9cce93f431 Dust off WASM build support 2023-12-08 21:52:34 -08:00
da83231559 Level Screenshots and Thumbnails
Adds some support for "less giant" level screenshots.

* In the Editor, the Level->Take Screenshot menu will render a cropped screen
  shot of just the level viewport on screen. Note: it is not an SDL2 screen
  copy but generated from scratch from the level data.
* In levels themselves, screenshots can be stored inside the level data in
  three different sizes: large (1280x720), medium and small (each a halved
  size of the previous).
* The first screenshot is created when the level is saved, starting from
  wherever the scroll position in the editor is at, and recording the 720p
  view of the level from there.
* The level screenshot can be previewed and updated in the Level Properties
  window of the editor: so you can scroll the editor to just the right position
  and take a good screenshot to represent your level.
* In the future: these embedded level screenshots will be displayed on the
  Story Mode and other screens to see a preview of each level.

Other tweaks:

* When taking a Giant Screenshot: a confirm modal will warn the player that
  it may take a while. And during the screenshot, show the new Wait Modal to
  block player interaction until the screenshot has finished.
2023-12-08 19:48:02 -08:00
481638bea6 PlaySound: Support OGG fallback over MP3 2023-12-02 14:15:41 -08:00
282229ba80 Prepare v1.13.2 for release 2023-12-02 12:46:17 -08:00
ffb9068fb6 Unit test fixes and code cleanup 2023-12-02 12:33:14 -08:00
79996ccd34 ListBoxes Overhaul
* Overhaul the clunky old alpha Edit Level/Doodad menu with a modernized
  version featuring the new ListBox widget.
* The new level loader is a Window that can be spawned from anywhere instead
  of on a dedicated MenuScene.

Updates to doodad scripts:

* Actor.IsOnScreen() checks whether an actor's visual sprite box is on-screen
  in the level viewport. `Self.IsOnScreen()` will check for the current actor.

Other changes

* PlaySound() to deduplicate the same sound effect from playing at once.
2023-04-08 21:26:08 -07:00
cf1bc81f25 Update savegame format, Allow out-of-bounds camera
Updates the savegame.json file format:

* Levels now have a UUID value assigned at first save.
* The savegame.json will now track level completion/score based on UUID,
making it robust to filename changes in either levels or levelpacks.
* The savegame file is auto-migrated on startup - for any levels not
found or have no UUID, no change is made, it's backwards compatible.
* Level Properties window adds an "Advanced" tab to show/re-roll UUID.

New JavaScript API for doodad scripts:

* `Actors.CameraFollowPlayer()` tells the camera to return focus to the
  player character. Useful for "cutscene" doodads that freeze the player,
  call `Self.CameraFollowMe()` and do a thing before unfreezing and sending the
  camera back to the player. (Or it will follow them at their next directional
  input control).
* `Self.MoveBy(Point(x, y int))` to move the current actor a bit.

New option for the `doodad` command-line tool:

* `doodad resave <.level or .doodad>` will load and re-save a drawing, to
  migrate it to the newest file format versions.

Small tweaks:

* On bounded levels, allow the camera to still follow the player if the player
  finds themselves WELL far out of bounds (40 pixels margin). So on bounded
  levels you can create "interior rooms" out-of-bounds to Warp Door into.
* New wallpaper: "Atmosphere" has a black starscape pattern that fades into a
  solid blue atmosphere.
* Camera strictly follows the player the first 20 ticks, not 60 of level start
* If player is frozen, directional inputs do not take the camera focus back.
2023-03-07 21:55:10 -08:00
d397584323 Update changelog 2023-02-18 17:50:08 -08:00
82884c79ae Signed Levels and Levelpacks
Add the ability for the free version of the game to allow loading levels that
use embedded custom doodads if those levels are signed.

* Uses the same signing keys as the JWT token for license registrations.
* Levels and Levelpacks can both be signed. So individual levels with embedded
  doodads can work in free versions of the game.
* Levelpacks now support embedded doodads properly: the individual levels in
  the pack don't need to embed a custom doodad, but if the doodad exists in
  the levelpack's doodads/ folder it will load from there instead - for full
  versions of the game OR when the levelpack is signed.

Signatures are computed by getting a listing of embedded assets inside the
zipfile (the assets/ folder in levels, and the doodads/ + levels/ folders
in levelpacks). Thus for individual signed levels, the level geometry and
metadata may be changed without breaking the signature but if custom doodads
are changed the signature will break.

The doodle-admin command adds subcommands to `sign-level` and `verify-level`
to manage signatures on levels and levelpacks.

When using the `doodad levelpack create` command, any custom doodads the
levels mention that are found in your profile directory get embedded into
the zipfile by default (with --doodads custom).
2023-02-18 17:37:54 -08:00
856de848c9 Add cheat code to send power to all actors 2023-02-18 14:21:07 -08:00
03cd1d4ca0 Binary format for chunks in zipfiles 2023-02-18 12:45:36 -08:00
0d8933513e Merge pull request 'Chunker size to uint8 and Rectangular Doodads' (#84) from file-format-optimization into master
Reviewed-on: #84
2023-02-18 05:49:48 +00:00
1e37509421 Update README and fix perfect run icon display 2023-02-17 21:49:19 -08:00
31097881ff Finalize Non-square Doodads
* Fix display bug with rectangular doodads scrolling off screen.
* The default Author of new files will be your registration name, if available
  before using your $USER name.
2023-02-17 21:09:11 -08:00
ddcad27485 WIP: Chunker size to uint8 and Rectangular Doodads
Convert the Chunker size to a uint8 so chunk sizes are limited to 255px. This
means that inside of a chunk, uint8's can track the relative pixel coordinates
and result in a great memory savings since all of these uint8's are currently
64-bits wide apiece.

WIP on rectangular shaped doodads:
* You can create such a doodad in the editor and draw it normally.
* It doesn't draw the right size when dragged into your level however:
  - In uix.Actor.Size() it gets a rect of the doodad's square Chunker size,
    instead of getting the proper doodad.Size rect.
  - If you give it the doodad.Size rect, it draws the Canvas size correctly
    instead of a square - the full drawing appears and in gameplay its hitbox
    (assuming the same large rectangle size) works correctly in-game.
  - But, the doodad has scrolling issues when it gets to the top or left edge
    of the screen! This old gnarly bug has come back. For some reason square
    canvas doodads draw correctly but rectangular ones have the drawing scroll
    just a bit - how far it scrolls is proportional to how big the doodad is,
    with the Start Flag only scrolling a few pixels before it stops.
2023-02-16 21:47:18 -08:00
a10a09a818 Cheats Menu UI
* Added a Cheats Menu UI accessible from the Settings window's "Experimental"
  tab and from there you can enable the Cheats Menu from the "Help" screen of
  the gameplay mode.
* Commonly used cheats all have corresponding buttons to click on, especially
  helpful for touchscreen devices like the Pinephone where keyboard input
  doesn't always work reliably.
* The buttons in the Cheats Menu just automate entry of the cheat commands.
* `boolProp` command has a new `flip` option to toggle their value (e.g.
  `boolProp show-hidden-doodads flip`)
2023-01-02 12:36:12 -08:00
06dd30893c Editor: Allow using doodad settings buttons in Pan Tool 2022-12-08 20:03:53 -08:00
cbc8682406 Dockerfile, AppImage Release
* Add a Dockerfile to this repo for self-contained easy releases.
  Run it from an x86_64 Linux host and it will produce 64-bit and
  32-bit Linux (rpm, deb, AppImage, tar.gz) and Windows releases.
* The `make appimage` command is more self-sufficient: it will
  download the appimagetool-x86_64.AppImage program for your $ARCH
  for an easy no-dependencies run after you have run `make dist`
2022-12-08 19:15:48 -08:00
56c03dda45 Unpin goja and fix callback registry functions 2022-10-10 19:14:38 -07:00
48d1f2c3b7 Pin github.com/dop251/goja v0.0.0-20220501172647-e1eca0b61fa9
The newer goja caused problems calling RunCollide or RunKeypress on
doodad scripts - resulting in a broken player character and no collision
events running on doodad scripts. Investigate later.
2022-10-10 13:43:41 -07:00
e330a7b6bb Update dependencies for v0.13.1 2022-10-10 13:28:04 -07:00
2dd6b5e34b Update default level palettes for new pixel attributes
* Default palette: adds "semisolid"
* Colored Pencil: adds "planks" (semisolid) and "ice" (slippery)
* Neon Bright: make "electric" semisolid and add "ice blue"
* Blueprint: make "electric" semisolid and add "ice" (slippery)
2022-10-10 11:17:11 -07:00
8b5dab6d6f Slippery Pixels + Update Changelog for 0.13.1 2022-10-10 10:52:28 -07:00
ecaa8c6cef SemiSolid Pixels + Icons
* Add new pixel attributes: SemiSolid and Slippery (the latter is WIP)
* SemiSolid pixels are only solid below the player character. You can walk on
  them and up and down SemiSolid slopes, but can freely pass through from the
  sides or jump through from below.
* Update the Palette Editor UI to replace the Attributes buttons: instead of
  text labels they now have smaller icons (w/ tooltips) for the Solid,
  SemiSolid, Fire, Water and Slippery attributes.
* Bugfix in Palette Editor: use cropped (24x24) images for the Tex buttons so
  that the large Bubbles texture stays within its designated space!
* uix.Actor.SetGrounded() to also set the Y velocity to zero when an actor
  becomes grounded. This fixes a minor bug where the player's Y velocity (due
  to gravity) was not updated while they were grounded, which may eventually
  become useful to allow them to jump down thru a SemiSolid floor. Warp Doors
  needed a fix to work around the bug, to set the player's Grounded(false) or
  else they would hover a few pixels above the ground at their destination,
  since Grounded status paused gravity calculations.
2022-10-09 21:39:43 -07:00
701073cecc Doodad/Actor Runtime Options
* Add "Options" support for Doodads: these allow for individual Actor instances
  on your level to customize properties about the doodad. They're like "Tags"
  except the player can customize them on a per-actor basis.
* Doodad Editor: you can specify the Options in the Doodad Properties window.
* Level Editor: when the Actor Tool is selected, on mouse-over of an actor,
  clicking on the gear icon will open a new "Actor Properties" window which
  shows metadata (title, author, ID, position) and an Options tab to configure
  the actor's options.

Updates to the scripting API:

* Self.Options() returns a list of option names defined on the Doodad.
* Self.GetOption(name) returns the value for the named option, or nil if
  neither the actor nor its doodad have the option defined. The return type
  will be correctly a string, boolean or integer type.

Updates to the doodad command-line tool:

* `doodad show` will print the Options on a .doodad file and, when showing a
  .level file with --actors, prints any customized Options with the actors.
* `doodad edit-doodad` adds a --option parameter to define options.

Options added to the game's built-in doodads:

* Warp Doors: "locked (exit only)" will make it so the door can not be opened
  by the player, giving the "locked" message (as if it had no linked door),
  but the player may still exit from the door if sent by another warp door.
* Electric Door & Electric Trapdoor: "opened" can make the door be opened by
  default when the level begins instead of closed. A switch or a button that
  removes power will close the door as normal.
* Colored Doors & Small Key Door: "unlocked" will make the door unlocked at
  level start, not requiring a key to open it.
* Colored Keys & Small Key: "has gravity" will make the key subject to gravity
  and set its Mobile flag so that if it falls onto a button, it will activate.
* Gemstones: they had gravity by default; you can now uncheck "has gravity" to
  remove their Gravity and IsMobile status.
* Gemstone Totems: "has gemstone" will set the totem to its unlocked status by
  default with the gemstone inserted. No power signal will be emitted; it is
  cosmetic only.
* Fire Region: "name" can let you set a name for the fire region similarly to
  names for fire pixels: "Watch out for ${name}!"
* Invisible Warp Door: "locked (exit only)" added as well.
2022-10-09 17:41:24 -07:00
7d15651ff6 "Look At Me" for Doodad Scripts
* New script API method: Self.CameraFollowMe() to draw camera focus toward
  your doodad (it sets the Canvas.FollowActor target.)
* The camera will go back to following the player on any action inputs
  (arrow keys, jump, use, etc.); if the player is constantly on the move
  the camera stays on him even if another actor is trying to take the focus.
* The first few ticks of Play Mode the player character is always followed,
  to allow for Anvils to settle into place without taking the focus.
* Canvas FollowActor: if the actor is 4 times the max scroll speed away,
  allow scrolling in greater leaps of 4 times the max scroll speed.

New and Changed Doodads

* Anvils will take the camera focus while they are falling.
* New doodad: "Look At Me" - a 'camera region' technical doodad. Link it to
  any power source such as a Button - when this doodad receives power it will
  take the camera focus for a few frames. Use it to highlight a door that
  opened far off screen by linking the Button to both an Electric Door and
  a "Look At Me" near the door.
2022-09-24 23:54:51 -07:00
653184b8f8 JavaScript Exception Catcher UI
* Add an exception catcher that pops open a UI window showing errors that
  occur in doodad scripts during gameplay.
* Shows a preview of the header of the error (character wrapped) with a
  Copy button to copy the full raw text to clipboard for inspection.
* Buttons to dismiss the modal once or stop any further errors from
  opening during this gameplay session (until next restart).
* Add developer shell commands to test the exception catcher:
  - 'throw <message>' to throw a custom message.
  - 'throw2' to stress test a "long" message.
  - 'throw3' to throw a realistic message copied from an actual error.
* Scripting engine: console.log() and friends will now insert the script
  VM's name in front of its messages (the filename + actor ID).
2022-09-24 21:58:01 -07:00
cd103f06c7 Touchscreen fixes 2022-09-24 19:05:42 -07:00
73421d27f2 Wait Modal
* Add modal.Wait() that creates a global progress bar modal which is not
  dismissable by the user; the caller must Dismiss() the modal
  themselves when ready.
* It will be useful in the future in case e.g. saving a Level needs to
  take a while to rebalance chunks and the modal prevents ALL
  interaction with the game so the user can't further modify the level
  while it's busy refactoring itself.
* Cheat code: "test wait screen" to show the Wait modal for 10 seconds.
2022-09-24 18:39:02 -07:00
546b5705db Detect touchscreen and tweak some behaviors 2022-09-24 17:45:54 -07:00
6631d8d11c Open Source Release 2022-09-24 16:17:30 -07:00
6404024d12 Update bootstrap to pull doodad sources 2022-09-24 15:39:54 -07:00
83f0a2fb49 Split doodads into new repository 2022-09-24 15:35:47 -07:00
ec0b5ba6ca Rename Go module 2022-09-24 15:17:25 -07:00
3e16051724 Update Linux launcher for mobile compatibility 2022-07-04 10:22:15 -07:00
53c72f18d1 Bugfix: Crusher to fall indefinitely w/o a time limit 2022-05-08 12:09:09 -07:00
d7f247e4cc Fix doodad tool --tag property 2022-05-08 10:58:53 -07:00
a28644d253 No appimage builds for now 2022-05-07 20:46:03 -07:00
46ab5c9de0 Remove replace directives in go.mod 2022-05-07 20:29:31 -07:00
0a18cd4227 Prepare v0.13.0 for release 2022-05-07 20:23:25 -07:00
34c45095b5 Idle animations for Boy 2022-05-07 20:18:44 -07:00
434416d3a4 Spit and polish
* Made the loadscreen useful again (give it work to do async so the game
  doesn't simply freeze during): does a first call to LoadUnloadChunks
  to preload the viewport chunks.
* Hide the mouse cursor when movement keys are pressed.
2022-05-07 18:54:37 -07:00
450c6b3bb2 Spit and polish
* On the failure (but still success) dialog on Survival Mode levels
  (e.g. Azulian Tag): make the default be to retry the level but
  show a "pity" Next Level button below, as the level is marked as
  completed (silver score) and the next one is unlocked.
2022-05-07 17:42:38 -07:00
ffc2c6f69b Performance?: Don't unload chunks so eagerly
Previously: the Chunker tracks with chunks were gotten during the
current game tick and the N-1 and N-2 ticks, and chunks not accessed in
two ticks were freed immediately.

Now: they go into a "garbage collection" pool with a minimum number of
game ticks to free. So if they're needed again, they're saved from the
gc pool. F3 overlay data shows the count of the gc pool.
2022-05-07 17:16:03 -07:00
315c8a81a0 Update Changelog 2022-05-05 22:34:03 -07:00
94d0da78e7 Swimming Physics and Bubble Pattern
Water pixels finally do something other than turn your character blue!

* When the player character is "wet" (touching water pixels, and so appearing in
  a blue mask), water physics apply: gravity is slower, your jump height is
  halved, but you get infinite jumps to swim higher in the water.
* Holding the jump key under water will incur a short delay between jumps, so
  that you don't just fly straight up to the surface. Tap the jump button to
  move up quicker, you can spam it all you want.

Azulians are also able to handle being under water:

* They'll sink to the bottom and keep walking back and forth normally.
* If you are above them and noticed, they'll jump (swim) up towards you,
  aware of the water and it jumps like you do.
* The Blue Azulian has the poorest vertical aggro range so it isn't a
  very good swimmer. The White Azulian is very good at navigating water
  as it can pursue the player from the furthest distance of them all.

Changes to the editor:

* New brush pattern added: bubbles.png
  * It's the default pattern now for the "water" color of all
    of the built-in palettes instead of ink.png
  * A repeating pattern of bubbles carved out showing the
    level wallpaper.
  * The old "Bubbles (circles.png)" is renamed "Circles"
* The last scroll position is saved with the Level file, so when you reload
  the level later it's scrolled at where you left it.
2022-05-05 21:35:32 -07:00
4efa8d00fc Fancy Mouse Cursors
The gamepad mouse cursor has become THE mouse cursor. It is always visible and your
real cursor is hidden, and this way the game can swap out other cursors for certain
scenarios:

* The Pencil Tool in the editor will use a pencil cursor over the level canvas.
* The Flood Tool has a custom Flood cursor so you don't forget it's selected!

Other improvements:

* The Palette buttons in the editor now render using their swatch's pattern
  instead of only using its color.
* If you have an ultra HD monitor and open a Bounded level in the editor which
  is too small to fill your screen, the editor canvas limits its size to fit
  the level (preferable over showing parts of the level you can't actually play
  as it's out of bounds).
* The "brush size" box is only drawn around the cursor when a relevant tool is
  selected (Pencil, Line, Rect, Ellipse, Eraser)
2022-05-04 22:38:26 -07:00
9b75f1b039 Spit and polish
* New built-in wallpaper: "Dotted paper (dark)" is a dark-themed wallpaper.
* New built-in palette: "Neon Bright" with bright colors for dark levels.
* New cheat: "warp whistle" to automatically win the level.
* In case the user has a VERY LARGE screen resolution bigger than the full
  bounds of a Bounded level, the Play Scene will cap the size and center
  the level canvas onto the window. This is preferable to being able to see
  beyond the level's boundaries and hitting an invisible wall in-game.
* Make the titlescreen Lazy Scroll work on unbounded levels. It can't bounce
  off scroll boundaries but it will reverse course if it reaches the level's
  furthest limits.
* Bugfix: characters' white eyes were transparent in-game. Multiple culprits
  from the `doodad convert` tool defaulting the chroma key to white, to the
  SDL2 textures considering white to be transparent. For the latter, the game
  offsets the color by -1 blue.
2022-05-03 21:15:39 -07:00
75fa0c7e56 Stability and Bugfixes
* Editor: Auto-save on a background goroutine so you don't randomly freeze
  the editor up during.
* Fix actor linking issues when you drag and re-place a linked doodad: the
  level was too eagerly calling PruneLinks() whenever a doodad was 'destroyed'
  (such as the one just picked up) breaking half of the link connection.
* Chunk unloader: do not unload a chunk that has been modified (Set or Delete
  called on), keep them in memory until the next ZIP file save to flush them
  out to disk.
* Link Tool: if you clicked an actor and don't want to connect a link, click
  the first actor again to de-select it.

Updates to the `doodad` tool:

* `doodad edit-level --resize <int>` can re-chunk a level to use a different
  chunk size than the default 128. Large chunk sizes 512+ lead to performance
  problems.
2022-05-02 20:35:53 -07:00
fc736abd5f Doodads: Gems, Snake and Crusher
Adds several new doodads to the game and 5 new wallpapers (parchment
paper in blue, green, red, white and yellow).

New doodads:

* Crusher: A purple block-headed mob wearing an iron helmet. It tries
  to crush the player when you get underneath. Its flat helmet can be
  ridden on like an elevator back up.
* Snake: A green stationary mob that always faces toward the player.
  If the player is nearby and jumps, the Snake will jump too and hope
  to catch the player in mid-air.
* Gems and Totems: A new key & lock collectible. Gems have quantity so
  you can collect multiple, and place them into matching Totems. A
  Totem gives off a power signal when its gem is placed and all other
  Totems it is linked to have also been activated. A single Totem may
  link to an Electric Door and require only one gem to open it, or it
  can link to other Totems and they all require gems before the power
  signal is sent out.
2022-05-01 15:18:23 -07:00
ad67e2b42b New Doodad: Blue Bird
* The blue bird follows the same base AI as the red bird (it has a
  target altitude that it tries to maintain, and it will dive at the
  player) but the blue bird flies in a sine wave pattern around its
  target altitude. It also has a longer scan radius to search for the
  player than the red bird.
* The sine wave pattern of the blue bird means you may fly under its
  radar depending how high it is on average.

Cheat codes that replace the player character are refactored to make
it easier to extend, and new cheats have been added:

* super azulian: play as the Red Azulian.
* hyper azulian: play as the White Azulian.
* bluebird: play as the new Bird (blue).
2022-04-30 17:59:55 -07:00
402b5efa7e Zipfiles for Attached Files Too
* The level.FileSystem type has updated to support ZIP files too.
* Legacy levels loaded from gz/json have their old FileSystem as a
  simple map[filename]data and this parses from JSON OK.
* On save to zip, the legacy loaded file data gets exported to ZIP.
* Going forward: newly added or deleted files during runtime are kept in
  the legacy file map until the next save when the filemap is again
  flushed out to ZIP.
* For regular read-access, the FileSystem reads from the ZIP file if the
  data is not in the hot map (legacy file or recently modified
  attachment).
* Bugfix: be sure to Inflate() the Level/Doodad after loading from
  zipfile - it used to be that directly after a save, trying to play the
  level failed because the Level.Actors struct was missing their IDs,
  and similarly recently written chunks would error out (become black
  voids) on levels/doodads so we Inflate() both after save/replacing
  their zip handle.
2022-04-30 12:50:00 -07:00
302506eda9 Cheat: $ d.SetPlayerCharacter("anything.doodad")
Too restricted by the cheat codes to play as certain characters
on-demand? Use the JS shell in the developer console to set any doodad
you want:

    $ d.SetPlayerCharacter("key-blue")
    $ d.SetPlayerCharacter("anvil")
    $ d.SetPlayerCharacter("box.doodad")

The .doodad suffix is optional.

Interesting behaviors when playing as odd doodads:

* Most non-mobile doodads don't collide with each other, so you can pass
  through doors and not activate buttons if you play as a key or a
  trapdoor. Non-mobile doodads also generally have antigravity so you
  can fly freely around the map.
* Non-mobile doodads can not open Warp Doors or interact with the Exit
  Flag. You'll have to change back to a creature such as "boy" or
  "azu-blue" to win the level.
* If you are a key, the Thief can collect you! This removes your player
  doodad from the level and soft locks the game. No worries, another
  call to d.SetPlayerCharacter() will put you back on the map!
* If the doodad name isn't found, you'll play as the built-in fallback
  doodad, which is just a red "X" shape. It has anti-gravity and does
  not generally interact with any doodad (can not push buttons or
  collect keys - but it can pass through doors and other obstacles. Can
  not win the level goal flag, though!)
2022-04-29 21:39:53 -07:00
93623e4e8a Zipfiles as File Format for Levels and Doodads
Especially to further optimize memory for large levels, Levels and
Doodads can now read and write to a ZIP file format on disk with
chunks in external files within the zip.

Existing doodads and levels can still load as normal, and will be
converted into ZIP files on the next save:

* The Chunker.ChunkMap which used to hold ALL chunks in the main json/gz
  file, now becomes the cache of "hot chunks" loaded from ZIP. If there is
  a ZIP file, chunks not accessed recently are flushed from the ChunkMap
  to save on memory.
* During save, the ChunkMap is flushed to ZIP along with any non-loaded
  chunks from a previous zipfile. So legacy levels "just work" when
  saving, and levels loaded FROM Zip will manage their ChunkMap hot
  memory more carefully.

Memory savings observed on "Azulian Tag - Forest.level":

* Before: 1716 MB was loaded from the old level format into RAM along
  with a slow load screen.
* After: only 243 MB memory was used by the game and it loaded with
  a VERY FAST load screen.

Updates to the F3 Debug Overlay:

* "Chunks: 20 in 45 out 20 cached" shows the count of chunks inside the
  viewport (having bitmaps and textures loaded) vs. chunks outside which
  have their textures freed (but data kept), and the number of chunks
  currently hot cached in the ChunkMap.

The `doodad` tool has new commands to "touch" your existing levels
and doodads, to upgrade them to the new format (or you can simply
open and re-save them in-game):

    doodad edit-level --touch ./example.level
    doodad edit-doodad --touch ./example.doodad

The output from that and `doodad show` should say "File format: zipfile"
in the headers section.

To do:

* File attachments should also go in as ZIP files, e.g. wallpapers
2022-04-29 20:34:59 -07:00
2d3f36379c AppImage Support 2022-04-25 21:31:46 -07:00
9cdc7260bb Prepare v0.12.1 for release 2022-04-16 17:50:40 -07:00
c5353df211 LoadUnloadChunk for Memory Optimization
Instead of the loadscreen eager-loading ALL level chunks to Go Images, only
load the chunks within the "LoadingViewport" - which is the on-screen
Viewport plus a margin of chunks off the screen edges.

During gameplay, every few ticks, reevaluate which chunks are inside or
outside the LoadingViewport; for chunks outside, free their SDL2 textures
and free their cached bitmaps to keep overall memory usage down. The
AzulianTag-Forest level now stays under 200 Textures at any given time
and the loadscreen goes faster as it doesn't have to load every chunk's
images up front.

The LoadUnloadChunk feature can be turned on/off with feature flags. If
disabled the old behavior is restored: loadscreen loads all images and
the LoadUnloadChunks function is not run.

Other changes:

* loadscreen: do not free textures in the Hide() function as this runs on
  a different goroutine and may break. The 4 wallpaper textures are OK
  to keep in memory anyway, the loadscreen is reused often!
* Free more leaked textures: on the Inventory frame and when an actor
  calls Self.Destroy()
* Stop leaking goroutines in the PubSub feature of the doodad script
  engine; scripting.Supervisor.Teardown() sends a stop signal to all
  scripts to clean up neatly. Canvas.Destroy() tears down its scripting
  supervisor automatically.
2022-04-10 12:40:25 -07:00
d694fcc7c2 Fix climbing on the right bug + eager-render boolprop
* New boolProp to help debug memory issues: eager-render, set it to
  false and the loadscreen will not eagerload Go images for all the
  level chunks.
* Finally fix the level collision bug where the player could climb walls
  to the right.
2022-04-09 18:21:26 -07:00
6b8c7a1efe Update Go dependencies 2022-04-09 16:01:56 -07:00
db5760ee83 Optimize memory by freeing up SDL2 textures
* Added to the F3 Debug Overlay is a "Texture:" label that counts the number
  of textures currently loaded by the (SDL2) render engine.
* Added Teardown() functions to Level, Doodad and the Chunker they both use
  to free up SDL2 textures for all their cached graphics.
* The Canvas.Destroy() function now cleans up all textures that the Canvas
  is responsible for: calling the Teardown() of the Level or Doodad, calling
  Destroy() on all level actors, and cleaning up Wallpaper textures.
* The Destroy() method of the game's various Scenes will properly Destroy()
  their canvases to clean up when transitioning to another scene. The
  MainScene, MenuScene, EditorScene and PlayScene.
* Fix the sprites package to actually cache the ui.Image widgets. The game
  has very few sprites so no need to free them just yet.

Some tricky places that were leaking textures have been cleaned up:

* Canvas.InstallActors() destroys the canvases of existing actors before it
  reinitializes the list and installs the replacements.
* The DraggableActor when the user is dragging an actor around their level
  cleans up the blueprint masked drag/drop actor before nulling it out.

Misc changes:

* The player character cheats during Play Mode will immediately swap out the
  player character on the current level.
* Properly call the Close() function instead of Hide() to dismiss popup
  windows. The Close() function itself calls Hide() but also triggers
  WindowClose event handlers. The Doodad Dropper subscribes to its close
  event to free textures for all its doodad canvases.
2022-04-09 14:41:24 -07:00
dbd79ad972 Update go.mod 2022-03-27 14:26:06 -07:00
ba373553cb Prepare v0.12.0 for release 2022-03-27 14:23:25 -07:00
38a23f00b2 Reset Timer Doodad + Various Fixes
* Bird is not solid when colliding with other birds.
* If the dev shell is used to run JavaScript during Play Mode, consider
  it cheating (so player can't `$ d.Scene.ResetTimer()` for example)
* On Survival Mode levels, DieByFire immediately opens the End Level
  (silver score) modal rather than respawn from checkpoint, so levels
  don't need checkpoint contraptions to end the level.
* During level loading screens, wait and call doodads' main() function
  until the very end.
2022-03-27 11:51:14 -07:00
af6b8625d6 Flood Tool, Survival Mode for Azulian Tag
New features:
* Flood Tool for the editor. It replaces pixels of one color with another,
  contiguously. Has limits on how far from the original pixel it will color,
  to avoid infinite loops in case the user clicked on wide open void. The
  limit when clicking an existing color is 1200px or only a 600px limit if
  clicking into the void.
* Cheat code: 'master key' to play locked Story Mode levels.

Level GameRules feature added:
* A new tab in the Level Properties dialog
* Difficulty has been moved to this tab
* Survival Mode: for silver high score, longest time alive is better than
  fastest time, for Azulian Tag maps. Gold high score is still based on
  fastest time - find the hidden level exit without dying!

Tweaks to the Azulians' jump heights:
* Blue Azulian:  12 -> 14
* Red Azulian:   14 -> 18
* White Azulian: 16 -> 20

Bugs fixed:
* When editing your Palette to rename a color or add a new color, it wasn't
  possible to draw with that color until the editor was completely unloaded
  and reloaded; this is now fixed.
* Minor bugfix in Difficulty.String() for Peaceful (-1) difficulty to avoid
  a negative array index.
* Try and prevent user giving the same name to multiple swatches on their
  palette. Replacing the whole palette can let duplication through still.
2022-03-26 13:55:06 -07:00
bf706efdc6 Update Changes.md 2022-03-19 12:24:01 -07:00
647124495b Level Difficulty + UI Polish
Added a new level property: Difficulty

* An enum ranging from -1, 0, 1 (Peaceful, Normal, Hard)
* Default difficulty is Normal; pre-existing levels are Normal by
  default per the zero value.

Doodad scripts can read the difficulty via the new global variable
`Level.Difficulty` and some doodads have been updated:

* Azulians: on Peaceful they ignore all player characters, and on Hard
  they are in "hunt mode": infinite aggro radius and they're aggressive
  to all characters.
* Bird: on Peaceful they will not dive and attack any player character.

Other spit and polish:

* New Level/Level Properties UI reworked into a magicform.
* New "PromptPre(question, answer, func)" function for prompting the
  user with the developer shell, but pre-filling in an answer for them
  to either post or edit.
* magicform has a PromptUser field option for simple Text/Int fields
  which present as buttons, so magicform can prompt and update the
  variable itself.
* Don't show the _autosave.doodad in the Doodad Dropper window.
2022-03-06 22:20:53 -08:00
661c5f4365 Loadscreen Update & Window Resize Fixes
* Loadscreen: put the progress bar between the Title and Subtitle so it
  looks good even on mobile landscape orientation (narrow height)
* Bugfixes around window OnResize events: the loadscreen handles
  resizing correctly now and the Level Editor (or w/e) will also be the
  right size if you resized the window during loading.
2022-03-06 12:07:59 -08:00
ba4fbf55ef Update dependencies 2022-03-06 11:37:08 -08:00
44122d4130 Spit and polish
UI improvements specifically for mobile (running the game with the
`-w mobile` or `-w landscape` options) screen sizes.

* Rework the Settings window to be mobile friendly to landscape
  oriented screens (`doodle -w landscape`) and migrate Options tab
  to magicform.
* The toolbar in the Editor will be a single column of buttons
  on small screens, such as `-w mobile` (375x812) portrait mode
  smartphone. On larger screens the toolbar shows in two columns
  of buttons.
* Fix tooltips not drawing on top.
* Centralize the hard-coded references to specific font filenames
* Add cheat code: `test load screen` to bring a sample loading screen up
  for a few seconds. It needs improvement on `-w landscape`
2022-03-05 22:44:54 -08:00
77297fd60d Text Tool and Pan Tool
Two new tools added to the Level Editor:

* Pan Tool: left-click to scroll the level around safely.
* Text Tool: write text onto your level.

Features of the Text Tool:

* Can choose from the game's built-in fonts, size and enter the message
  you want to write.
* The mouse cursor previews the text when hovered over the level.
* Click to "stamp" the text onto your level. The currently selected
  color swatch will be used to color the text in.
* Adds two new fonts: Azulian.ttf and Rive.ttf that can be selected in
  the Text Tool.

Some implementation notes:

* Added package native/engine_sdl.go that handles the lower-level
  SDL2_TTF logic to rasterize the text into a black&white image.
* WASM not supported yet (if the game even still built for WASM);
  native/engine_wasm.go stubs out the TextToImage() call with a "not
  supported" error just in case.

Other changes:

* New Toolbar icons: they are 24x24 instead of 32x32 to make more room
  for more tools.
* The toolbar now shows two buttons per row for a more densely packed
  layout. For very narrow screen widths (< 600px) the default Vertical
  Toolbar layout will use one-button-per-row to not eat too much screen
  real estate.
* In the Horizontal Toolbars layout there are 2 buttons per column.
2022-03-05 15:34:20 -08:00
bc15155b68 Update dependencies 2022-02-21 14:18:36 -08:00
0b2e04b336 Update changelog for v0.11.0 2022-02-21 13:26:25 -08:00
962098d4e7 v0.11.0 last minute tweaks
* When playing as the Bird, the dive attack is able to destroy other
  mobile doodads such as Azulians and Thieves.
* The Box has been made invulnerable so it can't be destroyed by Anvils
  or player-controlled Birds.
* Bugfixes with pop-up modals:
  * The quit game confirm modal doesn't appear if another modal is
    already active on screen.
  * The Escape key can dismiss Alert and Confirm modals.
* Add "Level" menu items to Play Mode to restart the level or retry from
  the last checkpoint (in case of softlocks, etc.)
2022-02-21 13:09:51 -08:00
40cb9f15cb Prepare v0.11.0 for release (+ fixes)
* The title screen now loads the default maps from a LevelPack. The game
  no longer ships with the Tutorial levels in the "levels" folder as
  default; they are in the LevelPack so the "Edit Drawing" screen begins
  as a blank slate for only user levels.
* Add the Zoo level to the Tutorial levelpack
* Bugfixes around changing the player character to work around clipping
  issues if the character has changed height drastically.
2022-02-20 17:48:07 -08:00
293ac668e7 Azulian: Don't follow boring players
If the Azulians aren't hostile to the player character (e.g. you are
playing as a Thief or Azulian or you are invulnerable because you're the
Anvil), the Azulians won't aggro and pathfind to you either.
2022-02-20 12:19:56 -08:00
1205dc2cd3 Invulnerable Anvil and other fixes
* Add methods `Invulnerable() bool` and `SetInvulnerable(bool)` to the
  Actor API accessible in JavaScript (e.g. `Self.SetInvulnerable(true)`)
* The Anvil is invulnerable - when played as, it can crush other mobs by
  jumping on them but is not defeated by those mobs at the same time.
* Anvils don't destroy invulnerable mobs, such as other Anvils.
* Bugfix: the Electric Door is considered to be opened from the first
  frame of animation when the door begins opening, and remains opened
  until the final frame of animation when it is closing.
* New cheat code: `megaton weight` to play as the Anvil by default.
2022-02-20 11:48:36 -08:00
0fc046250e Window Focus Bugfixes
* Fix the Doodad Dropper and Registration windows not stealing the focus
  when they are opened via menu bars.
* Bugfixes in gamepad support: stop at the first controller found,
  Draw() to handle controllers going away and hide the mouse cursor
2022-02-19 20:20:58 -08:00
4de0126b19 Game Controller Support
Adds support for Xbox and Nintendo style game controllers. The gamepad
controls are documented on the README and in the game's Settings window.

The buttons are not customizable yet, except that the player can choose
between two button styles:

* X Style (default): "A" button is on the bottom and "B" on the right.
* N Style: swaps the A/B and the X/Y buttons to use a Nintendo-style
  layout instead of an Xbox-style.
2022-02-19 18:31:22 -08:00
626fd53a84 Checkpoint Flag can Re-assign Player Character
Link a Doodad to a Checkpoint Flag (like you would a Start Flag) and
crossing the flag will replace the player with that doodad. Multiple
checkpoint flags like this can toggle you between characters.

* Azulians are now friendly to player characters who have the word
  "Azulian" in their title.
* Improve Bird as the playable character:
  * Dive animation if the player flies diagonally downwards
  * Animation loop while hovering in the air instead of pausing
* Checkpoint flags don't spam each other on PubSub so much which could
  sometimes lead to deadlocks!

SetPlayerCharacter added to the JavaScript API. The Checkpoint Flag
(not the region) can link to a doodad and replace the player character
with that linked doodad when you activate the checkpoint:

    Actors.SetPlayerCharacter(filename string): like "boy.doodad"

Add various panic catchers to make JavaScript safer and log issues
to console.
2022-01-18 21:24:36 -08:00
44aba8f1b4 White Azulian, Respawn invincibility timer
* Respawning from a checkpoint grants 3 seconds of immunity in case
  enemies are spawn camping.
* Add the white Azulian as an even faster and harder enemy than the red
  Azulian: twice as fast, jumps higher, and can detect the player from
  further away.
2022-01-18 18:32:15 -08:00
3f7e384633 Invincibility Cheat
Add cheat `god mode` that toggles invincibility. Fire pixels and hostile
mobs can't fail the level for you.
2022-01-17 22:02:27 -08:00
9201475060 Update Doodad JS API + Hostile mobs
New functions are available on the JavaScript API for doodads:

* Actors.At(Point) []*Actor: returns actors intersecting a point
* Actors.FindPlayer() *Actor: returns the nearest player character
* Actors.New(filename string): create a new actor (NOT TESTED YET!)
* Self.Grounded() bool: query the grounded status of current actor

With this the game's built-in doodads have been revised:

* Bird: will now scan 240 pixels diagonally searching for the player
  character and will dive if seen. The Bird is dangerous while
  diving. It will return to its original altitude once it touches
  the ground.
* Azulians: the Azulians are now dangerous to player characters but
  not to the Thief. Azulians will begin to follow the player when
  they are within the aggro range and will hop if the player is
  above them to try and overcome obstacles.
  * Blue Azulian: aggro is (250, 100) jump speed 12 movement 2
  * Red Azulian: aggro is (250, 200) jump speed 14 movement 4
2022-01-17 21:28:05 -08:00
1cc6eee5c8 Refactor Level Publishing + MagicForm
* magicform is a helper package that may eventually be part of the go/ui
  library, for easily creating structured form layouts.
* The Level Publisher UI is the first to utilize magicform.

Refactor how level publishing works:

* Level data now stores SaveDoodads and SaveBuiltins (bools) and when
  the level editor saves the file, it will attach custom and/or builtin
  doodads just before save.
* Move the menu item from the File menu to Level->Publish
* The Publisher UI just shows the checkboxes to toggle the level
  settings and a convenient Save button along with descriptive text.
* Free versions get the "Register" window popping up if they click the
  Save Now button from within the publisher window.

Note: free versions can still toggle the booleans on/off but their game
will not attach any new doodads on save.

* Free games which open a level w/ embedded doodads will get a pop-up
  warning that the doodads aren't available.
* If they DON'T turn off the SaveDoodads option, they can still edit and
  save the level and keep the existing doodads attached.
* If they UNCHECK the option and save, all attached doodads are removed
  from the level.
2022-01-17 18:51:11 -08:00
5ca87c752f Sort level actors deterministically by their (time sensitive) ID 2022-01-16 20:20:48 -08:00
4d08bf1d85 Switch JavaScript engine to goja
* Switch from otto to goja for JavaScript engine.
* goja supports many ES6 syntax features like arrow functions,
  const/let, for-of with more coming soon.
* Same great features as otto, more modern environment for doodads!
2022-01-16 20:09:27 -08:00
d67c1cfcf1 Send User-Agent of version/os/arch on update check 2022-01-16 18:33:27 -08:00
05b97df846 Prepare v0.10.1 for release 2022-01-09 15:03:02 -08:00
9e4f34864d Remove MsgPack, Fix doodad display on top/left edges
* Clean up unused msgpack code for levels and doodads
* Fix the cosmetic bug where actors in your level would display wrongly
  when scrolling off the top/left edges of the screen: they used to
  anchor at their own 0,0 coordinate and crop their width/height leading
  to a 'scrolling' effect that didn't happen on the right/bottom edges.
2022-01-09 13:16:29 -08:00
cbd7816fdf Easter Egg: RiveScript Chatbot
The Default handler of the developer command shell now calls out to
RiveScript to match the user's message to a friendly reply. If
RiveScript returns NoReplyMatched then give the "command not found"
error.
2022-01-08 19:21:08 -08:00
48e18da511 Centralize cheats, detect cheated player character
* If the player runs the PlayAsBird cheat they shouldn't be able to win
  a high score on a level, so at level startup it detects whether the
  DefaultPlayerCharacterDoodad has changed from default on a level that
  doesn't use the Start Flag to set a specific doodad - and immediately
  marks the session as cheated
2022-01-08 18:27:37 -08:00
24c47d1e3f Fix build scripts for real 2022-01-08 17:18:44 -08:00
51e585b2f8 Fix build scripts around architecture info 2022-01-08 17:07:24 -08:00
96314a852d Update go.mod dependencies to latest 2022-01-08 17:06:19 -08:00
3130d8ca94 Undo replace directives in go.mod 2022-01-03 20:33:41 -08:00
a6297f6cb6 Make build scripts more architecture-aware 2022-01-03 20:23:49 -08:00
9a51ac39f9 Spit and polish
* New doodad: Invisible Warp Door
* All warp doors require the player to be grounded (if affected by
  gravity) to open them. No jumping or falling thru and opening
  a warp door mid-air!
* Title Screen now randomly selects from a couple of levels.
* Title Screen: if it fails to load a level it sets up a basic
  blank level with a wallpaper instead.
* New developer shell command: titlescreen <level>
  Opens the MainScene with a custom user level as the background.
* Add Auto-save to the Editor to save your drawing every 5 minutes
* Add a MenuBar to the Play Scene for easier navigation to other
  features of the game.
* Doodad JS API: time.Since() now available.
2022-01-02 22:36:32 -08:00
672ee9641a Savegame and High Scores
* Adds pkg/savegame to store user progress thru Level Packs.
* The savegame.json is mildly tamper resistant by including a checksum
  along with the JSON body.
* The checksum combines the JSON string + an app secret (in savegame.go)
  + user specific entropy (stored in their settings.json). If the user
  modifies their save file and the checksum becomes invalid the game
  will not load the save file, acting like it didn't exist, resetting
  all their high scores.

Updates to the Story Mode window:

* On the LevelPacks list: shows e.g. "[completed 0 of 3 levels]" showing
  a user's progress thru the level pack.
* Below the levels on the Detail screen:
  * Shows an indicator whether the level is completed or not.
  * Shows high scores (fastest times beating the level)
  * Shows a padlock icon if levels are locked and the player hasn't
    reached them yet. Pops up an Alert modal if a locked level is
    clicked on.

Scoring is based around your fastest time elapsed to finish the level.

* Perfect Time (gold coin): player has not died during the level.
* Best Time (silver coin): player has continued from a checkpoint.

In-game an elapsed timer is shown in the top left corner along with the
gold or silver coin indicating if your run has been Perfect.

If the user enters any Cheat Codes during gameplay they are not eligible
to win a high score, but the level will still be marked as completed.
The icon next to the in-game timer disappears when a cheat code has been
entered.
2022-01-02 16:28:43 -08:00
690fdedb91 Add the ui.ColorPicker 2022-01-01 18:48:34 -08:00
fa5f303dad Bugfix: embedded levelpacks from bindata 2021-12-30 18:39:11 -08:00
3881457300 Prepare v0.10.0 for release 2021-12-30 17:57:13 -08:00
d16a8657aa Window Icon, UI Polish
* SDL2 builds of the game now set their app window icon.
* Create/Edit Level window is updated to show a tabbed UI to create a
  new Level or a new Doodad. The dedicated main menu button to create a
  new doodad (which immediately prompted for its size) is replaced by
  this new tab's UI.
* Edit Drawing/Play Level window is more responsive to smaller screen
  sizes by drawing fewer columns of filenames.
* Bugfix: the Alert and Confirm modals always re-center themselves on
  screen, especially to adapt between Portrait or Landscape mode on a
  mobile device.
2021-12-30 16:31:45 -08:00
37377cdcc1 Update Changelog 2021-12-26 21:07:52 -08:00
6d3ffcd98c Finalize basic functionality for Level Packs
* The "Story Mode" button on the MainScene opens the levelpacks window.
* Levelpacks from all places are shown (built-in and user files), basic
  level picker works.
* When playing a level out of a levelpack: the PlayScene gets the file
  data from the zipfile and plays it OK.
* When a levelpack level is solved, the "Next Level" button appears on
  the success modal and hitting Return will advance to the next level in
  the pack. The final level doesn't show this button.
* The user can edit levelpack levels! Clicking the "Edit" button on the
  Play Mode moves the loaded level over to the EditScene and the user
  could save it to disk or edit/playtest it perfectly OK! The link to
  the levelpack is lost upon opening in the editor, so the "Next Level"
  victory button doesn't appear.
2021-12-26 20:48:29 -08:00
678326540b WIP LevelPack UI + Landscape Mode Title Screen
The title screen is now responsive to landscape mode. If the window is
not tall enough to show all the menu buttons (~600px) it will switch to
a horizontal layout with the title on the left and buttons on the right.

WIP "Story Mode" button that brings up a Level Packs selection window.
2021-12-23 21:11:45 -08:00
a75b7208ca Doodad Tool: Levelpacks
Adds `doodad levelpack create` and `doodad levelpack show` commands to
the CLI tool to create levelpacks.

A levelpack is a ZIP file containing a descriptive index.json and
directories for levels and doodads.
2021-12-23 19:15:32 -08:00
ddf0074099 Condensed Palette, Bird AI Update
* The Red Bird now records its original altitude on the level and will
  try and return there should it accidentally climb up or down a wall.
  Sometimes goes into a wavy pattern surrounding its original altitude.
* Editor UI: in the default (vertical) toolbar, the Palette now has a
  two column view to show more color choices on screen at once.
* User setting added: hide the touch control hints.
2021-10-12 20:49:48 -07:00
3a9cc83e78 Bugfix: Undo/Redo works for the Doodad Editor
Changed dependencies around so the undo/redo feature works on doodads as
well as levels.
2021-10-11 16:10:04 -07:00
0ec259b171 Crosshair Option + Doodad Editor crash fix
* The level scroll logic was getting a null pointer crash if you open a
  doodad rather than a level file.
* Add a crosshair option to the level editor, configurable in the Game
  Settings window.
2021-10-11 15:57:33 -07:00
8ca411a0ae Prepare for release v0.9.0 2021-10-09 21:29:14 -07:00
a112c19d76 Few small tweaks 2021-10-09 21:22:50 -07:00
1a8a5eb94b Polish and bugfixes
- Fix a memory sharing bug in the Giant Screenshot feature.
- Main Menu to eagerload chunks in the background to make scrolling less
  jittery. No time for a loadscreen!
- Extra script debugging: names/IDs of doodads are shown when they send
  messages to one another.
- Level Properties: you can edit the Bounded max width/height values for
  the level.

Doodad changes:

- Buttons: fix a timing bug and keep better track of who is stepping on it,
  only popping up when all colliders have left. The effect: they pop up
  immediately (not after 200ms) and are more reliable.
- Keys: zero-qty keys will no longer put themselves into the inventory of
  characters who already have one except for the player character. So
  the Thief will not steal them if she already has the key.

Added to the JavaScript API:

* time.Hour, time.Minute, time.Second, time.Millisecond, time.Microsecond
2021-10-09 20:45:38 -07:00
feea703d0c Update changelog for upcoming 0.9.0 2021-10-07 21:26:39 -07:00
e80a3f0446 Various minor tweaks and changes
* Recolor some of the region doodads
* Add command: `doodad edit-level --remove-actor` to remove actors from
  your level.
* Tweak the player jump velocity from playtesting levels.
2021-10-07 20:50:24 -07:00
d6acee5a66 Adjust Gravity and Prevent Moonwalking
* Tweak max gravity speed to match player max velocity.
* Boy's script watches for his velocity to flip suddenly and stops
  animations, limiting the moonwalking a bit.
* JS API: Self.GetVelocity() added.
2021-10-07 18:49:09 -07:00
fb5a8a1ae8 Async Giant Screenshot, Player Physics and UI Polish
* The "Giant Screenshot" feature takes a very long time, so it is made
  asynchronous. If you try and run a second one while the first is busy,
  you get an error flash. You can continue editing the level, even
  playtest it, or load a different level, and it will continue crunching
  on the Giant Screenshot and flash when it's finished.
* Updated the player physics to use proper Velocity to jump off the
  ground rather than the hacky timer-based fixed speed approach.
* FlashError() function to flash "error level" messages to the screen.
  They appear in orange text instead of the usual blue, and most error
  messages in the game use this now. The dev console "error <msg>"
  command can simulate an error message.
* Flashed message fonts are updated. The blue font now uses softer
  stroke and shadow colors and the same algorithm applies to the orange
  error flashes.

Some other changes to player physics:

* Max velocity, acceleration speed, and gravity have been tweaked.
* Fast turn-around if you are moving right and then need to go left.
  Your velocity resets to zero at the transition so you quickly get
  going the way you want to go.

Some levels that need a bit of love for the new platforming physics:

* Tutorial 3.level
2021-10-07 18:27:38 -07:00
0b0af70a62 Viewport Windows, Quality of Life, Spit and Polish
* New keybind: 'v' to open a new Viewport in the Level Editor.
* New keybind: Backspace to close the topmost UI window,
  and Shift+Backspace to close them all.
* Zoom has graduated out of experimental feature status. Still a bit
  buggy but workable.
* Viewport windows now copy the Tool and BrushSize of the toplevel
  editor, so drawing in and out of viewports works well.
* Viewport window UI improved: buttons to grow or shrink the window
  size, refresh the actors, etc.
2021-10-06 22:22:34 -07:00
a24c94a161 Multitouch Level Panning
Add multi-touch gesture support so that the player can scroll the level
in the editor (and title screen) by treating a two finger swipe to be
equivalent to a middle click drag.

Fun quirks found with SDL2's MultiGestureEvent:

* They don't begin sending us the event until motion is detected after
  two fingers have touched the screen; not the moment the second finger
  touches it.
* It spams us with events when it detects any tiny change and a lot of
  cool details like rotate/pinch deltas, but it never tells us when the
  multitouch STOPS! The game has to block left clicks while multitouch
  happens so the user doesn't draw all over their level, so it needs to
  know when touch has ended.
* The workaround is to track the mouse cursor position at the first
  touch and each delta thereafter; if the deltas stop changing tick to
  tick, unset the "is touching" variable.
2021-10-06 20:02:09 -07:00
cc16a472af "Playtest From Here" Feature
In the level editor, the "Play (P)" button has a new feature: Play
From Here. On mouse down you begin dragging a silhouette of Boy or
whoever the default player character is, as if you were dragging a
doodad onto your level.

Drop the silhouette on your level and enter Play Mode from that
location instead of the Start Flag.

Release your cursor over the Play button or press the "P" key to
spawn at the Start Flag as usual.
2021-10-04 22:02:00 -07:00
c2c91e45a9 Middle-click to Pan + Remember Scroll Position
In the editor, clicking and dragging with the middle mouse button
will scroll the view of the editor in place of the arrow keys.

When entering Play Mode, the original scroll position in the level
editor is remembered for when you come back - no more having to
scroll from 0,0 each time to get back to where you were working!
2021-10-04 20:49:11 -07:00
489a43ea8c Touch Screen Controls for Play Mode!
The game can now be played using only a touch screen! The left
mouse click (Button1) can now move and control the player
character.

* A box in the very middle of the screen is the "Use" button and
  a deadzone for directional inputs.
* Anywhere outside the middle and to the left registers a Left
  button, to the right a Right button, above the top of the middle
  is a Jump button, and below the bottom of the middle is a down
  input (for antigravity mode).
* Tight platforming is possible: above and below the middle box,
  the left/right split is tight in the middle of the window. You
  can get tight jumps if jumping or go below if you don't want to
  jump. The left/right deadzone is only over the space of the Use
  button.

If the player is idle for a while with no controller inputs, some
hints will fade in about the touch controls.

Note: the ScrollboxOffset to track the player character is changed
to 60,60 from 60,100 so the camera will track tighter to the player
and so the player will mostly be over the Use button on touch
controls as long as he's away from a level boundary.
2021-10-04 19:51:31 -07:00
1f83300cec Picture-in-Picture Window (WIP)
In the Level Editor, the "Level->New viewport" menu opens a window with
its own view into your level. You can open as many viewports as you
want.

* Mouse over a viewport and the arrow keys scroll that canvas instead of
  the main editor canvas!
* You can draw inside the viewports! A selectbox to choose the tool to
  draw with. No palette or thickness support yet!
* The actors are installed as-is when the viewport is created and it
  doesn't show any changes to actors after. Make a new viewport for a
  refreshed view.
* Strokes committed inside the viewport show up in the main editor (and
  in other viewports), and vice versa. The viewports accurately track
  changes to the level's colors, just not the actors.
* Fun feature to load a DIFFERENT level inside of the viewport! Editing
  that level doesn't save changes or anything.
2021-10-03 21:18:39 -07:00
4469847c72 Giant Screenshot Feature
In the Level Editor, the "Level->Giant Screenshot" menu will take a full
scale PNG screenshot of the entire level, with its wallpaper and
doodads, and save it in ~/.config/doodle/screenshots.

It is currently CPU intensive and slow. With future work it should be
made asynchronous. The function is abstracted away nicely so that the
doodad CLI tool may support this as well.
2021-10-03 17:21:17 -07:00
55efdd6eb5 Technical Doodad: Checkpoint Region
The Checkpoint Region acts as an invisible checkpoint flag, remembering
the player's location should they need to respawn there.

New cheat: `show all actors` during Play Mode will make every hidden
actor visible. Useful to see your technical doodads during gameplay!

Developer shell: `Execute(command string)` is available to the
JavaScript interpreter. It simulates another command being run on the
developer console.
2021-10-02 21:36:03 -07:00
97e179716c Add Technical Doodads + UI Fixes
New category for the Doodad Dropper: "Technical"

Technical doodads have a dashed outline and label for now, and they
turn invisible on level start, and are for hidden technical effects on
your level.

The doodads include:

* Goal Region: acts like an invisible Exit Flag (128x128), the level is
  won when the player character touches this region.
* Fire Region: acts like a death barrier (128x128), kills the player
  when a generic "You have died!" message.
* Power Source: on level start, acts like a switch and emits a
  power(true) signal to all linked doodads. Link it to your Electric
  Door for it to be open by default in your level!
* Stall Player (250ms): The player is paused for a moment the first time
  it touches this region. Useful to work around timing issues, e.g.
  help prevent the player from winning a race against another character.

There are some UI improvements to the Doodad Dropper window:

* If the first page of doodads is short, extra spacers are added so the
  alignment and size shows correctly.
* Added a 'background pattern' to the window: any unoccupied icon space
  has an inset rectangle slot.
* "Last pages" which are short still render weirdly without reserving
  the correct height in the TabFrame.

Doodad scripting engine updates:

* Self.Hide() and Self.Show() available.
* Subscribe to "broadcast:ready" to know when the level is ready, so you
  can safely Publish messages without deadlocks!
2021-10-02 20:52:16 -07:00
df3a1679b6 Makefile: mingw 32-bit 2021-09-12 17:15:54 -07:00
528e7b4807 Prepare release v0.8.1 2021-09-12 16:55:36 -07:00
0a1d86e1f5 Bugfix: Scroll constraint favors top/left edge
For levels having a top/left scroll boundary, the top/left point takes
higher priority for resolving out-of-bounds scroll ranges instead of the
bottom/right.

This fixes a bug where you Zoom Out of a level far enough that the
entire boundaries of a Bounded level are smaller than the viewport into
the level. It could happen if playing normal levels in Play Mode on a
very high-resolution monitor. Previously, the level would anchor to the
bottom/right corner of your screen.

With the Zoom In/Out Feature this broke the ability to scroll well on
the level; so the easy fix is to put the X>0, Y>0 bounds check after the
above, so the level will hug the top/left corner of the screen which
fixes both problems.
2021-09-12 15:59:40 -07:00
21520e71e9 Zoom: Fix scrolling into negative coordinates
* If you open a wide unbounded level like Castle.level and zoom out and
  scroll left (into negative world coordinates), the level chunks
  display correctly now.
2021-09-12 15:47:16 -07:00
fd730483b0 Zoom Improvements
* Doodad outline while dragging is now sized properly for the zoom level
* Make doodad hitboxes for Actor/Link Tool more accurate while zoomed
* Fix chunks low on the level not loading while zoomed in
* Fix Link lines drawn between doodads while zoomed - they point to the
  correct position and their DrawLine calls have been optimized so they
  don't lag out the level when lots of them are drawn at once.
2021-09-12 15:27:37 -07:00
6f5bd910c8 Zoom Progress: Actor/Link Tool Hitboxes
* When the Actor Tool or Link Tool is active, mouse-over hitboxes on the
  level's actors now works correctly while zoomed and scrolling in the
  level.
* Regression: Level chunks don't appear outside a certain range from
  origin while zoomed in.
* Regression: Actors don't draw their sprite while zoomed in, but do
  when zoomed out.
2021-09-12 14:42:39 -07:00
731d142dd6 WIP Zoom hell 2021-09-11 22:30:45 -07:00
0a8bce708e Actor Zoom + Experimental Settings GUI
Improvements to the Zoom feature:
* Actor position and size within your level scales up and down
  appropriately. The canvas size of the actor is scaled and its canvas
  is told the Zoom number of the parent so it will render its own
  graphic scaled correctly too.

Other features:
* "Experimental" tab added to the Settings window as a UI version of the
  --experimental CLI option. The option saves persistently to disk.
* The "Replace Palette" experimental feature now works better. Debating
  whether it's a useful feature to even have.
2021-09-11 21:18:22 -07:00
ecdfc46358 Zoom And Edit
Progress on the Zoom feature: when you zoom in and out, you can draw
shapes accurately onto the level. Seems a little buggy if you edit
while scrolling (as in drawing a very long line).

The title screen buttons are now more colorful.
2021-09-11 17:02:01 -07:00
13ae66e1fa Bash for Makefiles 2021-09-06 14:06:55 -07:00
4d3e336ca1 Update release date for v0.8.0 2021-09-04 12:44:10 -07:00
449a30dc2c Small typo fix 2021-09-03 21:45:48 -07:00
f446ed9130 Prepare v0.8.0 for release 2021-09-03 21:35:12 -07:00
7866f618da First-class Doodad Hitboxes + Generic Item Script
A new property is added to the Doodad struct: Hitbox (Rect).

The uix.Actor for Play Mode will defer to the Doodad.Hitbox until the
JavaScript has manually set its own via Self.SetHitbox(). So in effect,
scripts no longer need to worry about their hitbox! The one assigned to
the Doodad will be the default.

Scripts can check if their hitbox is zero before setting a default:

  if (Self.Hitbox().IsZero()) {
    var size = Self.Size()           // get doodad canvas size
    Self.SetHitbox(0, 0, size, size) // the full square
  }

The built-in generic doodad scripts have made this change, so that your
simple doodad can have a custom hitbox defined easily using in-game
tools.

Other changes:

* New script: Generic Collectible Item. Selecting it will add a
  "quantity" tag to your doodad, to easily configure the script.
* JavaScript API: "Self.Hitbox()" returns your doodad's current hitbox.
  You can check "Self.Hitbox.IsZero()" to check if it's empty.
2021-09-03 20:39:44 -07:00
c499a15c71 Animations for Thief + No More Moonwalking
* Adds walking animations for the Thief.
* Mobile doodads no longer moonwalk: their A.I. used to wait for the
  animation to finish before setting the appropriate animation, so when
  it changed directions it would "moonwalk" for a time. Their A.I. is
  now updated to cancel the animation if they change directions so to
  immediately play the correct animation.
2021-09-03 19:54:10 -07:00
7ea86b4ffc Generic Doodad Script Selection
In the Doodad Properties window, instead of browsing to select a .js
file to install your script, a SelectBox of built-in generic scripts are
available. These scripts implement simple behaviors and adapt to the
full canvas size of the doodad.

Built-in scripts so far include:

* generic-anvil.js: behaves just like the Anvil.
* generic-fire.js: the entire canvas hitbox acts like fire pixels,
  "burning" mobile doodads and failing the level for the player.
* generic-solid.js: the entire canvas hitbox acts solid
2021-09-02 22:33:28 -07:00
0fa1bf8a76 Editor: Doodad Properties Window
The Doodad Properties window brings many features that used to be
available only in the `doodad` CLI tool into the Doodad Editor.

* In the Doodad Editor there is a new menubar item: "Doodad" which
  corresponds to the "Level" menu when you're editing a level.
* The "Doodad" menu has two items:
  - "Doodad Properties" (NEW)
  - "Layers" (moved here from the Tools menu)
* The Doodad Properties window lets you edit the Title and Author values
  of the doodad, as well as modify its Tags and manage its Script.
* Its script can be attached (browse for .js file on disk), its existing
  script saved back to disk (dev shell prompt) or deleted altogether
  from the doodad.
* You can create, modify, and delete Tags on the doodad.

Other changes:

* In the Level Editor, the "Level->Page Settings" menu is renamed to
  "Level->Level Properties" to match with "Doodad->Doodad Properties"
  and the pop-up window is retitled accordingly.
* The Exit Flag only exits if the Player touches it - not just any
  mobile doodad!
2021-09-02 21:26:55 -07:00
0cc1d17f4f Sort levels and doodads in the Open menu 2021-08-15 20:27:05 -07:00
1ac85c9297 Checkpoint Flag & Retry from Checkpoint
* New Doodad: Checkpoint Flag. They update the player's spawn point
  whenever the player passes one. The most recently activated
  checkpoint is rendered brighter than the others.
* End Level Modal: the fake alert box window drawn by the Play Mode
  is replaced with a fancy modal widget (similar to Alert and Confirm).
  It handles level victory or failure conditions and can show or hide
  all the buttons as needed.
* Gameplay: There is a "Retry from Checkpoint" option added, which
  appears in the level failure modal. It will teleport you back to
  the Start Flag or the last Checkpoint Flag you had touched, without
  resetting the level -- your keys, unlocked doors, etc. will be
  preserved so you can retry.
* Set a maximum speed on the "Camera Follows Actor" logic of 64
  pixels per tick. This results in a smoother scrolling transition
  when the player jumps to a new location on the map, such as by
  a Warp Door.
* Update the default color palettes:
    * All: Add a "hint" magenta color.
    * Colored Pencil: Add a "darkstone" solid color.

Updates to the Doodads JavaScript API:

* SetCheckpoint(Point(x, y)): set the player character's spawn
  position. Giving it Self.Position() is an easy way to set the
  player spawn to your doodad's location.
2021-08-15 20:17:53 -07:00
43f8e3d9b2 Thief: Ability to Steal as Player Character
* The Thief's ability is now available to the player character in levels
  where you'll play as the Thief.
* The Thief is able to steal items from all characters it contacts,
  including Azulians and other Thieves.
* A.I. Thieves will not steal items from each other, to prevent loops.
  Only a Thief controlled by the player will steal items from a Thief.
2021-08-15 17:33:05 -07:00
0bf5045a53 Death Barrier and Player Character Cheat Codes
* Added the Death Barrier to Play Mode to catch players from falling off
  the map and then falling indefinitely, especially on Unbounded maps.
* The Death Barrier is set 1,000 pixels below the lowest point on your
  map. If the player falls here they get a death message: "Watch out for
  falling off the map!"
* Added cheat codes to change the default Player Character doodad, as a
  way to force play as a different character (for levels which don't
  specify a custom character):
  * Play as Bird: fly like a bird
  * Play as Blue Azulian: the cell
  * Play as Thief: play as thief
  * Reset to default (Boy): pinocchio
2021-08-15 17:01:18 -07:00
405aaf509d Link Start Flags to Change Characters
New feature: link a Start Flag to another doodad in your level
and you will play as that doodad instead of Boy. All Creatures
are designed to be playable. Playing as "other" doodads leads
to interesting effects, like not being able to activate buttons,
switches, or warp doors and not having an inventory to pick up
keys. The Anvil is fun: it can destroy other mobile doodads by
jumping on them.

If the actor does not specify that it has gravity, the gameplay
starts in antigravity mode. This will be the vast majority of
non-mobile doodads and the Bird.

Other changes:

* The Blue and Red Azulians now share a doodad script.
* The Azulians AI is still to walk back and forth, pickup keys and
  press buttons. The Blue Azulian walks slower than the red one.
* The Blue Azulian is no longer hidden from the doodads list.
* Actor UUID values in levels are now V1 UUIDs (time-ordered).
  This will help to reliably resolve conflicts in draw order
  of overlapping doodads (newest added to level wins).
* Link Tool: clicking on a pair of already-linked doodads will
  now unlink them, so you don't have to delete one to delete
  the link.
* Actor Tool: deleting an actor immediately calls PruneLinks()
  to clean up any links that the deleted doodad might have.
2021-08-11 20:40:31 -07:00
d7a96d1770 Thief and Inventory APIs
This commit adds the Thief character with starter graphics
(no animations).

The Thief walks back and forth and will steal items from other
doodads, including the player. For singleton items that have no
quantity, like the Colored Keys, the Thief will only steal one
if he does not already have it. Quantitied items like the
Small Key are always stolen.

Flexibility in the playable character is introduced: Boy,
Azulian, Bird, and Thief all respond to playable controls.
There is not currently a method to enable these apart from
modifying balance.PlayerCharacterDoodad at compile time.

New and Changed Doodads

* Thief: new doodad that walks back and forth and will steal
  items from other characters inventory.
* Bird: has no inventory and cannot pick up items, unless player
  controlled. Its hitbox has also been fixed so it collides with
  floors correctly - not something normally seen in the Bird.
* Boy: opts in to have inventory.
* Keys (all): only gives themselves to actors having inventories.

JavaScript API - New functions available

* Self.IsPlayer() - returns if the current actor IS the player.
* Self.SetInventory(bool) - doodads must opt-in to having an
  inventory. Keys should only give themselves to doodads having
  an inventory.
* Self.HasInventory() bool
* Self.AddItem(filename, qty)
* Self.RemoveItem(filename, qty)
* Self.HasItem(filename)
* Self.Inventory() - returns map[string]int
* Self.ClearInventory()
* Self.OnLeave(func(e)) now receives a CollideEvent as parameter
  instead of the useless actor ID. Notably, e.Actor is the
  leaving actor and e.Settled is always true.

Other Changes

* Play Mode: if playing as a character which doesn't obey gravity,
  such as the bird, antigravity controls are enabled by default.
  If you `import antigravity` you can turn gravity back on.
* Doodad collision scripts are no longer run in parallel
  goroutines. It made the Thief's job difficult trying to steal
  items in many threads simultaneously!
2021-08-09 22:42:22 -07:00
0518df226c New Doodad: Anvil
* The Anvil doodad is affected by gravity and becomes dangerous when
  falling. If it lands on the player character, you die! If it lands on
  any other mobile doodad, it destroys it! It can land on solid doodads
  such as the Electric Trapdoor and the Crumbly Floor. It will activate
  a Crumbly Floor if it lands on one, and can activate buttons and
  switches that it passes.
* JavaScript API: FailLevel(message) can be called from a doodad to kill
  the player character. The Anvil does this if it collides with the
  player while it's been falling.
2021-08-08 21:57:41 -07:00
810ba193d9 Doodads: Electric Trapdoor and Resettable Box
* New doodad: Electric Trapdoor. It is a horizontal version of the
  Electric Door. Opens while powered by a button or a switch and closes
  when it loses power.
* The Box doodad will reset to its original location if it receives a
  power signal from a linked Button or Switch. So for box pushing
  puzzles you can add a reset button in case the boxes get stuck.
* Refactored the Doodad build scripts into many Makefiles for easier
  iteration (don't need to compile ALL doodads to test one).

Updates to the JavaScript API for doodads:

* Self.MoveTo(Point) is now available to set the actor's position in
  world coordinates.
2021-08-08 20:10:42 -07:00
49876c4fdf New TabFrame Widget for Doodads and Settings
* Install the new ui.TabFrame widget into the Settings and Doodad
  Dropper windows to give them properly tabbed interfaces.
* Doodad Dropper's new tabs divide the list of doodads into categories
  to make them easier to find.
* The officially defined categories so far are:
  - Objects (Start/End Flags and Box)
  - Doors (All locked doors and keys, Warp Doors, and Electric Door)
  - Gizmos (All buttons, switches, state blocks/doors, Electric Door)
  - Creatures (Blue/Red Azulian, Bird, Boy)
* The "All" tab of the Doodad Dropper will show every doodad regardless
  of its category or whether it fit one of the official categories.
* How doodads are assigned categories is by a special "category" tag in
  their metadata, e.g. "category=doors,gizmos" - multiple supported.
2021-07-25 21:46:55 -07:00
fbeeb207a8 Embed: Normalize path separator for Windows
* Windows was asking for files like "assets\doodads\" and the embedded
  files used Unix-like paths so no assets could be loaded!
2021-07-19 22:15:40 -07:00
3949934bc1 Prepare v0.7.2 for release 2021-07-19 21:20:22 -07:00
215ed5c847 Stabilize Load Screen by Deferring SDL2 Calls
* The loading screen for Edit and Play modes is stable and the risk of
  game crash is removed. The root cause was the setupAsync() functions
  running on a background goroutine, and running SDL2 draw functions
  while NOT on the main thread, which causes problems.
* The fix is all SDL2 Texture draws become lazy loaded: when the main
  thread is presenting, any Wallpaper or ui.Image that has no texture
  yet gets one created at that time from the cached image.Image.
* All internal game logic then uses image.Image types, to cache bitmaps
  of Level Chunks, Wallpaper images, Sprite icons, etc. and the game is
  free to prepare these asynchronously; only the main thread ever
  Presents and the SDL2 textures initialize on first appearance.
* Several functions had arguments cleaned up: Canvas.LoadLevel() does
  not need the render.Engine as (e.g. wallpaper) textures don't render
  at that stage.
2021-07-19 17:14:00 -07:00
2d1b926e4f New Doodad: Box
The Box can be pushed around by the player or other mobile doodads.

It is affected by gravity and can be pushed off ledges.

If the player gets under a box they can bump it up with their head.
2021-07-18 21:22:53 -07:00
d4e6d9babb Loading Screen
* pkg/loadscreen implements a global Loading Screen for loading heavy
  levels for playing or editing.
* All chunks in a level are pre-rendered to bitmap before gameplay
  begins, which reduces stutter as chunks were being lazily rendered on
  first appearance before.
* The loading screen can be played with in the developer console:
  $ loadscreen.Show()
  $ loadscreen.Hide()
  Along with ShowWithProgress(), SetProgress(float64) and IsActive()
* Chunker: separate the concerns between Bitmaps an (SDL2) Textures.
* Chunker.Prerender() converts a chunk to a bitmap (a Go image.Image)
  and caches it, only re-rendering if marked as dirty.
* Chunker.Texture() will use the pre-cached bitmap if available to
  immediately produce the SDL2 texture.

Other miscellaneous changes:

* Added to the Colored Pencil palette: Sandstone
* Added "perlin noise" brush pattern

Note: this commit introduces instability and crashes:

* New `asyncSetup()` functions run on a goroutine, but SDL2 texture
  calls must run on the main thread.
* Chunker avoids this by caching bitmaps, not textures.
* Wallpaper though is unstable, sometimes works, sometimes has graphical
  glitches, sometimes crashes the game.
* Wallpaper.Load() and the *Texture() functions are where it crashes.
2021-07-18 21:19:52 -07:00
2885b2c3d0 Remove bindata references from bootstrap.py 2021-07-13 20:16:16 -07:00
8603c43c58 Gzip Compression for Levels and Doodads
* Levels and Doodad files will be written in gzip-compressed JSON format
* `boolProp compress-drawings false` to disable compression and save as
  classic JSON format directly
* The game can still read uncompressed JSON files

The file size savings on some built-in assets:

* Tutorial 2.level: 2.2M -> 414K (82% smaller)
* warp-door-orange.doodad: 105K -> 17K (84% smaller)
2021-07-13 20:06:57 -07:00
3486050702 Go 1.16 embed instead of go-bindata
* Migrate off go-bindata to embed built-in fonts, levels and doodads in
  favor of Go 1.16 native embed functionality.
* `make bindata` prints a deprecation warning to not break older build
  scripts
* Removes all references of bindata from the program
2021-07-13 18:04:25 -07:00
26b1ac88dd Shift to scroll slowly + Doodads on Q
* Holding Shift while pressing arrow keys in the editor will scroll by
  just 1 pixel per tick to aid in precise debugging with the Zoom In/Out
  feature.
* The keybinds used in canvas_editable.go to catch the arrow keys are
  updated to use our nice keybind package. As a consequence, the WASD
  keys will also scroll the level.
* The "d for Doodads" keybind is renamed "q" so as not to open the
  Doodads window whenever scrolling right using the WASD keys.
2021-07-13 18:04:25 -07:00
37f6177a17 Zoom In/Out Feature: WorldIndexAt Fixed
WorldIndexAt() translates the pixel below the mouse cursor in screen
space (0,0 at top-left corner of the application window) into a world
coordinate in the level shown inside the canvas, taking into account the
canvas's position on the window and the scroll position.

It now translates correctly when zoom In or Out, so the "Abs:" mouse
position level in the status bar shows correctly.

Zoom features that are still jank:

- Scrolling while zoomed in, the chunks to the top/left start unloading
  too rapidly and outpacing the scroll, eventually level is invisible
- Drawing and committing pixels to the image while zoomed in/out is
  unpredictable where the pixels actually land.
- Actors in the level don't move or zoom at all.
2021-07-13 18:04:25 -07:00
ed492a4451 Progress on the Zoom In/Out Feature
* Got the level chunks AND the wallpaper to both scale UP and DOWN
  consistently together.
* Trying to draw new pixels while zoomed in/out ends up offsetting the
  pixels by 2X still. Still seems an issue between screen coordinates
  and world coordinates. Zoom in 2X and try and draw a line 64px from
  the corners of the screen? The committed line appropriately lands at
  the 64px coord on the level data but, zoomed in, it appears 2X to the
  right on the screen from where I dropped the cursor!
* When zooming OUT, the limit on number of chunks the viewport will try
  and render is not increased, leaving dead space in the screen; more
  chunks should render when there's room.
2021-07-11 21:54:28 -07:00
456863839e release.sh steps for easy Mac OS distribution 2021-07-11 14:38:26 -07:00
d1ef9d2932 Prepare v0.7.1 for release 2021-07-11 14:09:18 -07:00
1c7678c48e Improve automated distribution and release 2021-07-11 14:09:18 -07:00
0af4dd40bc Bugfix (Windows): Bindata wallpapers weren't resolving
* The Windows build of v0.6.0 couldn't load embedded wallpapers such as
  legal.png when asked, but could load the hard-coded default.png
* Root cause was the filesystem.FindFile() checking for path separators
  in the filepath, and on Win32 this is \ but the internal wallpaper
  paths use /
2021-07-11 14:09:18 -07:00
1105d9312a Updater: Better SemVer version checks for updates
* Instead of a simple "cur. ver != latest ver" check, parse the Major,
  Minor and Patch components and do a detailed check.
* So a x.x.1 release could be made for a specific platform that had a
  bad build, and it won't mind when it sees the latest version is the
  older x.x.0 build that other platforms had working fine.
2021-07-11 14:09:18 -07:00
fa15a8bcf5 Fix mac-app.sh script 2021-06-20 15:11:03 -07:00
78f9d0dbfa Fix fpmbundle script 2021-06-20 14:40:23 -07:00
99c93dc174 Fix Profile Directory file:// URI for Windows 2021-06-20 13:21:47 -07:00
53123dff1d Prepare v0.7.0 for release 2021-06-20 13:10:23 -07:00
386e0b2b0c Brighten Patterns + Update Default Palettes
* The pattern textures for level palettes have been brightened and work
  better with bright colors.
* The three default palettes for new levels now have patterns applied to
  each of their colors.
* Bugfix around resetting keybind states for Zoom In/Out, Scroll to
  Origin and Reset Zoom Level bindings.
2021-06-20 10:42:51 -07:00
864156da53 Settings Window + Bugfix
* Added a Settings window for game options, such as enabling the
  horizontal toolbars in Edit Mode. The Settings window also has a
  Controls tab showing the gameplay buttons and keyboard shortcuts.
* The Settings window is available as a button on the home screen OR
  from the Edit->Settings menu in the EditScene.
* Bugfix: using WASD to move the player character now works better and
  is considered by the game to be identical to the arrow key inputs. Boy
  now updates his animation based on these keys, and they register as
  boolean on/off keys instead of affected by key-repeat.
* Refactor the boolProps: they are all part of usercfg now, and if you
  run e.g. "boolProp show-all-doodads true" and then cause the user
  settings to save to disk, that boolProp will be permanently enabled
  until turned off again.
2021-06-19 22:14:41 -07:00
d0cfa50625 Hook up keybinds like Ctrl-N, Ctrl-S
* Menu keybinds that weren't working before, like Ctrl-N, Ctrl-S, Ctrl-O
  to create and open levels are now working.
2021-06-17 19:43:30 -07:00
dce32ea14b Diverge Free vs. Paid Features
* Free (shareware) versions of the game will not be able to Publish
  Levels (attach custom doodads to the level file) and they will not be
  able to load a level which relies on embedded doodads.
* The UI for the Publish Level window is still available, but clicking
  on the confirm button will just open the Register (License) window.
* When loading a level containing embedded doodads: if some can't load
  because they're embedded and you're using the free version of the
  game, the error message is customized to reflect that.
2021-06-16 22:35:01 -07:00
0449737607 License Key Registration with ECDSA JWT Tokens
* New command-line tool: doodle-admin for signing license keys for
  users. Includes functions to initialize a keypair, sign license keys
  and validate existing keys.
* The Main Menu screen shows a blue "Register Game" button in the bottom
  right corner of the screen, for unregistered users only.
* In Edit Mode, there is a "Help -> Register" menu item that opens the
  License Window.
* The License UI Window lets the user select the license.key file to
  register the game with. If registered, a copy of the key is placed in
  Doodle's profile directory and the licensee name/email is shown in the
  License UI window.
* Unregistered games will show the word "(shareware)" next to the title
  screen version number and Edit Mode status bar.
* No restrictions are yet placed on free versions of the game.
2021-06-16 21:56:30 -07:00
d6f86487f5 Horizontal Toolbars Option for Editor Mode
On small screen sizes like the Pinephone, the toolbars in the Level
Editor are best made horizontal across the top and bottom of the screen
leaving more room for the drawing.

Enable it with a boolProp for now, and then reopen the level editor:

    boolProp horizontalToolbars true

When launching `doodle -w mobile` it will automatically enable this
option.
2021-06-13 21:23:26 -07:00
e6b71f5512 Fix Scroll-Follow-Actor Behavior
* The scrollbox by which the game follows the player character has been
  revised, it is now an offset away from the window's center instead of
  fixed pixel distances from the window's edges.
* Mobile form-factor (Pinephone) now scrolls OK instead of jerking back
  and forth rapidly when moving left.
2021-06-13 20:25:42 -07:00
c5e3fc297c Manage Embedded Files In Levels
In the Level Editor, the "Level->Attached files" menu opens the
FileSystem Window, which shows a paginated list of attached files and a
"Delete" button to remove them.

- Custom doodads which also exist locally can be deleted from the
  level's filesystem at any time.
- If a custom doodad does NOT exist locally, and one of them is still
  placed somewhere within the level, you can not delete it.
- You can't delete the custom wallpaper image IF the level is still
  using it. Change to a default wallpaper and then you can delete the
  custom wallpaper image.
2021-06-13 16:03:32 -07:00
7093b102e3 Embeddable Doodads In Levels
* The Publisher is all hooked up. No native Save File dialogs yet, so
  uses the dev shell Prompt() to ask for output filename.
* Custom-only or builtin doodads too can be stored in the level's file
  data, at "assets/doodads/*.doodad"
* When loading the embedded level in the Editor: it gets its custom
  doodads out of its file, and you can drag and drop them elsehwere,
  link them, Play Mode can use them, etc. but they won't appear in the
  Doodad Dropper if they are not installed in your local doodads
  directory.
* Fleshed out serialization API for the Doodad files:
  - LoadFromEmbeddable() looks to load a doodad from embeddable file
    data in addition to the usual places.
  - Serialize() returns the doodad in bytes, for easy access to embed
    into level data.
  - Deserialize() to parse and return from bytes.
* When loading a level that references doodads not found in its embedded
  data or the filesystem: an Alert modal appears listing the missing
  doodads. The rest of the level loads fine, but the actors referenced
  by these doodads don't load.
2021-06-13 14:59:03 -07:00
d9bca2152a WIP Publish Dialog + UI Improvements
* File->Publish Level in the Level Editor opens the Publish window,
  where you can embed custom doodads into your level and export a
  portable .level file you can share with others.
* Currently does not actually export a level file yet.
* The dialog lists all unique doodad names in use in your level, and
  designates which are built-ins and which are custom (paginated).
* A checkbox would let the user embed built-in doodads into their level,
  as well, locking it in to those versions and not using updated
  versions from future game releases.

UI Improvements:
* Added styling for a "Primary" UI button, rendered in deep blue.
* Pop-up modals (Alert, Confirm) color their Ok button as Primary.
* The Enter key pressed during an Alert or Confirm modal will invoke its
  default button and close the modal, corresponding to its Primary
  button.
* The developer console is now opened with the tilde/grave key ` instead
  of the Enter key, so that the Enter key is free to click through
  modals.
* In the "Open/Edit Drawing" window, a "Browse..." button is added to
  the level and doodad sections, spawning a native File Open dialog to
  pick a .level or .doodad outside the config root.
2021-06-10 22:36:22 -07:00
eb24858830 Brush Pattern Textures
Palette swatches gain a new property: Pattern.

Patterns are grayscale textures that the swatch color will sample
against when drawing pixels to the level, by taking the world coordinate
modulo a value inside the texture.

A few algorithms were tried (Screen, Overlay), this branch lands on one
that tries to cast the color from grayscale which comes out rather dark;
to get a patterned color to look black while still seeing the pattern,
the color needs to be as bright as #777 to get the effect.
2021-06-09 22:36:32 -07:00
e8388fafad Title Screen: Lazily scroll the demo level
Adds a lazy scroll algorithm that basically:
- Zigzags right/down a certain distance, then up again
- Then enters a bounce phase where it bounces off the level
  boundaries like a screensaver.

Arrow keys can still scroll the level manually, but the
automated scroll takes over otherwise.
2021-06-08 21:12:30 -07:00
bd90393cc3 Prepare v0.6.0 for release 2021-06-06 22:08:56 -07:00
8d3fc41e43 New Default Wallpapers
* Graph paper, Dotted paper, and secret Blue Notebook
2021-06-06 19:22:53 -07:00
640e75ba4d Custom Wallpapers for Levels
* You can now browse for a custom wallpaper image to use with your
  levels. A platform-native file picker dialog is used (no WASM support)
* In the New/Edit Level Properties dialog, the Wallpaper drop-down
  includes an option to browse for a custom map.
* When editing an existing level: the wallpaper takes effect immediately
  in your level once the file is picked. For NEW levels, the wallpaper
  will appear once the "Continue" button is pressed.
* All common image types supported: png, jpeg, gif.
* The wallpaper is embedded in the level using the filepath
  "assets/wallpapers/custom.b64img" as a Base64-encoded blob of the
  image data.
* The `doodad show` command will list the names and sizes of files
  embedded in levels. `doodad show --attachment <name>` will get an
  attachment and print it to the console window.
* To extract a wallpaper image from a level:
  `doodad show -a assets/wallpapers/custom.b64img | base64 -d > out.png`
2021-06-06 18:59:04 -07:00
ba29f407cc SelectBoxes in Add/Edit Level Window
* Replace the radio buttons for Page Type and Wallpaper with the new
  SelectBox widgets from the UI toolkit.
* Choice of default palette also switched from a MenuButton to
  a SelectBox widget.
* Experimental "Browse..." option added to the Wallpaper drop-down when
  run in --experimental mode; not yet functional.
2021-06-06 14:32:52 -07:00
3d8eedce35 Choice of palette when creating a new level
* In the "New Level" dialog, a "Palette:" option shows a MenuButton
  drop-down with options: Default, Colored Pencil, and Blueprint. These
  control the set of colors the new level starts with.
2021-06-05 20:51:20 -07:00
be47dc21c7 Decouple gravity from player velocities 2021-06-02 22:18:25 -07:00
d470f7e647 Collision: Fix walking up leftward slopes
* Actors can now walk up gentle inclines to the left as well as they can
  to the right. The bug was introduced as a hack to prevent clipping
  thru the left wall of a 90 degree corner, but that problem seems
  resolved now.
2021-06-02 21:49:29 -07:00
d14eaf7df2 Collision Box Updates
* The F4 key to draw collision boxes works reliably again: it draws the
  player's hitbox in world-space using the canvas.DrawStrokes()
  function, rather than in screen-space so it follows the player
  reliably.
* The F4 key also draws hitboxes for ALL other actors in the level:
  buttons, enemies, doors, etc.
* The level geometry collision function is updated to respect a doodad's
  declared Hitbox from their script, which may result in a smaller box
  than their raw Canvas size. The result is tighter collision between
  doodads, and Boy's sprite is rather narrow for its square Canvas so
  collision on rightward geometry is tighter for the player character.
* Collision checks between actors also respect the actor's declared
  hitboxes now, allowing for Boy to get even closer to a locked door
  before being blocked.
2021-06-02 20:50:28 -07:00
fcb5d27290 bootstrap.py: add Manjaro/Arch Linux setup 2021-06-02 19:18:52 -07:00
9b80d38c3e App rename + macOS Build Fixes 2021-05-02 12:06:34 -07:00
f5d814283c New icons and update rpm/deb/macOS scripts 2021-03-31 21:22:13 -07:00
dc1f0721c2 Update README file for 0.5.0 2021-03-31 19:35:32 -07:00
0fedcf4fcb Adjust ScrollboxVert and Prepare v0.5.0 for Release 2021-03-31 19:27:40 -07:00
1f274e0ca6 Changelog and Prepare v0.5.0 for Release 2021-03-31 19:16:33 -07:00
76b7dfa4f8 Various updates
New doodad interactions:
* Sticky Buttons will emit a "sticky:down" event to linked doodads, with
  a boolean value showing the Sticky Button's state.
* Normal Buttons will listen for "sticky:down" -- when a linked Sticky
  Button is pressed, the normal Button presses in as well, and stays
  pressed while the sticky:down signal is true.
* When the Sticky Button is released (e.g. because it received power
  from another doodad), any linked buttons which were sticky:down
  release as well.
* Switch doodads emit a new "switch:toggle" event JUST BEFORE sending
  the "power" event. Sensitive Doodads can listen for switches in
  particular this way.
* The Electric Door listens for switch:toggle; if a Switch is activated,
  the Electric Door always flips its current state (open to close, or
  vice versa) and ignores the immediately following power event. This
  allows doors to toggle on/off regardless of sync with a Switch.

Other changes:
* When the player character dies by fire, instead of the message saying
  "Watch out for fire!" it will use the name of the fire swatch that
  hurt the player. This way levels could make it say "Watch out for
  spikes!" or "lava" or whatever they want. The "Fire" attribute now
  just means "instantly kills the player."
* Level Editor: You can now edit the Title and Author name of your level
  in the Page Settings window.
* Bugfix: only the player character ends the game by dying in fire.
  Other mobile doodads just turn dark but don't end the game.
* Increase the size of Trapdoor doodad sprites by 150% as they were a
  bit small for the player character.
* Rename the game from "Project: Doodle" to "Sketchy Maze"
2021-03-30 23:40:41 -07:00
837960c477 Doodads: Small Key Door + Bigger Crumbly Floor
* The crumbly floor doodad was made 50% larger.
* New doodad: Small Key and Small Key Door. These work like the colored
  doors and locks except each Small Key is consumed when it unlocks a
  door. The door's appearance is of iron bars.
* The inventory HUD displays a small quantity label in the lower-right
  corner of items that have a quantity, such as the Small Key. This is
  done as a Canvas.CornerLabel string attribute on uix.Canvas.
* The "give all keys" cheat adds 99 Small Keys to your inventory.
2021-01-03 17:06:33 -08:00
3892087932 Doodads: Use Key and Working Warp Doors
* The "Use Key" (Q or Spacebar) now activates the Warp Door instead of a
  collision event doing so.
* Warp Doors are now functional: the player opens a door, disappears,
  the door closes; player is teleported to the linked door which opens,
  appears the player and closes.
* If the player exits thru a Blue or Orange door which is disabled
  (dotted outline), the door still opens and drops the player off but
  returns to a Disabled state, acting as a one-way door.
* Clean up several debug log lines from Doodle and doodad scripts.
2021-01-03 15:19:21 -08:00
2c1185cc9f Doodads: Warp Doors, Bird, Larger State Blocks
* The blue and orange ON/OFF state blocks have all been increased in
  size to better match the player character (42x42 up from 33x33)
* Added a new mob: the Red Bird. It flies back and forth while
  maintaining its altitude, similar to the Red Azulian. Planned AI
  behavior is to divebomb the player when it gets close. Dive sprites
  are included but not yet hooked up in JavaScript.
* Warp Doors! (WIP). They have a golden "W" on them and come in three
  varieties: Brown, Blue and Orange. The blue and orange ones are
  sensitive to the State Block and will become dotted outlines when
  inactive (and can not be entered in this state). The door opens for
  the player character, makes him disappear, then closes again. The plan
  is it will then warp you to the location of a linked Warp Door
  elsewhere on the level, but for now it will just make the player
  re-appear after completing the Close Door animation.
2020-12-29 20:31:35 -08:00
11afc7b522 New Doodads: Bigger Doors
* The colored locked doors and the Electric Door are increased in size
  to better match Boy's sprite size.
* Colored doors now have a "locked" and "unlocked" state when closed;
  when locked, a gold padlock hangs on the door with a keyhole shaped to
  match the corresponding Colored Key.
2020-12-29 17:24:42 -08:00
6912362899 Revert go.mod replace directives 2020-12-28 20:49:35 -08:00
6c5da42c91 Update the bootstrap.py script
* Tested on a fresh Ubuntu 20.04 VM
2020-12-28 20:46:32 -08:00
c78cd38c1d Add chdir option for Flatpak
* The --chdir CLI option to doodle will set a working directory for the
  game to switch to on startup. Flatpak builds place the files at
  /app/share/doodle where the ./rtp and ./guidebook files are relative
  to and this allows the game to find its sound effects and such.
2020-12-28 18:32:55 -08:00
580aaca2c5 go.mod: dependencies inside local deps/ folder
* Simplify building Doodle by cloning outside dependencies (like
  go/render and go/ui) into the deps/ folder, to assist with Flatpak
  building the app from source easily.
2020-12-28 15:04:51 -08:00
9529980ee4 Update changelog for v0.4.0-alpha 2020-11-20 23:35:37 -08:00
8eb3ab51d3 Fixup some developer console commands 2020-11-20 22:53:38 -08:00
fade085695 Move dev-assets/guidebook into its own repository 2020-11-20 19:08:31 -08:00
6cd5f17e9b Prepare v0.4.0 for release 2020-11-19 20:51:02 -08:00
6e40d58010 WIP Zoom Tool
* Added Feature Flag support, run doodle with --experimental to enable
  all flags. Eraser Tool is behind a feature flag now.
* + and - on the top row of keyboard keys will zoom the drawing in and
  out in Edit Mode. The wallpaper zooms nicely enough, but level
  chunkers need work.
* A View menu is added with Zoom in/out, reset zoom, and scroll to
  origin options. The whole menu is behind the Zoom feature flag.
* Update README with lots of details for fun debug mode options to play
  around with.
2020-11-19 20:09:15 -08:00
24aef28a0d Centralize Keybinds, Improve Menus
* pkg/keybinds holds central functions to check global keybinds, like
  DebugOverlay (F3), Undo (Ctrl-Z), GotoPlay/GotoEdit (p/e), etc.
* The Tools menu in the editor mode lists out more options to select
  various drawing tools (line, pencil, etc.) - and showing the hotkey
  for each tool.
2020-11-17 18:22:48 -08:00
190d4be1b6 Layer Selection Window for Doodad Editor
* When editing a doodad in the Editor Mode, the toolbar has a "Lyr."
  button that opens the Layers window.
* The Layers window allows switching the active doodad layer that you
  are drawing on, as well as create and rename layers.
* With this feature, Doodads may be fully drawn in-game, including
  adding alternate named layers for animations and multiple-state
  doodads.
* Update the Pager component to have a configurable MaxPageButtons.
  Controls that have more pages than this limit will stop having buttons
  drawn after the limit. The "Forward" and "Next" buttons can still
  navigate into the extra pages.
* Refactored and centralized the various popup windows in Editor Mode
  into editor_ui_popups.go; the SetupPopups() and various methods such
  as ShowPaletteWindow() and ShowDoodadDropper() make management of
  popups simple for the editor_ui!
* The Menu Bar in Editor Mode now has context-specific tools in the
  Tools menu: the Doodad Dropper for levels and Layers for doodads.
* Bugfix the Palette Editor window to work equally between Levels and
  Doodads, by only having it care about the Palette and not the Level
  that owns it.
2020-11-16 23:23:21 -08:00
336a949ed0 Global UI Popup Modals
* Adds global modal support in the pkg/modal/ package. It has easy
  Alert() and Confirm() methods to prompt the user before calling a
  callback function on affirmative response.
* Modals have global app state: they're processed in the main loop in
  pkg/doodle.go similar to the global command shell.
* When a modal is active, a semitransparent black frame covers the
  screen (gameplay loop paused, last game frame rendered below) and the
  modal window appears on top.
* The developer console retains higher priority than the modal system
  and always renders on top.
* Editor Mode: track when the level pixels have been modified, and
  confirm the user about unsaved changes when they attempt to close the
  level (New, Open, Close, etc.)
* Global: the Escape key no longer immediately shuts down the game, but
  will confirm the user's intent via a modal.
* File->Quit in the Editor Mode also invokes the confirm shutdown modal.
2020-11-15 18:02:35 -08:00
bc02f2c685 Convert to use Go modules 2020-11-15 15:20:15 -08:00
6241bfe415 Prepare v0.3.0 for release 2020-09-18 22:52:05 -07:00
71b3eafbe4 Add Player Character Sprites
* Added initial walking sprites for the player character, "Boy."
* Player doodad filename and title screen level are now configurable in
  the balance/numbers.go package.
2020-09-18 22:35:43 -07:00
6d8aa387d7 WIP Game Settings Window, WASM Fixes, Sound FX
* Add sound effect and music support to Doodle.
* Fix WASM build to use the 'null' sound driver for now.
* Add a Settings button to the main menu; UI for it is WIP.
2020-09-01 20:54:58 -07:00
47cca8c7c6 Palette Editor and Doodad Dropper Windows
* Start the program window maximized with the `-w maximized` CLI option.
* Move the Doodad Palette off the right-side dock of the Editor Scene and
  into its own pop-up window: the DoodadDropper.
* Shrink the width of the Color Palette panel and show only the colors in
  the buttons. The name of the swatch is available in the mouse-over tooltip.
* Added an "Edit" button to the Color Palette. It opens a Palette Editor
  window where you can rename, change colors and attributes of existing colors
  OR insert new colors into your palette. (Deleting colors not yet supported).
* level.Chunker gets a Redraw method: invalidates all cached textures of all
  chunks forcing the level to redraw itself, possibly with an updated palette.
2020-07-09 19:38:37 -07:00
5f75168235 Command-line flag for window resolution
* Added a --window flag to the game executable to specify the startup
  window resolution. Either specify an exact size (e.g. 1024x768) or a
  special keyword "desktop", "mobile" or "landscape"
* Default size is "desktop" or 1024x768
* Mobile simulates a smartphone form factor of 375x812
* Landscape is mobile but flipped horizontally.
* Doodle UX isn't great on mobile but this is a step towards working on
  mobile friendly UI
2020-06-17 18:21:15 -07:00
dabf88dff8 Prepare v0.2.0-alpha for release 2020-06-06 20:52:29 -07:00
8964322f4e Fix doodad edit-doodad args 2020-06-05 00:26:48 -07:00
b0a2524f1a In 'make dist' add a symlink to the latest output 2020-06-05 00:12:27 -07:00
cb155c8750 Fix version parsing on Makefiles 2020-06-05 00:02:06 -07:00
eae7258ce1 Modernize usage of urfave/cli 2020-06-04 23:11:03 -07:00
de896c93e6 Add dummy bindata Go package to help new setup experience 2020-06-04 22:43:37 -07:00
2c032f1df7 Menu Bar Update
* Integrate the new ui.MenuBar into the Editor Scene.
  * File: New Level/Doodad, Save [as], Open, Close, Exit
  * Edit: Undo, Redo, Level options
  * Level: Playtest
  * Tools: Debug overlay, Command shell
  * Help: User Manual, About
* Add an About dialog accessible from the Help menu.
2020-06-04 21:55:54 -07:00
82d50f1c91 Initial Guidebook Documentation 2020-05-22 21:03:01 -07:00
27896a9253 Add Initial Sound Effects
Adds support for sound effects in Doodle and configures some for various
doodads to start out with:

* Buttons and Switches: "Clicked down" and "clicked up" sounds.
* Colored Doors: an "unlocked" sound and a "door opened" sound.
* Electric Door: sci-fi sounds when opening and closing.
* Keys: sound effect for collecting keys.

JavaScript API for Doodads adds a global function `Sound.Play(filename)`
to play sounds. All sounds in the `rtp/sfx/` folder are pre-loaded on
startup for efficient use in the app. Otherwise sounds are lazy-loaded
on first playback.
2020-05-22 20:07:48 -07:00
38614ee280 Tighten Doodad JavaScript API, User Documentation
* Tightens up the surface area of API methods available to the
  JavaScript VMs for doodads. Variables and functions are carefully
  passed in one-by-one so the doodad script can only access intended
  functions and not snoop on undocumented APIs.
* Wrote tons of user documentation for Doodad Scripts: documented the
  full surface area of the exposed JavaScript API now that the surface
  area is known and limited.
* Early WIP code for the Campaign JSON
2020-04-21 23:50:45 -07:00
44788e8032 Prepare v0.1.0-alpha for release 2020-04-12 17:23:04 -07:00
695ff4da42 Collision: Fix clipping thru left walls, w/ caveats
There was a clipping bug where the player could sometimes clip thru a
left-side wall, if the left wall and floor made a 90 degree bend and the
player was holding the Left key while jumping slightly into the wall.

A band-aid that seems to work involved two steps:
1. When capping their leftward movement, add a "+ 1" to the cap.
2. At the start of the point loop, enforce the left cap like we do the
   ceiling cap.

This seems to patch the problem, BUT it breaks the ability to walk up
slopes while moving left. Right-facing slopes can be climbed fine still.

Note: the original bug never was a problem against right walls, only
left ones, but the true root cause was not identified. See TODO comments
in collide_level.go.
2020-04-11 19:21:12 -07:00
d615619aba Bugfix: Don't draw in the level behind open windows
* With the Window Manager update you can open the Level Settings window
  while editing a level, to change its wallpaper or page type. But you
  could "draw" in the level "through" the opened window. This bug is now
  fixed: if the cursor is on top of a managed UI window, the Canvas loop
  is not called.
2020-04-08 18:21:29 -07:00
f0101ba048 The Window Manager Update
* Take advantage of the new Window Manager feature of the UI toolkit.
* Move the MenuScene's "New Level" and "Play/Edit Level" windows into
  stand-alone functions in new pkg/windows/ package. The 'windows'
  package is isolated from the rest of Doodle and communicates using
  config variables and callback functions to avoid circular dependency.
* MenuScene calls the window constructors from the new package.
* Add an "Options" button to the Menu Bar in the Editor Scene, which
  opens the "New Level" window to allow changing the wallpaper or
  bounding type of the level currently being edited.
* Move the cheat codes into their own file, cheats.go
2020-04-06 23:21:17 -07:00
2bd420ff54 Fix getting stuck atop solid doodads
The platformer physics change introduced a regression where the player
character got "stuck" when standing on top of solid doodads.

Fixes #21
2020-04-04 21:21:11 -07:00
08e65c32b5 Overhaul the Platformer Physics System
* Player character now experiences acceleration and friction when
  walking around the map!
* Actor position and movement had to be converted from int's
  (render.Point) to float64's to support fine-grained acceleration
  steps.
* Added "physics" package and physics.Vector to be a float64 counterpart
  for render.Point. Vector is used for uix.Actor.Position() for the sake
  of movement math. Vector is flattened back to a render.Point for
  collision purposes, since the levels and hitboxes are pixel-bound.
* Refactor the uix.Actor to no longer extend the doodads.Drawing (so it
  can have a Position that's a Vector instead of a Point). This broke
  some code that expected `.Doodad` to directly reference the
  Drawing.Doodad: now you had to refer to it as `a.Drawing.Doodad` which
  was ugly. Added convenience method .Doodad() for a shortcut.
* Moved functions like GetBoundingRect() from doodads package to
  collision, where it uses its own slimmer Actor interface for just the
  relevant methods it needs.
2020-04-04 21:00:32 -07:00
c3d7348843 Inventory System for Level Actors
* Added an inventory system for actors as a replacement to the arbitrary
  key/value data store. Colored keys now add themselves to the player's
  inventory, and colored doors check the inventory.
* Inventory is a map[string]int between doodad filenames
  (red-key.doodad) and quantity (0 for key items/unlimited qty).
* API methods to add and remove inventory.
* Items HUD appears in Play Mode in lower-left corner showing doodad
  sprites of all the items in the Player's inventory.
2020-04-02 23:09:46 -07:00
3cb99ad5f8 New (Colored) Locked Door Doodads
* Revamped the sprites for the four colored locked doors. They now have
  a side-view profile perspective rather than a front view.
* Doors open facing the left or the right based on what direction the
  colliding actor approached it from.
2020-04-02 21:43:41 -07:00
f8ca9a0921 Tooltips Update
* Update code for recent changes in UI toolkit around event handlers for
  buttons.
* Add tooltips to various buttons in the Editor Mode. The left toolbar
  shows the names of each tool, the Doodad Palette shows the title of
  each doodad and the Color Palette shows the swatch attributes (solid,
  fire, water, etc.)
2020-03-09 22:22:22 -07:00
7142c76b86 Initial Guidebook code 2020-03-09 22:21:59 -07:00
b4922edf5d Doodad Tool: Add Tag Support for edit-doodad
* The `doodad edit-doodad` command now allows setting custom key/value
  tags in doodad files, for extra data storage useful to their scripts.
* Colored keys and doors now store a `color` tag with the appropriate
  color so that their scripts don't have to parse their Title to find
  that information.
* Trapdoors now store a `direction` tag to hold the direction the door
  is facing.
2020-01-02 22:12:20 -08:00
0e3a30e633 Fix Actor Collision Checks Again
* Recent collision update caused a regression where the player would get
  "stuck" while standing on top of a solid doodad, unable to walk left
  or right.
* When deciding if the actor is on top of a doodad, use the doodad's
  Hitbox (if available) instead of the bounding box. This fixes the
  upside-down trapdoor acting solid when landed on from the top, since
  its Hitbox Y coordinate is not the same as the top of its sprite.
* Cheats: when using the noclip cheat in Play Mode, you can hold down
  the Shift key while moving to only move one pixel at a time.
2020-01-02 22:05:49 -08:00
a43e45fad0 Level Collision and Scrolling Fixes
* Fix the level collision bug that allowed clipping thru a ceiling while
  climbing up a wall.
* Fix the scrolling behavior to keep the character on-screen no matter
  how fast the character is moving, especially downwards.
* Increase player speed and gravity.
* New cheat: "ghost mode" disables clipping for the player character.
* Mark an actor as "grounded" if they fall and are stopped by the lower
  level border, so they may jump again.
2020-01-02 20:23:27 -08:00
7b3aec0fef Fix Two-State Blocks & Collision Detection
* Two-state Buttons now also subscribe to the state change message, so
  other on/off buttons in the same level update to match the state of
  the button that was hit.
* Add lock mutexes around the scripting engine to protect from
  concurrent event handlers.
2020-01-02 17:58:22 -08:00
cd31868a13 Add app version/update check to the Main Scene 2020-01-01 17:50:15 -08:00
8965a7d86a Doodads: Crumbly Floor, Start Flag & State Blocks
Add new doodads:

* Start Flag: place this in a level to set the spawn point of the player
  character. If no flag is found, the player spawns at 0,0 in the top
  corner of the map. Only use one Start Flag per level, otherwise the
  player will randomly spawn at one of them.
* Crumbly Floor: a solid floor that begins to shake and then fall apart
  after a moment when a mobile character steps on it. The floor respawns
  after 5 seconds.
* State Blocks: blue and orange blocks that toggle between solid and
  pass-thru whenever a State Button is activated.
* State Button: a solid "ON/OFF" block that toggles State Blocks back
  and forth when touched. Only activates if touched on the side or bottom;
  acts as a solid floor when walked on from the top.

New features for doodad scripts:

* Actor scripts: call SetMobile(true) to mark an actor as a mobile mob
  (i.e. player character or enemy). Other doodads can check if the actor
  colliding with them IsMobile so they don't activate if placed too close
  to other (non-mobile) doodads in a level. The Blue and Red Azulians
  are the only mobile characters so far.
* Message.Broadcast allows sending a pub/sub message out to ALL doodads
  in the level, instead of only to linked doodads as Message.Publish does.
  This is used for the State Blocks to globally communicate on/off status
  without needing to link them all together manually.
2019-12-30 18:13:28 -08:00
c08a1bc13e PlayScene: Set the Edit Button's position correctly 2019-12-29 00:01:47 -08:00
b924ea9467 UI: Renamed Anchor -> Side for frame packing layout 2019-12-28 21:48:49 -08:00
0437adfbf8 Change types int32 -> int per upstream render and ui library 2019-12-27 19:16:34 -08:00
c1353d1c0f Split lib/ui into its own separate repo 2019-12-27 16:32:26 -08:00
a060330450 Switch to external git.kirsle.net/go/ui package 2019-12-27 16:31:58 -08:00
d658359240 Switch github.com/kirsle/golog to git.kirsle.net/go/log
* New logger module supports js/wasm build by skipping the dependency on
  ssh/terminal (which detected interactive consoles, not applicable to
  JS). In WASM the logs go to the browser console and ANSI color codes
  not needed.
2019-12-22 18:34:31 -08:00
ea0b41a781 Cut lib/render into its own package, change all imports 2019-12-22 18:21:58 -08:00
2adffd56c6 Update wasm_exec.js from latest Go release 2019-12-22 18:15:09 -08:00
7355778a39 render: Refactor Events System to Make Module Standalone
* Refactor the events used in lib/render/sdl to be more general-purpose
  to make librender a stand-alone library separate from Doodle.
2019-12-22 14:11:01 -08:00
3634577f19 Prepare v0.0.10-alpha for release 2019-07-17 18:22:59 -07:00
32db95ea85 MacOS .app Bundle
* Add a shell script to generate a MacOS .app bundle for proper
  distribution.
2019-07-17 18:10:13 -07:00
65a811db0d Auto-prune Empty Chunks in Level Files
* Discovered a bug where if you hit the Undo key to erase pixels and an
  entire chunk became empty by it, the chunk would have rendering errors
  and show as a solid black square instead of the level wallpaper
  showing through.
* Chunks that have no pixels in them are culled from the chunker
  immediately when you call a Delete() operation.
* The level file saver also calls a maintenance function to prune all
  empty chunks upon saving the file. So existing levels with broken
  chunks need only be re-saved to fix them.
2019-07-16 22:10:18 -07:00
6af60f1128 Improve Collision Detection: More Active w/ Actors
* Improve the collision detection algorithm so that Actor OnCollide
  scripts get called more often WHILE an actor is moving, to prevent a
  fast-moving actor from zipping right through the "solid" hitbox and
  not giving the subject actor time to protest the movement.
* It's implemented by adding a `Settled` boolean to the OnCollide event
  object. When the game is testing out movement, Settled=false to give
  the actor a chance to say "I'm solid!" and have the moving party be
  stopped early.
* After all this is done, for any pair of actors still with overlapping
  hitboxes, OnCollide is called one last time with Settled=true. This is
  when the actor should run its actions (like publishing messages to
  other actors, changing state as in a trapdoor, etc.)
* The new collision detection algorithm works as follows:
  * Stage 1 is the same as before, all mobile actors are moved and
    tested against level geometry. They record their Original and New
    position during this phase.
  * Stage 2 is where we re-run that movement but ping actors being
    intersected each step of the way. We trace the steps between
    Original and New position, test OnCollide handler, and if it returns
    false we move the mobile actor to the Last Good Position along the
    trace.
  * Stage 3 we run the final OnCollide(Settled=true) to let actors run
    actions they wanted to for their collide handler, WITHOUT spamming
    those actions during Stage 2.
* This should now allow for tweaking of gravity speed and player speed
  without breaking all actor collision checking.
2019-07-16 21:07:38 -07:00
17b18b8c0a Better Ellipse Drawing Algorithm 2019-07-16 18:27:00 -07:00
0c6c77a423 Lemon-shaped Ellipse Tool (WIP)
* Add initial Ellipse Tool to the Editor Mode. Currently there's
  something wrong with the algorithm and the ellipses have a sort of
  'lemon shape' to them.
* Refactor the IterLine/IterLine2 functions to be more consistent.
  IterLine used to be the raw algorithm that took a bunch of coordinate
  numbers and IterLine2 took two render.Point's and was the main one
  used throughout the app. Now, IterLine takes the two Points and the
  raw algorithm function removed.
2019-07-14 14:18:44 -07:00
cc1e441232 Eraser Tool, Brush Sizes
* Implement Brush Sizes for drawtool.Stroke and add a UI to the tools panel
  to control the brush size.
  * Brush sizes: 1, 2, 4, 8, 16, 24, 32, 48, 64
* Add the Eraser Tool to editor mode. It uses a default brush size of 16
  and a max size of 32 due to some performance issues.
* The Undo/Redo system now remembers the original color of pixels when
  you change them, so that Undo will set them back how they were instead
  of deleting the pixel entirely. Due to performance issues, this only
  happens when your Brush Size is 0 (drawing single-pixel shapes).
* UI: Add an IntVariable option to ui.Label to bind showing the value of
  an int reference.

Aforementioned performance issues:

* When we try to remember whole rects of pixels for drawing thick
  shapes, it requires a ton of scanning for each step of the shape. Even
  de-duplicating pixel checks, tons of extra reads are constantly
  checked.
* The Eraser is the only tool that absolutely needs to be able to
  remember wiped pixels AND have large brush sizes. The performance
  sucks and lags a bit if you erase a lot all at once, but it's a
  trade-off for now.
* So pixels aren't remembered when drawing lines in your level with
  thick brushes, so the Undo action will simply delete your pixels and not
  reset them. Only the Eraser can bring back pixels.
2019-07-11 19:07:46 -07:00
7317615318 Add fpm script to make RPM and Deb packages 2019-07-09 20:09:01 -07:00
329adb76d9 Add Open Source Licenses 2019-07-08 19:12:25 -07:00
0126c288b2 Minor Build Script Updates, Mac OS Support
* Update the Makefile to choose MacOS friendly `date` formats.
* Build the Windows doodle.exe binary as a GUI application to skip the
  console window.
* Added Mac OS build instructions.
2019-07-08 18:16:45 -07:00
154fc6c9cb Update Doodad build-scripts to tag extra data
* The Blue Azulian marks its doodad file as Hidden.
* All Doodads are write locked after generation and tagged with common
  author value.
2019-07-06 23:50:38 -07:00
fd649b7ab1 Doodad CLI Tool Features; Write Lock and Hidden
* The `doodad` CLI tool got a lot of new commands:
  * `doodad show` to verbosely print details about Levels and Doodads.
  * `edit-level` and `edit-doodad` to update details about Levels and
    Doodads, such as their Title, Author, page type and size, etc.
* Doodads gain a `Hidden bool` that hides them from the palette in
  Editor Mode. The player character (Blue Azulian) is Hidden.
* Add some boolProps to the balance/ package and made a dynamic system
  to easily configure these with the in-game dev console.
  * Command: `boolProp list` returns available balance.boolProps
  * `boolProp <name>` returns the current value.
  * `boolProp <name> <true or false>` sets the value.
* The new boolProps are:
  * showAllDoodads: enable Hidden doodads on the palette UI (NOTE:
    reload the editor to take effect)
  * writeLockOverride: edit files that are write locked anyway
  * prettyJSON: pretty-format the JSON files saved by the game.
2019-07-06 23:28:11 -07:00
6476a67faf Make Fire Deadly
* Touching "fire" pixels in a level will pop up the End Level alert box
  saying you've died by fire and can restart the level.
* Update level.WriteFile() to prune broken links between actors before
  save. So when a linked actor is deleted, the leftover link data is
  cleaned up.
* Slight optimization in Canvas.drawStrokes: if either end of the stroke
  is not within view of the screen, don't show the stroke.
2019-07-06 20:31:50 -07:00
cb02feff1d Add Switches, Fire/Water Collision and Play Menu
* New doodads: Switches.
  * They come in four varieties: wall switch (background element, with
    "ON/OFF" text) and three side-profile switches for the floor, left
    or right walls.
  * On collision with the player, they flip their state from "OFF" to
    "ON" or vice versa. If the player walks away and then collides
    again, the switch flips again.
  * Can be used to open/close Electric Doors when turned on/off. Their
    default state is "off"
  * If a switch receives a power signal from another linked switch, it
    sets its own state to match. So, two "on/off" switches that are
    connected to a door AND to each other will both flip on/off when one
    of them flips.
* Update the Level Collision logic to support Decoration, Fire and Water
  pixel collisions.
  * Previously, ALL pixels in the level were acting as though solid.
  * Non-solid pixels don't count for collision detection, but their
    attributes (fire and water) are collected and returned.
* Updated the MenuScene to support loading a map file in Play Mode
  instead of Edit Mode. Updated the title screen menu to add a button
  for playing levels instead of editing them.
* Wrote some documentation.
2019-07-06 18:30:03 -07:00
a504658055 Centralized Tick Counter, Fix Actor Dragging Bug
* The game's tick counter was moved from Doodle.ticks to shmem.Tick
  where it is more easily available from every corner of the code.
* Fix a bug in the Level Editor where dragging an already-existing actor
  from one part of your map to another, would cause it to lose all its
  data (especially its UUID), breaking links to other doodads. Now the
  existing Actor catches a ride on the drag object to be reinserted
  later.
* Animate the Link Line visualizers between actors. They now animate a
  blinking color between magenta and grey-ish.
2019-07-05 16:04:36 -07:00
dc2695cfc9 Add More Trapdoor Doodads
* Add the other trapdoor directions: Left, Right and Up.
* UI: Show a color square in each Palette Swatch button in Edit Mode.
  * Instead of just the label like "solid", "fire", "decoration" it also
    shows a square box colored as the swatch color. The label and box
    are left-aligned in the button.
* Minor Play Mode physics update:
  * The player jump is now limited: they may only continue to move
    upwards for 20 ticks, after which they must touch ground before
    jumping again.
  * Remove the "press Down to move down" button. Only gravity moves you
    down.
* Fix a crash in the Editor Mode when you dragged doodads on top of each
  other. Source of bug was the loopActorCollision() function, which only
  should be useful to Play Mode, and it expected the scripting engine to
  be attached to the Canvas. In EditorMode there is no scripting engine.
2019-07-05 15:02:22 -07:00
22440f436b Add Scrolling in the Doodad Palette Window
* Rudimentary scrolling shows a Left and Right button at the top of the
  Doodad Palette if your window is deemed not tall enough to contain all
  of the doodads.
* A "progress bar" is shown between the buttons indicating the
  percentage of your scroll down the doodad list. When you're able to
  see the final row of doodads, the progress bar is at 100%.
2019-07-03 21:55:15 -07:00
12d34517e9 Add Tool Bar to Editor Mode
* Toolbar has icon buttons for the Pencil Tool, Line Tool, Rect Tool,
  Actor Tool and Link Tool.
* Remove the tab buttons from the top of the Palette window. The palette
  tab is now toggled between Swatches and Doodads by the tool selected
  on the tool bar, instead of the tab buttons setting the tool.
* Remove the "Link Doodads" button from the Doodad Palette. The Link
  Tool has its own dedicated toolbar button with the others.
2019-07-03 20:24:04 -07:00
5a1ec156ca Editor Mode: Line Tool and Rectangle Tool
* Add support for the LineTool and RectTool while in the EditorMode to
  easily draw straight lines and rectangle outlines.
* Key bindings were added to toggle tools in lieu of a proper UI to
  select the tool from a toolbar.
  * "F" for Pencil (Freehand) Tool (since "P" is for "Playtest")
  * "L" for Line Tool
  * "R" for Rectangle Tool
2019-07-03 17:19:25 -07:00
5d8c5510d8 Draw Lines Visualizing Doodad Links in Edit Mode
* If the current edit tool is Actor or Link, use the new drawtool.Stroke
  object to draw visual lines connecting every pair of linked actors in
  the level. The lines are hidden during normal editing and gameplay and
  only appear when you're possibly manipulating your actors and links.
2019-07-03 16:51:23 -07:00
c8620f871e Drawing Strokes and Undo/Redo Functionality
* Add new pkg/drawtool with utilities to abstract away drawing actions
  into Strokes and track undo/redo History for them.
* The freehand Pencil tool in EditorMode has been refactored to create a
  Stroke of Shape=Freehand and queue up its world pixels there instead
  of directly modifying the level chunker in real time. When the mouse
  button is released, the freehand Stroke is committed to the level
  chunker and added to the UndoHistory.
* UndoHistory is (temporarily) stored with the level.Level so it can
  survive trips to PlayScene and back, but is not stored as JSON on
  disk.
* Ctrl-Z and Ctrl-Y in EditorMode for undo and redo, respectively.
2019-07-03 16:25:23 -07:00
0c22ecae5e Level Exit Doodad
* Add a Level Exit doodad, which for now is a little blue flag on a pole
  that reads "END"
* JavaScript API: global function EndLevel() will end the level. The
  exit doodad calls this when touched by the player.
* Add a "Level Completed" alert box UI to PlayScene with dynamic button
  layouts.
  * The alert box pops up when a doodad calls EndLevel() and contains
    action buttons what to do next.
  * "Play Again" restarts the current level again.
  * "Edit Level" if you came from the EditorScene; otherwise this button
    is not visible.
  * "Next Level" is a to-be-implemented button to advance in the single
    player story mode. Only shows up when PlayScene.HasNext=true.
  * "Exit to Menu" is always visible and closes out to the MainScene.
2019-07-02 15:24:46 -07:00
3d08291bc5 Demo Running Level as Title Screen Wallpaper
* Load SDL2 fonts from go-bindata storage so we don't have to ship
  external font files on disk.
* Dedupe names of doodads so we don't show double on the front-end
  (go-bindata bundled doodads + those on local filesystem)
* Use go-bindata for accessing wallpaper images.
* Better flashed messages walking you through the Link Tool.
* Stylize the title screen (MainScene) by rendering a live example level
  as the background wallpaper, with mobile doodads in motion.
2019-06-27 22:59:36 -07:00
54776ec9e1 Makefile Love and Windows Bugfixes
* Fixed a bad filepath separator check that failed on Windows.
* Disable ANSI colors in logger for Windows console.
2019-06-27 20:24:13 -07:00
35a89e5dbe WASM: Store User Files in localStorage
* In WASM build, user levels and doodads are written to localStorage
  using their userdir path as keys (".config/levels/test.level")
* LoadFile() and WriteFile() for both Levels and Doodads interact with
  the localStorage for WASM build instead of filesystem for desktop.
* userdir.ListLevels() and ListDoodads() for WASM scan the localStorage
  keys for file names.
* userdir.ResolvePath() now works for WASM (previously was dummied out),
  checks for the file in localStorage.
2019-06-27 15:59:18 -07:00
b17ca34de2 Bindata: Embedding Doodads and Levels (for WASM)
* Use `go-bindata` to embed built-in doodads and levels directly into
  the Doodle binary. `make bindata` produces the bindata source file.
* Add `FromJSON()` method to Levels and Doodads to load objects from
  JSON strings in memory (for bindata built-ins or WASM ajax requests)
* Update file loading functions to check the embedded bindata files.
  * pkg/config.go#EditFile:
    * Supports editing a level from bindata (TODO: remove this support)
    * If the "assets/levels/%(simple-name.level)" exists in bindata,
      edits that drawing.
    * No such support for editing built-in doodads.
    * WASM has no filesystem access to edit files except built-in
      levels (yet)
  * pkg/doodads#ListDoodads:
    * Prepends built-in doodads from bindata to the returned list.
    * WASM: no filesystem access so gets only the built-ins.
  * pkg/doodads#LoadFile:
    * Checks built-in bindata store first for doodad files.
    * WASM: tries an HTTP request if not found in bindata but can go no
      further if not found (no filesystem access)
  * pkg/filesystem#FindFile:
    * This function finds a level/doodad by checking all the places.
    * If the level or doodad exists in bindata built-in, always returns
      its system path like "assets/doodads/test.doodad"
    * WASM: always returns the built-in candidate path even if not found
      in bindata so that ajax GET can be attempted.
  * pkg/level#ListSystemLevels:
    * New function that lists the system level files, similar to the
      equivalent doodads function.
    * Prepends the bindata built-in level files.
    * WASM: only returns the built-ins (no filesystem support)
    * Desktop: also lists and returns the assets/levels/ directory.
  * pkg/level#LoadFile:
    * Like the doodads.LoadFile, tries from built-in bindata first, then
      ajax request (WASM) before accessing the filesystem (desktop)
* Menu Scene: TODO, list the built-in levels in the Load Level menu.
  This feature will soon go away when WASM gets its own storage for user
  levels (localStorage instead of filesystem)
2019-06-27 15:07:34 -07:00
c7cc40a339 Refactor Render Texture-Cache Interface
Since SDL2 is using in-memory bitmaps the same as Canvas engine, the
function names of the render.Engine interface have been cleaned up:

* NewTexture(filename, image) -> StoreTexture(name, image)
  Create a new cached texture with a given name.
* NewBitmap(filename) -> LoadTexture(name)
  Recall a stored texture with a given name.
* level.Chunk.ToBitmap uses simpler names for the textures instead of
  userdir.CacheFilename file-like paths.
2019-06-27 13:01:01 -07:00
3d199ca263 SDL2: Cache Bitmaps in Memory, Not on Disk
* Update the SDL2 engine's texture caching to use an sdl.RWops file
  buffer in memory instead of outputting bitmap images to the
  filesystem.
2019-06-27 12:46:35 -07:00
ba6892aa95 WASM Texture Caching
* Refactor texture caching in render.Engine:
  * New interface method: NewTexture(filename string, image.Image)
  * WASM immediately encodes the image to PNG and generates a JavaScript
    `Image()` object to load it with a data URI and keep it in memory.
  * SDL2 saves the bitmap to disk as it did before.
  * WASM: deprecate the sessionStorage for holding image data. Session
    storage methods panic if called. The image data is directly kept in
    Go memory as a js.Value holding an Image().
* Shared Memory workaround: the level.Chunk.ToBitmap() function is where
  chunk textures get cached, but it had no access to the render.Engine
  used in the game. The `pkg/shmem` package holds global pointers to
  common structures like the CurrentRenderEngine as a work-around.
  * Also shmem.Flash() so Doodle can make its d.Flash() function
    globally available, any sub-package can now flash text to the screen
    regardless of source code location.
  * JavaScript API for Doodads now has a global Flash() function
    available.
* WASM: Handle window resize so Doodle can recompute its dimensions
  instead of scaling/shrinking the view.
2019-06-27 12:03:52 -07:00
48fc40ade4 Texture Caching for WASM Canvas Engine
* Add RGBA color blending support in WASM build.
* Initial texture caching API for Canvas renderer engine. The WASM build
  writes the chunk caches as a "data:image/png" base64 URL on the
  browser's sessionStorage, for access to copy into the Canvas.
* Separated the ClickEvent from the MouseEvent (motion) in the WASM
  event queue system, to allow clicking and dragging.
* Added the EscapeKey handler, which will abruptly terminate the WASM
  application, same as it kills the window in the desktop build.
* Optimization fix: I discovered that if the user clicks and holds over
  a single pixel when drawing a level, repeated Set() operations were
  firing meaning multiple cache invalidations. Not noticeable on PC but
  on WebAssembly it crippled the browser. Now if the cursor isn't moving
  it doesn't do anything.
2019-06-26 22:44:08 -07:00
c5c85330de WASM Event Queue
* Refactor the event system in the WASM render engine to serialize the
  async JavaScript events into a channel, so that queued events are read
  off serially in the main loop similar to SDL. This fixes keyboard
  input issues, altho if you type really fast some input keys get lost.
2019-06-26 20:33:24 -07:00
af67b20d9b Initial WebAssembly Build Target
* Initial WebAssembly build target for Doodle in the wasm/ folder.
* Add a new render.Engine implementation, lib/render/canvas that uses
  the HTML 5 Canvas API instead of SDL2 for the WebAssembly target.
  * Ported the basic DrawLine(), DrawBox() etc. functions from SDL2 to
    Canvas context2d API.
  * Fonts are handled with CSS embedded fonts named after the font
    filename and defined in wasm/index.html
* `make wasm` builds the WASM program, and `make wasm-serve` runs a dev
  Go server that hosts the WASM file for development. The server also
  watches the dev tree for *.go files and rebuilds the WASM binary
  automatically on change.
* This build "basically" runs the game. UI and fonts all work and mouse
  movements and clicks are detected. No wallpaper support yet or texture
  caching (which will crash the game as soon as you click and draw a
  pixel in your map!)
2019-06-26 18:40:40 -07:00
8d855582ed Clean up documentation 2019-06-25 18:58:48 -07:00
9efe16582c Add Play/Edit Buttons to Toggle Between Modes
* Instead of needing to press the "P" and "E" keys to toggle from edit
  mode to play mode (and back again), respectively, the UI now draws a
  "Play (P)" or "Edit (E)" button on the bottom right corner of the
  level canvas. Clicking it will toggle the mode.
2019-06-25 18:36:53 -07:00
4c2e8eca49 Add blank white wallpaper 2019-06-25 18:10:57 -07:00
c7fee43f54 New Wallpapers: Legal Pad and Blueprint 2019-06-25 17:48:17 -07:00
3d3561b8e6 Blueprint Theme Palette
* Fix the EditorUI not showing the correct palette baked into the level
  and only showing the default. This was tricky because the palette UI
  can only be configured at setup time but not updated later.
* Add a new default palette for the Blueprint theme. Blueprint has a
  dark background, so the palette colors should be bright. This palette
  is chosen when you start a map with the blueprint wallpaper.
* Add a background Canvas to the MenuScene. In the "New Level" screen,
  the background canvas will update to show the wallpaper settings
  you've chosen as a preview of the level theme you're about to create.
2019-06-25 17:43:23 -07:00
7281fcbf91 Add "Load Drawing" Menu UI
* To the MenuScene add the "Load Drawing" window UI.
* Displays the user's Levels and Doodads using rows of buttons, 4
  buttons per row. Clicking the button loads the EditorScene with that
  filename.
* Free Version does not display the Doodads label or button on this
  menu screen.
2019-06-25 15:23:01 -07:00
4dd1bebc5f Add MenuScene with New Level UI
* Debug mode: no longer enables the DebugOverlay (F3) by default, but
  does now insert the current FPS counter into the window title bar.
* ui.Frame: set a default "mostly transparent" BG color so the frame
  background doesn't render as white.
* Add the MenuScene which will house the game's main menus.
* The "New Level" menu is first to be added.
  * UI lets you pick Page Type and Wallpaper using radio buttons.
  * Page Type: Unbounded, Bounded (default), No Negative Space, Bordered
  * Fix bugs in uix.Canvas to fully support all these page types.
2019-06-25 15:01:37 -07:00
1150d6d3e9 Add Branding Module for Centralized Game Info
* Moves the game's Title, Summary and Version into pkg/branding where it
  is centrally controlled.
2019-06-23 17:52:48 -07:00
99eab19c5b Pub/Sub Messages Between Linked Actors (JavaScript)
* Implement the pub/sub message passing system that lets the JavaScript
  VM of one actor (say, a Button) send messages to other linked actors
  in the level (say, an Electric Door)
* Buttons now emit a "power(true)" message while pressed and
  "power(false)" when released. Sticky Buttons do not release and so do
  not send the power(false) message.
* Electric Doors listen for the "power" event and open or close
  themselves based on the boolean value received.
* If a Sticky Button receives power and is currently pressed down, it
  will pop back up (reset to "off" position) and notify its linked
  actors that they have lost power too. So if a Sticky Button held an
  Electric Door open, and another Button powers the Sticky Button, it
  would pop back up and also close the Electric Door.
2019-06-23 17:34:11 -07:00
87416f9740 Link Tool UX
* On the Doodads tab is the Link button to enter the Link Tool.
* Click Link, then click the 1st doodad on the level, then click the 2nd
  doodad to complete the link.
* The actors struct in the Level holds the link IDs for each actor.
2019-06-23 16:15:09 -07:00
b06c52a705 UI: Add MainWindow Widget and start an example app
* MainWindow is ideal for apps that just want a UI and
  don't manage their own SDL windows.
* The example app will grow into a series of demos that
  test the UI toolkit to help fix bugs and grow features.
2019-06-08 17:03:59 -07:00
567b3158f1 Minor Tweaks 2019-06-08 17:02:28 -07:00
de79bde776 Add silly cheat codes to make Play Mode editable 2019-05-28 22:34:54 -07:00
1523deeb9c Return False: Solid Collision Between Actors
* Implement the handler code for `return false` when actors are
  colliding with each other and wish to act like solid walls.
* The locked doors will `return false` when they're closed and the
  colliding actor does not have the matching key.
* Add arbitrary key/value storage to Actors. The colored keys will set
  an actor value "key:%TITLE%" on the one who touched the key before
  destroying itself. The colored doors check that key when touched to
  decide whether to open.
* The trapdoor now only opens if you're touching it from the top (your
  overlap box Y value is 0), but if you touch it from below and the door
  is closed, it acts like a solid object.
2019-05-28 21:43:30 -07:00
a2e1bd1ccb Improve OnCollide Doodad Script Handling
* Events.OnCollide now receives a CollideEvent object, which makes
  available the .Actor who collided and the .Overlap rect which is
  zero-relative to the target actor. Doodad scripts can use the .Overlap
  to see WHERE in their own box the other actor has intruded.
  * Update the LockedDoor and ElectricDoor doodads to detect when the
    player has entered their inner rect (since their doors are narrower
    than their doodad size)
  * Update the Button doodads to only press in when the player actually
    touches them (because their sizes are shorter than their doodad
    height)
  * Update the Trapdoor to only trigger its animation when the board
    along its top has been touched, not when the empty space below was
    touched from the bottom.
* Events.OnLeave now implemented and fires when an actor who was
  previously intersecting your doodad has left.
* The engine detects when an event JS callback returns false.
  Eventually, the OnCollide can return false to signify the collision is
  not accepted and the actor should be bumped away as if they hit solid
  geometry.
2019-05-06 22:58:09 -07:00
61af068b80 Load Balance Collision and Actor Loop Across CPU Cores
* Add sync.WaitGroup to some parts of the level collision detection
  function and Canvas.Loop() to speed up the frame rate by load
  balancing some work in parallel across multiple cores.
* Improves FPS from 30 to 55+ even for busy scenes with lots of mobile
  enemies walking around.
* Before the level collision optimization, framerate would sometimes dip
  to 30 FPS simply to move the player character on a completely blank
  map!
2019-05-06 17:06:40 -07:00
d28745f89e Mobile Enemy Doodad Test
* Add a Red Azulian as a test for mobile enemies.
  * Its A.I. has it walk back and forth, changing directions when it
    comes up against an obstacle for a few moments.
  * It plays walking animations and can trigger collision events with
    other Doodads, such as the Electric Door and Trapdoor.
* Move Gravity responsibility to the doodad scripts themselves.
  * Call `Self.SetGravity(true)` to opt the Doodad in to gravity.
  * The canvas.Loop() adds gravity to any doodad that has it enabled.
2019-05-06 16:30:45 -07:00
a73dec9f31 Doodad Animations Managed In-Engine
* Add animation support for Doodad actors (Play Mode) into the core
  engine, so that the Doodad script can register named animations and
  play them without managing all the details themselves.
  * Doodad API functions on Self: AddAnimation, PlayAnimation,
    StopAnimation, IsAnimating
* CLI: the `doodad convert` command will name each layer after the
  filename used as the input image.
* CLI: fix the `doodad convert` command creating duplicate Palette
  colors when converting a series of input images into a Doodad.
2019-05-06 15:30:43 -07:00
ac490473b3 Load Doodads from System Path as well as User Path 2019-05-06 13:35:08 -07:00
f76ba6fbb7 WIP: MsgPack stubs, Level Filesystem Module
* Add some encoding/decoding functions for binary msgpack format for
  levels and doodads. Currently it writes msgpack files that can be
  decoded and printed by Python (mp2json.py) but it can't re-read from
  the binary format. For now, levels will continue to write in JSON
  format.
* Add filesystem abstraction functions to the balance/ package to search
  multiple paths to find Levels and Doodads, to make way for
  system-level doodads.
2019-05-06 12:41:46 -07:00
d042457365 Use Azulian doodad as player character instead of empty dummy 2019-05-01 18:30:30 -07:00
af35703df0 Add Azulian doodad sprites and build script 2019-05-01 18:27:20 -07:00
693664db6c Shareware Build Flags
* Build the app with -tags="shareware" to compile the free/shareware
  build of the game.
* `make build-free` compiles both binaries to the bin/ folder in
  shareware mode.
* The constant balance.FreeVersion is true in the shareware build and
  all functionality related to the Doodad Editor UI mode is disabled
  in this build mode.
2019-04-19 17:23:37 -07:00
52a2545692 Remove ScreenshotKey Event, Add F* Key Handlers
* The F3 key now toggles the Debug Overlay, which is now OFF by default.
* The F4 key now toggles the Debug Collision Boxes feature.
2019-04-19 16:21:04 -07:00
2a162a86dd UI: Fix packing bug in the GUITest 2019-04-19 15:08:00 -07:00
412 changed files with 39361 additions and 5736 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
bin/*
dist/*

11
.gitignore vendored
View File

@ -1,7 +1,18 @@
pkg/bindata/bindata.go
deps/
fonts/ fonts/
maps/ maps/
bin/ bin/
dist/ dist/
rtp/
guidebook/
docker-artifacts/
wasm/assets/
*.wasm
*.doodad
*.level
*.levelpack
*.AppImage
docker/ubuntu docker/ubuntu
docker/debian docker/debian
docker/fedora docker/fedora

View File

@ -1,9 +1,226 @@
# Building Doodle # Building Doodle
Makefile commands for Linux: - [Building Doodle](#building-doodle)
- [Dockerfile](#dockerfile)
- [Automated Release Scripts](#automated-release-scripts)
- [Go Environment](#go-environment)
- [Quickstart with bootstrap.py](#quickstart-with-bootstrappy)
- [Detailed Instructions](#detailed-instructions)
- [Fonts](#fonts)
- [Makefile](#makefile)
- [Dependencies](#dependencies)
- [Flatpak for Linux](#flatpak-for-linux)
- [Windows Cross-Compile from Linux](#windows-cross-compile-from-linux)
- [Windows DLLs](#windows-dlls)
- [Build on macOS from scratch](#build-on-macos-from-scratch)
- [WebAssembly](#webassembly)
- [Build Tags](#build-tags)
- [doodad](#doodad)
- [dpp](#dpp)
# Dockerfile
The Dockerfile in this git repo may be the quickest way to fully
release the game for as many platforms as possible. Run it from a
64-bit host Linux system and it will generate Linux and Windows
releases for 64-bit and 32-bit Intel CPUs.
It depends on your git clone of doodle to be fully initialized
(e.g., you have run the bootstrap.py script and a `make dist`
would build a release for your current system, with doodads and
runtime assets all in the right places).
Run `make docker` and the results will be in the
`artifacts/release` folder in your current working directory.
**Fedora notes (SELinux):** if you run this from a Fedora host
you will need to `sudo setenforce permissive` to allow the
Dockerfile to mount the artifacts/release folder to export its
results.
# Automated Release Scripts
Other Dockerfiles and scripts used to release the game:
* [SketchyMaze/docker](https://git.kirsle.net/SketchyMaze/docker) provides a Dockerfile
that fully end-to-end releases the latest version of the game for Linux and Windows. 64bit and 32bit versions that freshly clone the
game from git and output their respective CPU release artifacts:
* Windows: .zip file
* Linux: .tar.gz, .rpm, .deb
* [flatpak](https://code.sketchymaze.com/game/flatpak) is a Flatpak manifest for
Linux distributions.
The Docker container depends on all the git servers being up, but if you have
the uber blob source code you can read the Dockerfile to see what it does.
# Go Environment
Part of the build scripts involve building and running the `doodad` command
from this repo in order to generate the game's built-in doodads. For this to
work smoothly from your Linux or macOS build environment, you may need to
ensure that your `${GOPATH}/bin` directory is on your `$PATH` by, for example,
configuring this in your bash/zsh profile:
```bash
export GOPATH="${HOME}/go"
export PATH="${PATH}:${GOPATH}/bin"
```
For a complete example, see the "Build on macOS from scratch" section below.
# Quickstart with bootstrap.py
From any Unix-like system (Fedora, Ubuntu, macOS) the bootstrap.py script
is intended to set this app up, from scratch, _fast._ The basic steps are:
```bash
# Example from an Ubuntu 20.04 LTS fresh install running in a
# libvirt-manager virtual machine on a Fedora host.
# 1. Ensure your SSH keys have git clone permission for git.kirsle.net.
# For example just scp my keys from the host Fedora machine.
$ scp -r kirsle@192.168.122.1:.ssh/id_rsa* ~/.ssh/
# 2. git clone the Project Doodle repository.
$ git clone git@git.kirsle.net:apps/doodle
$ cd ./doodle
# 3. Run the bootstrap script.
$ python3 bootstrap.py
```
The bootstrap script will take care of the rest:
* `apt install` all the dependencies (golang, SDL2, etc.)
* `git clone` various other repositories into a "deps/" folder in doodle's
directory. These are things like my Go render library `go/render` and
`go/ui` as well as the doodle-rtp runtime package (sound effects, etc.)
all of which are hosted on git.kirsle.net.
* Build and install the `doodad` tool so it can generate the builtin
doodads, and build and release a full distribution of the game.
It should work on Fedora-likes, Debian-likes and macOS all the same.
It even runs on the Pine64 Pinephone (ARM64) with Mobian!
MacOS is expected to have [homebrew](https://brew.sh) installed.
MP3 support issues? [See here](https://github.com/veandco/go-sdl2/issues/299#issuecomment-611681191).
**To do:** the most important repositories, like the game itself, are
also mirrored on GitHub. Other supporting repos need mirroring too, or
otherwise, full source tarballs (the result of bootstrap.py) will be
built and archived somewhere safe for posterity in case git.kirsle.net
ever goes away. The doodle mirror is at <https://github.com/SketchyMaze/doodle>
(private repository) and the others are there too (go/render, go/ui, etc.)
# Detailed Instructions
For building the app the hard way, and in-depth instructions, read
this section. You'll need the following git repositories:
* `git.kirsle.net/SketchyMaze/doodle` - the game engine.
* `git.kirsle.net/SketchyMaze/assets` - where built-in level files are kept (optional)
* `git.kirsle.net/SketchyMaze/vendor` - vendored libraries for Windows (SDL2.dll etc.)
* `git.kirsle.net/SketchyMaze/rtp` - runtime package (sounds and music mostly)
* `git.kirsle.net/SketchyMaze/doodads` - sources to compile the built-in doodads.
The [docker](https://git.kirsle.net/SketchyMaze/docker) repo will
be more up-to-date than the instructions below, as that repo actually has
runnable code in the Dockerfile!
```bash
# Clone all the repos down to your project folder
git clone https://git.kirsle.net/SketchyMaze/rtp rtp
git clone https://git.kirsle.net/SketchyMaze/vendor vendor
git clone https://git.kirsle.net/SketchyMaze/masters masters
git clone https://git.kirsle.net/SketchyMaze/doodle doodle
git clone https://git.kirsle.net/SketchyMaze/doodads doodle/deps/doodads
# Enter doodle/ project
cd doodle/
# Copy fonts and levels in
cp ../assets/levelpacks assets/levelpacks
cp ../vendor/fonts assets/fonts
mkdir rtp && cp -r ../rtp/* rtp/
# From the doodle repo:
make setup # -or-
go get ./... # install dependencies etc.
# The app should build now. Build and install the doodad tool.
go install git.kirsle.net/SketchyMaze/doodle/cmd/doodad
doodad --version
# "doodad version 0.3.0-alpha build ..."
# Build and release the game into the dist/ folder.
# This will: generate builtin doodads, bundle them with bindata,
# and create a tarball in the dist/ folder.
make dist
# Build a cross-compiled Windows target from Linux.
# (you'd run before `make dist` to make an uber release)
make mingw
# After make dist, `make release` will carve up Linux
# and Windows (mingw) builds and zip them up nicely.
make release
```
`make build` produces a local binary in the bin/ folder and `make dist`
will build an app for distribution in the dist/ folder.
The bootstrap.py script does all of the above up to `make dist` so if you need
fully release the game by hand (e.g. on a macOS host) you can basically get away
with:
1. Clone the doodle repo and cd into it
2. Run `bootstrap.py` to fully set up your OS with dependencies and build a
release quality version of the game with all latest assets (the script finishes
with a `make dist`).
3. Run `make release` to package the dist/ artifact into platform specific
release artifacts (.rpm/.deb/.tar.gz bundles for Linux, .zip for Windows,
.dmg if running on macOS) which output into the dist/release/ folder.
Before step 3 you may want to download the latest Guidebook to bundle with
the game (optional). Grab and extract the tarball and run `make dist && make release`:
```bash
wget -O - https://download.sketchymaze.com/guidebook.tar.gz | tar -xzvf -
```
## Fonts
The `fonts/` folder is git-ignored. The app currently uses font files here
named:
* `DejaVuSans.ttf` for sans-serif font.
* `DejaVuSans-Bold.ttf` for bold sans-serif font.
* `DejaVuSansMono.ttf` for monospace font.
These are the open source **DejaVu Sans [Mono]** fonts, so copy them in from
your `/usr/share/fonts/dejavu` folder or provide alternative fonts.
```bash
mkdir fonts
cp /usr/share/fonts/dejavu/{DejaVuSans.ttf,DejaVuSans-Bold.ttf,DejaVuSansMono.ttf} fonts/
```
The doodle-vendor repo has copies of these fonts.
## Makefile
Makefile commands for Unix-likes:
* `make setup`: install Go dependencies and set up the build environment * `make setup`: install Go dependencies and set up the build environment
* `make doodads`: build the default Doodads from sources in `deps/doodads/`
* `make build`: build the Doodle and Doodad binaries to the `bin/` folder. * `make build`: build the Doodle and Doodad binaries to the `bin/` folder.
* `make buildall`: runs all build steps: doodads, build.
* `make build-free`: build the shareware binaries to the `bin/` folder. See
Build Tags below.
* `make build-debug`: build a debug binary (not release-mode) to the `bin/`
folder. See Build Tags below.
* `make wasm`: build the WebAssembly output
* `make wasm-serve`: build the WASM output and then run the server.
* `make run`: run a local dev build of Doodle in debug mode * `make run`: run a local dev build of Doodle in debug mode
* `make guitest`: run a local dev build in the GUITest scene * `make guitest`: run a local dev build in the GUITest scene
* `make test`: run the test suite * `make test`: run the test suite
@ -17,18 +234,28 @@ Makefile commands for Linux:
* `make docker.fedora` * `make docker.fedora`
* `make clean`: clean all build artifacts * `make clean`: clean all build artifacts
## Linux # Dependencies
Dependencies are Go, SDL2 and SDL2_ttf: The bootstrap.py script lists dependencies for Fedora, Debian and macOS.
Also here for clarity, hopefully not out-of-date:
```bash ```bash
# Fedora # Fedora-likes
sudo dnf -y install golang SDL2-devel SDL2_ttf-devel sudo dnf install make golang SDL2-devel SDL2_ttf-devel \
SDL2_mixer-devel
# Ubuntu and Debian # Debian and Ubuntu
sudo apt -y install golang libsdl2-dev libsdl2-ttf-dev sudo dnf install make golang libsdl2-dev libsdl2-ttf-dev \
libsdl2-mixer-dev
# macOS via Homebrew (https://brew.sh)
brew install golang sdl2 sdl2_ttf sdl2_mixer pkg-config
``` ```
## Flatpak for Linux
The repo for this is at <https://git.kirsle.net/SketchyMaze/flatpak>.
## Windows Cross-Compile from Linux ## Windows Cross-Compile from Linux
Install the Mingw C compiler: Install the Mingw C compiler:
@ -75,3 +302,108 @@ cp /usr/x86_64-w64-mingw32/bin/SDL*.dll bin/
SDL2_ttf requires libfreetype, you can get its DLL here: SDL2_ttf requires libfreetype, you can get its DLL here:
https://github.com/ubawurinna/freetype-windows-binaries https://github.com/ubawurinna/freetype-windows-binaries
## Build on macOS from scratch
Here are some detailed instructions how to build Sketchy Maze from a fresh
install of macOS Ventura that assumes no previous software or configuration
was applied to the system yet.
Install homebrew: https://brew.sh pay attention to the instructions at the end
of the install to set up your zsh profile for homebrew to work correctly.
Clone the doodle repository:
```bash
git clone https://git.kirsle.net/SketchyMaze/doodle
cd doodle
```
Note: on a fresh install, invoking the `git` command may cause macOS to install
developer tools and Xcode. After installed, run the git clone again to finish
cloning the repository.
Set your Go environment variables: edit your ~/.zprofile and ensure that $GOPATH
is configured and that your $PATH includes $GOPATH/bin. **Note:** restart your
terminal session or reload the config file (e.g. `. ~/.zprofile`) after making
this change.
```bash
# in your .zprofile, .bash_profile, .zshrc or similar shell config
export GOPATH="${HOME}/go"
export PATH="${PATH}:${GOPATH}/bin"
```
Run the bootstrap script:
```bash
python3 bootstrap.py
```
Answer N (default) when asked to clone dependency repos over ssh. The bootstrap
script will `brew install` any necessary dependencies (Go, SDL2, etc.) and clone
support repos for the game (doodads, levelpacks, assets).
# WebAssembly
There is some **experimental** support for a WebAssembly build of Sketchy Maze
since the very early days. Early on, the game "basically worked" but performance
could be awful: playing levels was OK but clicking and dragging in the editor
would cause your browser to freeze. Then for a time, the game wouldn't even get
that far. Recently (December 2023), WASM performance seems much better but there
are strange graphical glitches:
* On the title screen, the example levels in the background load OK and their
doodads will wander around and performance seems OK.
* But during Play Mode, only the menu bar draws but nothing else on the screen.
* In the Level Editor, the entire screen is white BUT tooltips will appear and
the menu bar can be clicked on (blindly) and the drop-down menus do appear.
Some popups like the Palette Editor can be invoked and draw to varying degrees
of success.
Some tips to get a WASM build to work:
* For fonts: symlink it so that ./wasm/fonts points to ./assets/fonts.
* You may need an updated wasm_exec.js shim from Go. On Fedora,
`dnf install golang-misc` and `cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .`
from the wasm/ folder.
* Run `make wasm` to build the WASM binary and `make wasm-serve` to run a simple
Go web server to serve it from.
# Build Tags
Go build tags used by this game:
## doodad
This tag is used when building the `doodad` command-line tool.
It ensures that the embedded bindata assets (built-in doodads, etc.) do not
need to be bundled into the doodad binary, but only the main game binary.
## dpp
The dpp tag stands for Doodle++ and is used for official commercial builds of
the game. Doodle++ builds include additional code not found in the free & open
source release of the game engine.
This build tag should be set automatically by the Makefile **if** the deps/
folder has a git clone of the dpp project. The bootstrap.py script will clone
the dpp repo **if** you use SSH to clone dependencies: so you will need SSH
credentials to the upstream git server. It basically means that third-party
users who download the open source release will not have the dpp dependency,
and will not build dpp copies of the game.
If you _do_ have the dpp dependency, you can force build (and run) FOSS
versions of the game via the Makefile commands `make build-free`,
`make run-free` or `make dist-free` which are counterparts to the main make
commands but which deliberately do not set the dpp build tag.
In source code, files ending with `_dpp.go` and `_foss.go` are conditionally
compiled depending on this build tag.
How to tell whether your build of Sketchy Maze is Doodle++ include:
* The version string on the title screen.
* FOSS builds (not dpp) will say "open source" in the version.
* DPP builds may say "shareware" if unregistered or just the version.

1277
Changes.md

File diff suppressed because it is too large Load Diff

121
Dockerfile Normal file
View File

@ -0,0 +1,121 @@
##
# Fully build and distribute Linux and Windows binaries for Project: Doodle.
#
# This is designed to be run from a fully initialized Doodle environment
# (you had run the bootstrap.py for your system, and the doodads and
# levelpacks are installed in the assets/ folder, and `make dist` would
# build a release quality game for your local machine).
#
# It will take your working directory (minus any platform-specific artifacts
# and git repos cloned in to your deps/ folder) and build them from a sane
# Debian base and generate full release artifacts for:
#
# - Linux (x86_64 and i686) as .rpm, .deb, .flatpak and .tar.gz
# - Windows (64-bit and 32-bit) as .zip
#
# Artifact outputs will be in the dist/mw/ folder.
##
FROM debian:latest AS build64
ENV GOPATH /go
ENV GOPROXY direct
ENV PATH /opt/go/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/go/bin
# Install all dependencies.
RUN apt update && apt -y install git zip tar libsdl2-dev libsdl2-ttf-dev \
libsdl2-mixer-dev gcc-mingw-w64-x86-64 gcc make wget \
flatpak-builder ruby-dev gcc rpm libffi-dev \
ruby-dev ruby-rubygems rpm libffi-dev rsync file
RUN gem install fpm; exit 0
# Download and install modern Go.
WORKDIR /root
RUN wget https://go.dev/dl/go1.21.4.linux-amd64.tar.gz -O go.tgz && \
tar -xzf go.tgz && \
cp -r go /opt/go
# Add some cacheable directories to speed up Dockerfile trial-and-error.
ADD deps/vendor /SketchyMaze/deps/vendor
# MinGW setup for Windows executable cross-compile.
WORKDIR /SketchyMaze/deps/vendor/mingw-libs
RUN for i in *.tar.gz; do tar -xzvf $i; done
RUN cp -r SDL2-2.0.9/x86_64-w64-mingw32 /usr && \
cp -r SDL2_mixer-2.0.4/x86_64-w64-mingw32 /usr && \
cp -r SDL2_ttf-2.0.15/x86_64-w64-mingw32 /usr
RUN mkdir -p /usr/lib/golang/pkg/windows_amd64
WORKDIR /SketchyMaze
RUN mkdir -p bin && cp deps/vendor/DLL/*.dll bin/
# Add the current working directory (breaks the docker cache every time).
ADD . /SketchyMaze
# Fetch the guidebook.
# RUN sh -c '[[ ! -d ./guidebook ]] && wget -O - https://download.sketchymaze.com/guidebook.tar.gz | tar -xzvf -'
# Use go-winres on the Windows exe (embed application icons)
RUN go install github.com/tc-hib/go-winres@latest && go-winres make
# Revert any local change to go.mod (replace lines)
RUN git checkout -- go.mod
# Install Go dependencies and do the thing:
# - builds the program for Linux
# - builds for Windows via MinGW
# - runs `make dist/` creating an uber build for both OS's
# - runs release.sh to carve out the Linux and Windows versions and
# zip them all up nicely.
RUN make setup && make from-docker64
# Collect the build artifacts.
RUN mkdir -p artifacts && cp -rv dist/release ./artifacts/
###
# 32-bit Dockerfile version of the above
###
FROM i386/debian:latest AS build32
ENV GOPATH /go
ENV GOPROXY direct
ENV PATH /opt/go/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/go/bin
# Dependencies, note the w64-i686 difference to the above
RUN apt update && apt -y install git zip tar libsdl2-dev libsdl2-ttf-dev \
libsdl2-mixer-dev gcc-mingw-w64-i686 gcc make wget \
flatpak-builder ruby-dev gcc rpm libffi-dev \
ruby-dev ruby-rubygems rpm libffi-dev rsync file
RUN gem install fpm; exit 0
# Download and install modern Go.
WORKDIR /root
RUN wget https://go.dev/dl/go1.19.3.linux-386.tar.gz -O go.tgz && \
tar -xzf go.tgz && \
cp -r go /opt/go
COPY --from=build64 /SketchyMaze /SketchyMaze
# MinGW setup for Windows executable cross-compile.
WORKDIR /SketchyMaze/deps/vendor/mingw-libs
RUN for i in *.tar.gz; do tar -xzvf $i; done
RUN cp -r SDL2-2.0.9/i686-w64-mingw32 /usr && \
cp -r SDL2_mixer-2.0.4/i686-w64-mingw32 /usr && \
cp -r SDL2_ttf-2.0.15/i686-w64-mingw32 /usr
RUN mkdir -p /usr/lib/golang/pkg/windows_386
WORKDIR /SketchyMaze
RUN mkdir -p bin && cp deps/vendor/DLL-32bit/*.dll bin/
# Do the thing.
RUN make setup && make from-docker32
# Collect the build artifacts.
RUN mkdir -p artifacts && cp -rv dist/release ./artifacts/
###
# Back to (64bit) base for the final CMD to copy artifacts out.
###
FROM debian:latest
COPY --from=build32 /SketchyMaze /SketchyMaze
CMD ["cp", "-r", "-v", \
"/SketchyMaze/artifacts/release/", \
"/mnt/export/"]

View File

@ -76,10 +76,10 @@ The major milestones of the game are roughly:
* Colors are not tied to behaviors. Each "Swatch" on the palette has its own * Colors are not tied to behaviors. Each "Swatch" on the palette has its own
color and a set of boolean flags for `solid`, `fire` and `water` behaviors. color and a set of boolean flags for `solid`, `fire` and `water` behaviors.
* [ ] User interface to edit (add/remove) swatches from the palette. * [ ] User interface to edit (add/remove) swatches from the palette.
* [ ] A Toolbox window with radio buttons to select between various drawing tools. * [x] A Toolbox window with radio buttons to select between various drawing tools.
* [x] Pencil (the default) draws single pixels on the level. * [x] Pencil (the default) draws single pixels on the level.
* [ ] Rectangle would draw a rectangular outline. * [x] Rectangle would draw a rectangular outline.
* [ ] Line would draw a line from point to point. * [x] Line would draw a line from point to point.
* [ ] A way to adjust brush properties: * [ ] A way to adjust brush properties:
* [ ] Brush size, shape (round or square). * [ ] Brush size, shape (round or square).
* [ ] Tools to toggle "layers" of visibility into your level: * [ ] Tools to toggle "layers" of visibility into your level:
@ -98,11 +98,11 @@ The major milestones of the game are roughly:
For creating Doodads in particular: For creating Doodads in particular:
* [ ] Make a way to enter Edit Mode in either "Level Mode" or "Doodad Mode", * [x] Make a way to enter Edit Mode in either "Level Mode" or "Doodad Mode",
i.e. by a "New Level" or "New Doodad" button. i.e. by a "New Level" or "New Doodad" button.
* [ ] Create a "frame manager" window to see and page between the frames of the * [ ] Create a "frame manager" window to see and page between the frames of the
drawing. drawing.
* [ ] Ability to work on canvases with constrained size (including smaller than * [x] Ability to work on canvases with constrained size (including smaller than
your window). This will use a Canvas widget in the UI toolkit as an abstraction your window). This will use a Canvas widget in the UI toolkit as an abstraction
layer. Small canvases will be useful for drawing doodads of a fixed size. layer. Small canvases will be useful for drawing doodads of a fixed size.

636
LICENSE.md Normal file
View File

@ -0,0 +1,636 @@
# GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 [Free Software Foundation, Inc.](http://fsf.org/)
Everyone is permitted to copy and distribute verbatim copies of this license
document, but changing it is not allowed.
## Preamble
The GNU General Public License is a free, copyleft license for software and
other kinds of works.
The licenses for most software and other practical works are designed to take
away your freedom to share and change the works. By contrast, the GNU General
Public License is intended to guarantee your freedom to share and change all
versions of a program--to make sure it remains free software for all its users.
We, the Free Software Foundation, use the GNU General Public License for most
of our software; it applies also to any other work released this way by its
authors. You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the freedom to
distribute copies of free software (and charge for them if you wish), that you
receive source code or can get it if you want it, that you can change the
software or use pieces of it in new free programs, and that you know you can do
these things.
To protect your rights, we need to prevent others from denying you these rights
or asking you to surrender the rights. Therefore, you have certain
responsibilities if you distribute copies of the software, or if you modify it:
responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for
a fee, you must pass on to the recipients the same freedoms that you received.
You must make sure that they, too, receive or can get the source code. And you
must show them these terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps:
1. assert copyright on the software, and
2. offer you this License giving you legal permission to copy, distribute
and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that
there is no warranty for this free software. For both users' and authors' sake,
the GPL requires that modified versions be marked as changed, so that their
problems will not be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified
versions of the software inside them, although the manufacturer can do so. This
is fundamentally incompatible with the aim of protecting users' freedom to
change the software. The systematic pattern of such abuse occurs in the area of
products for individuals to use, which is precisely where it is most
unacceptable. Therefore, we have designed this version of the GPL to prohibit
the practice for those products. If such problems arise substantially in other
domains, we stand ready to extend this provision to those domains in future
versions of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents. States
should not allow patents to restrict development and use of software on
general-purpose computers, but in those that do, we wish to avoid the special
danger that patents applied to a free program could make it effectively
proprietary. To prevent this, the GPL assures that patents cannot be used to
render the program non-free.
The precise terms and conditions for copying, distribution and modification
follow.
## TERMS AND CONDITIONS
### 0. Definitions.
*This License* refers to version 3 of the GNU General Public License.
*Copyright* also means copyright-like laws that apply to other kinds of works,
such as semiconductor masks.
*The Program* refers to any copyrightable work licensed under this License.
Each licensee is addressed as *you*. *Licensees* and *recipients* may be
individuals or organizations.
To *modify* a work means to copy from or adapt all or part of the work in a
fashion requiring copyright permission, other than the making of an exact copy.
The resulting work is called a *modified version* of the earlier work or a work
*based on* the earlier work.
A *covered work* means either the unmodified Program or a work based on the
Program.
To *propagate* a work means to do anything with it that, without permission,
would make you directly or secondarily liable for infringement under applicable
copyright law, except executing it on a computer or modifying a private copy.
Propagation includes copying, distribution (with or without modification),
making available to the public, and in some countries other activities as well.
To *convey* a work means any kind of propagation that enables other parties to
make or receive copies. Mere interaction with a user through a computer
network, with no transfer of a copy, is not conveying.
An interactive user interface displays *Appropriate Legal Notices* to the
extent that it includes a convenient and prominently visible feature that
1. displays an appropriate copyright notice, and
2. tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the work
under this License, and how to view a copy of this License.
If the interface presents a list of user commands or options, such as a menu, a
prominent item in the list meets this criterion.
### 1. Source Code.
The *source code* for a work means the preferred form of the work for making
modifications to it. *Object code* means any non-source form of a work.
A *Standard Interface* means an interface that either is an official standard
defined by a recognized standards body, or, in the case of interfaces specified
for a particular programming language, one that is widely used among developers
working in that language.
The *System Libraries* of an executable work include anything, other than the
work as a whole, that (a) is included in the normal form of packaging a Major
Component, but which is not part of that Major Component, and (b) serves only
to enable use of the work with that Major Component, or to implement a Standard
Interface for which an implementation is available to the public in source code
form. A *Major Component*, in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system (if any) on
which the executable work runs, or a compiler used to produce the work, or an
object code interpreter used to run it.
The *Corresponding Source* for a work in object code form means all the source
code needed to generate, install, and (for an executable work) run the object
code and to modify the work, including scripts to control those activities.
However, it does not include the work's System Libraries, or general-purpose
tools or generally available free programs which are used unmodified in
performing those activities but which are not part of the work. For example,
Corresponding Source includes interface definition files associated with source
files for the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require, such as
by intimate data communication or control flow between those subprograms and
other parts of the work.
The Corresponding Source need not include anything that users can regenerate
automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
### 2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on
the Program, and are irrevocable provided the stated conditions are met. This
License explicitly affirms your unlimited permission to run the unmodified
Program. The output from running a covered work is covered by this License only
if the output, given its content, constitutes a covered work. This License
acknowledges your rights of fair use or other equivalent, as provided by
copyright law.
You may make, run and propagate covered works that you do not convey, without
conditions so long as your license otherwise remains in force. You may convey
covered works to others for the sole purpose of having them make modifications
exclusively for you, or provide you with facilities for running those works,
provided that you comply with the terms of this License in conveying all
material for which you do not control copyright. Those thus making or running
the covered works for you must do so exclusively on your behalf, under your
direction and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the
conditions stated below. Sublicensing is not allowed; section 10 makes it
unnecessary.
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure
under any applicable law fulfilling obligations under article 11 of the WIPO
copyright treaty adopted on 20 December 1996, or similar laws prohibiting or
restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention is
effected by exercising rights under this License with respect to the covered
work, and you disclaim any intention to limit operation or modification of the
work as a means of enforcing, against the work's users, your or third parties'
legal rights to forbid circumvention of technological measures.
### 4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it,
in any medium, provided that you conspicuously and appropriately publish on
each copy an appropriate copyright notice; keep intact all notices stating that
this License and any non-permissive terms added in accord with section 7 apply
to the code; keep intact all notices of the absence of any warranty; and give
all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may
offer support or warranty protection for a fee.
### 5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it
from the Program, in the form of source code under the terms of section 4,
provided that you also meet all of these conditions:
- a) The work must carry prominent notices stating that you modified it, and
giving a relevant date.
- b) The work must carry prominent notices stating that it is released under
this License and any conditions added under section 7. This requirement
modifies the requirement in section 4 to *keep intact all notices*.
- c) You must license the entire work, as a whole, under this License to
anyone who comes into possession of a copy. This License will therefore
apply, along with any applicable section 7 additional terms, to the whole
of the work, and all its parts, regardless of how they are packaged. This
License gives no permission to license the work in any other way, but it
does not invalidate such permission if you have separately received it.
- d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your work need
not make them do so.
A compilation of a covered work with other separate and independent works,
which are not by their nature extensions of the covered work, and which are not
combined with it such as to form a larger program, in or on a volume of a
storage or distribution medium, is called an *aggregate* if the compilation and
its resulting copyright are not used to limit the access or legal rights of the
compilation's users beyond what the individual works permit. Inclusion of a
covered work in an aggregate does not cause this License to apply to the other
parts of the aggregate.
### 6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4
and 5, provided that you also convey the machine-readable Corresponding Source
under the terms of this License, in one of these ways:
- a) Convey the object code in, or embodied in, a physical product (including
a physical distribution medium), accompanied by the Corresponding Source
fixed on a durable physical medium customarily used for software
interchange.
- b) Convey the object code in, or embodied in, a physical product (including
a physical distribution medium), accompanied by a written offer, valid for
at least three years and valid for as long as you offer spare parts or
customer support for that product model, to give anyone who possesses the
object code either
1. a copy of the Corresponding Source for all the software in the product
that is covered by this License, on a durable physical medium
customarily used for software interchange, for a price no more than your
reasonable cost of physically performing this conveying of source, or
2. access to copy the Corresponding Source from a network server at no
charge.
- c) Convey individual copies of the object code with a copy of the written
offer to provide the Corresponding Source. This alternative is allowed only
occasionally and noncommercially, and only if you received the object code
with such an offer, in accord with subsection 6b.
- d) Convey the object code by offering access from a designated place
(gratis or for a charge), and offer equivalent access to the Corresponding
Source in the same way through the same place at no further charge. You
need not require recipients to copy the Corresponding Source along with the
object code. If the place to copy the object code is a network server, the
Corresponding Source may be on a different server operated by you or a
third party) that supports equivalent copying facilities, provided you
maintain clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the Corresponding
Source, you remain obligated to ensure that it is available for as long as
needed to satisfy these requirements.
- e) Convey the object code using peer-to-peer transmission, provided you
inform other peers where the object code and Corresponding Source of the
work are being offered to the general public at no charge under subsection
6d.
A separable portion of the object code, whose source code is excluded from the
Corresponding Source as a System Library, need not be included in conveying the
object code work.
A *User Product* is either
1. a *consumer product*, which means any tangible personal property which is
normally used for personal, family, or household purposes, or
2. anything designed or sold for incorporation into a dwelling.
In determining whether a product is a consumer product, doubtful cases shall be
resolved in favor of coverage. For a particular product received by a
particular user, *normally used* refers to a typical or common use of that
class of product, regardless of the status of the particular user or of the way
in which the particular user actually uses, or expects or is expected to use,
the product. A product is a consumer product regardless of whether the product
has substantial commercial, industrial or non-consumer uses, unless such uses
represent the only significant mode of use of the product.
*Installation Information* for a User Product means any methods, procedures,
authorization keys, or other information required to install and execute
modified versions of a covered work in that User Product from a modified
version of its Corresponding Source. The information must suffice to ensure
that the continued functioning of the modified object code is in no case
prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as part of a
transaction in which the right of possession and use of the User Product is
transferred to the recipient in perpetuity or for a fixed term (regardless of
how the transaction is characterized), the Corresponding Source conveyed under
this section must be accompanied by the Installation Information. But this
requirement does not apply if neither you nor any third party retains the
ability to install modified object code on the User Product (for example, the
work has been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates for a
work that has been modified or installed by the recipient, or for the User
Product in which it has been modified or installed. Access to a network may be
denied when the modification itself materially and adversely affects the
operation of the network or violates the rules and protocols for communication
across the network.
Corresponding Source conveyed, and Installation Information provided, in accord
with this section must be in a format that is publicly documented (and with an
implementation available to the public in source code form), and must require
no special password or key for unpacking, reading or copying.
### 7. Additional Terms.
*Additional permissions* are terms that supplement the terms of this License by
making exceptions from one or more of its conditions. Additional permissions
that are applicable to the entire Program shall be treated as though they were
included in this License, to the extent that they are valid under applicable
law. If additional permissions apply only to part of the Program, that part may
be used separately under those permissions, but the entire Program remains
governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any
additional permissions from that copy, or from any part of it. (Additional
permissions may be written to require their own removal in certain cases when
you modify the work.) You may place additional permissions on material, added
by you to a covered work, for which you have or can give appropriate copyright
permission.
Notwithstanding any other provision of this License, for material you add to a
covered work, you may (if authorized by the copyright holders of that material)
supplement the terms of this License with terms:
- a) Disclaiming warranty or limiting liability differently from the terms of
sections 15 and 16 of this License; or
- b) Requiring preservation of specified reasonable legal notices or author
attributions in that material or in the Appropriate Legal Notices displayed
by works containing it; or
- c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in reasonable
ways as different from the original version; or
- d) Limiting the use for publicity purposes of names of licensors or authors
of the material; or
- e) Declining to grant rights under trademark law for use of some trade
names, trademarks, or service marks; or
- f) Requiring indemnification of licensors and authors of that material by
anyone who conveys the material (or modified versions of it) with
contractual assumptions of liability to the recipient, for any liability
that these contractual assumptions directly impose on those licensors and
authors.
All other non-permissive additional terms are considered *further restrictions*
within the meaning of section 10. If the Program as you received it, or any
part of it, contains a notice stating that it is governed by this License along
with a term that is a further restriction, you may remove that term. If a
license document contains a further restriction but permits relicensing or
conveying under this License, you may add to a covered work material governed
by the terms of that license document, provided that the further restriction
does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place,
in the relevant source files, a statement of the additional terms that apply to
those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a
separately written license, or stated as exceptions; the above requirements
apply either way.
### 8. Termination.
You may not propagate or modify a covered work except as expressly provided
under this License. Any attempt otherwise to propagate or modify it is void,
and will automatically terminate your rights under this License (including any
patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a
particular copyright holder is reinstated
- a) provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and
- b) permanently, if the copyright holder fails to notify you of the
violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated
permanently if the copyright holder notifies you of the violation by some
reasonable means, this is the first time you have received notice of violation
of this License (for any work) from that copyright holder, and you cure the
violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses
of parties who have received copies or rights from you under this License. If
your rights have been terminated and not permanently reinstated, you do not
qualify to receive new licenses for the same material under section 10.
### 9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy
of the Program. Ancillary propagation of a covered work occurring solely as a
consequence of using peer-to-peer transmission to receive a copy likewise does
not require acceptance. However, nothing other than this License grants you
permission to propagate or modify any covered work. These actions infringe
copyright if you do not accept this License. Therefore, by modifying or
propagating a covered work, you indicate your acceptance of this License to do
so.
### 10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a
license from the original licensors, to run, modify and propagate that work,
subject to this License. You are not responsible for enforcing compliance by
third parties with this License.
An *entity transaction* is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered work
results from an entity transaction, each party to that transaction who receives
a copy of the work also receives whatever licenses to the work the party's
predecessor in interest had or could give under the previous paragraph, plus a
right to possession of the Corresponding Source of the work from the
predecessor in interest, if the predecessor has it or can get it with
reasonable efforts.
You may not impose any further restrictions on the exercise of the rights
granted or affirmed under this License. For example, you may not impose a
license fee, royalty, or other charge for exercise of rights granted under this
License, and you may not initiate litigation (including a cross-claim or
counterclaim in a lawsuit) alleging that any patent claim is infringed by
making, using, selling, offering for sale, or importing the Program or any
portion of it.
### 11. Patents.
A *contributor* is a copyright holder who authorizes use under this License of
the Program or a work on which the Program is based. The work thus licensed is
called the contributor's *contributor version*.
A contributor's *essential patent claims* are all patent claims owned or
controlled by the contributor, whether already acquired or hereafter acquired,
that would be infringed by some manner, permitted by this License, of making,
using, or selling its contributor version, but do not include claims that would
be infringed only as a consequence of further modification of the contributor
version. For purposes of this definition, *control* includes the right to grant
patent sublicenses in a manner consistent with the requirements of this
License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent
license under the contributor's essential patent claims, to make, use, sell,
offer for sale, import and otherwise run, modify and propagate the contents of
its contributor version.
In the following three paragraphs, a *patent license* is any express agreement
or commitment, however denominated, not to enforce a patent (such as an express
permission to practice a patent or covenant not to sue for patent
infringement). To *grant* such a patent license to a party means to make such
an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the
Corresponding Source of the work is not available for anyone to copy, free of
charge and under the terms of this License, through a publicly available
network server or other readily accessible means, then you must either
1. cause the Corresponding Source to be so available, or
2. arrange to deprive yourself of the benefit of the patent license for this
particular work, or
3. arrange, in a manner consistent with the requirements of this License, to
extend the patent license to downstream recipients.
*Knowingly relying* means you have actual knowledge that, but for the patent
license, your conveying the covered work in a country, or your recipient's use
of the covered work in a country, would infringe one or more identifiable
patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you
convey, or propagate by procuring conveyance of, a covered work, and grant a
patent license to some of the parties receiving the covered work authorizing
them to use, propagate, modify or convey a specific copy of the covered work,
then the patent license you grant is automatically extended to all recipients
of the covered work and works based on it.
A patent license is *discriminatory* if it does not include within the scope of
its coverage, prohibits the exercise of, or is conditioned on the non-exercise
of one or more of the rights that are specifically granted under this License.
You may not convey a covered work if you are a party to an arrangement with a
third party that is in the business of distributing software, under which you
make payment to the third party based on the extent of your activity of
conveying the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory patent
license
- a) in connection with copies of the covered work conveyed by you (or copies
made from those copies), or
- b) primarily for and in connection with specific products or compilations
that contain the covered work, unless you entered into that arrangement, or
that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied
license or other defenses to infringement that may otherwise be available to
you under applicable patent law.
### 12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not excuse
you from the conditions of this License. If you cannot convey a covered work so
as to satisfy simultaneously your obligations under this License and any other
pertinent obligations, then as a consequence you may not convey it at all. For
example, if you agree to terms that obligate you to collect a royalty for
further conveying from those to whom you convey the Program, the only way you
could satisfy both those terms and this License would be to refrain entirely
from conveying the Program.
### 13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have permission to
link or combine any covered work with a work licensed under version 3 of the
GNU Affero General Public License into a single combined work, and to convey
the resulting work. The terms of this License will continue to apply to the
part which is the covered work, but the special requirements of the GNU Affero
General Public License, section 13, concerning interaction through a network
will apply to the combination as such.
### 14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU
General Public License from time to time. Such new versions will be similar in
spirit to the present version, but may differ in detail to address new problems
or concerns.
Each version is given a distinguishing version number. If the Program specifies
that a certain numbered version of the GNU General Public License *or any later
version* applies to it, you have the option of following the terms and
conditions either of that numbered version or of any later version published by
the Free Software Foundation. If the Program does not specify a version number
of the GNU General Public License, you may choose any version ever published by
the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the
GNU General Public License can be used, that proxy's public statement of
acceptance of a version permanently authorizes you to choose that version for
the Program.
Later license versions may give you additional or different permissions.
However, no additional obligations are imposed on any author or copyright
holder as a result of your choosing to follow a later version.
### 15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
PARTIES PROVIDE THE PROGRAM *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
CORRECTION.
### 16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS
PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY
HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
### 17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot
be given local legal effect according to their terms, reviewing courts shall
apply local law that most closely approximates an absolute waiver of all civil
liability in connection with the Program, unless a warranty or assumption of
liability accompanies a copy of the Program in return for a fee.
## END OF TERMS AND CONDITIONS ###
### How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible
use to the public, the best way to achieve this is to make it free software
which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach
them to the start of each source file to most effectively state the exclusion
of warranty; and each file should have at least the *copyright* line and a
pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like
this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w` and `show c` should show the appropriate
parts of the General Public License. Of course, your program's commands might
be different; for a GUI interface, you would use an *about box*.
You should also get your employer (if you work as a programmer) or school, if
any, to sign a *copyright disclaimer* for the program, if necessary. For more
information on this, and how to apply and follow the GNU GPL, see
[http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
The GNU General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may consider
it more useful to permit linking proprietary applications with the library. If
this is what you want to do, use the GNU Lesser General Public License instead
of this License. But first, please read
[http://www.gnu.org/philosophy/why-not-lgpl.html](http://www.gnu.org/philosophy/why-not-lgpl.html).

186
Makefile
View File

@ -1,41 +1,159 @@
SHELL := /bin/bash SHELL := /bin/bash
VERSION=$(shell grep -e 'Version =' pkg/doodle.go | head -n 1 | cut -d '"' -f 2) VERSION=$(shell egrep -e 'Version\s+=' pkg/branding/branding.go | head -n 1 | cut -d '"' -f 2)
BUILD=$(shell git describe --always) BUILD=$(shell git describe --always)
BUILD_DATE=$(shell date -Iseconds) BUILD_DATE=$(shell date +"%Y-%m-%dT%H:%M:%S%z")
CURDIR=$(shell curdir) CURDIR=$(shell curdir)
# Inject the build version (commit hash) into the executable. # Inject the build version (commit hash) into the executable.
LDFLAGS := -ldflags "-X main.Build=$(BUILD) -X main.BuildDate=$(BUILD_DATE)" LDFLAGS := -ldflags "-X main.Build=$(BUILD) -X main.BuildDate=$(BUILD_DATE)"
LDFLAGS_W := -ldflags "-X main.Build=$(BUILD) -X main.BuildDate=$(BUILD_DATE) -H windowsgui"
# Doodle++ build tag for official builds of the game.
BUILD_TAGS := -tags=""
ifneq ("$(wildcard ./deps/dpp)", "")
BUILD_TAGS = -tags="dpp"
endif
# `make setup` to set up a new environment, pull dependencies, etc. # `make setup` to set up a new environment, pull dependencies, etc.
.PHONY: setup .PHONY: setup
setup: clean setup: clean
go get ./...
# `make build` to build the binary. # `make build` to build the binary.
.PHONY: build .PHONY: build
build: build:
go build $(LDFLAGS) $(BUILD_TAGS) -o bin/sketchymaze cmd/doodle/main.go
go build $(LDFLAGS) -tags=doodad -o bin/doodad cmd/doodad/main.go
# `make buildall` to run all build steps including doodads.
.PHONY: buildall
buildall: doodads build
# `make build-free` to build the binary in free mode.
.PHONY: build-free
build-free:
gofmt -w . gofmt -w .
go build $(LDFLAGS) -i -o bin/doodle cmd/doodle/main.go go build $(LDFLAGS) -o bin/sketchymaze cmd/doodle/main.go
go build $(LDFLAGS) -i -o bin/doodad cmd/doodad/main.go go build $(LDFLAGS) -tags=doodad -o bin/doodad cmd/doodad/main.go
# `make bindata` generates the embedded binary assets package.
.PHONY: bindata
bindata:
echo "make bindata: deprecated in favor of Go 1.16 embed; nothing was done"
# `make bindata-dev` generates the debug version of bindata package.
.PHONY: bindata-dev
bindata-dev:
echo "make bindata-dev: deprecated in favor of Go 1.16 embed; nothing was done"
# `make wasm` builds the WebAssembly port.
.PHONY: wasm
wasm:
cd wasm && make
# `make wasm-serve` builds and launches the WebAssembly server.
.PHONY: wasm-serve
wasm-serve: wasm
sh -c 'sleep 1; xdg-open http://localhost:8080/' &
cd wasm && go run server.go
# `make install` to install the Go binaries to your GOPATH.
.PHONY: install
install:
go install git.kirsle.net/SketchyMaze/doodle/cmd/...
# `make doodads` to build the doodads from the deps/doodads folder.
.PHONY: doodads
doodads:
cd deps/doodads && ./build.sh > /dev/null
# `make mingw` to cross-compile a Windows binary with mingw. # `make mingw` to cross-compile a Windows binary with mingw.
.PHONY: mingw .PHONY: mingw
mingw: mingw:
env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS) -i -o bin/doodle.exe cmd/doodle/main.go go build $(LDFLAGS_W) $(BUILD_TAGS) -o bin/sketchymaze.exe cmd/doodle/main.go
env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS) -i -o bin/doodad.exe cmd/doodad/main.go go build $(LDFLAGS) -tags=doodad -o bin/doodad.exe cmd/doodad/main.go
# `make mingw32` to cross-compile a Windows binary with mingw (32-bit).
.PHONY: mingw32
mingw32:
env CGO_ENABLED="1" CC="/usr/bin/i686-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS_W) $(BUILD_TAGS) -o bin/sketchymaze.exe cmd/doodle/main.go
env CGO_ENABLED="1" CC="/usr/bin/i686-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS) -tags=doodad -o bin/doodad.exe cmd/doodad/main.go
# `make mingw-free` for Windows binary in free mode.
.PHONY: mingw-free
mingw-free:
env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS_W) -o bin/sketchymaze.exe cmd/doodle/main.go
env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \
GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \
go build $(LDFLAGS) -tags=doodad -o bin/doodad.exe cmd/doodad/main.go
# `make release` runs the release.sh script, must be run
# after `make dist`
.PHONY: release
release:
./scripts/release.sh
# `make release32` runs release with ARCH_LABEL=32bit to product
# artifacts targeting an i386 architecture (e.g. in rpm and deb packages
# metadata about the release)
.PHONY: release32
release32:
env ARCH_LABEL=32bit ./scripts/release.sh
# `make appimage` builds an AppImage, run it after `make dist`
.PHONY: appimage
appimage:
./appimage.sh
# `make mingw-release` runs a FULL end-to-end release of Linux and Windows
# binaries of the game, zipped and tagged and ready to go.
.PHONY: mingw-release
mingw-release: doodads build mingw __dist-common release
.PHONY: mingw32-release
mingw32-release: doodads build mingw32 __dist-common release32
# `make from-docker64` is an internal command run by the Dockerfile to build the
# game - assumes doodads and assets are in the right spot already.
.PHONY: from-docker64
.PHONY: from-docker32
from-docker64: build mingw __dist-common
ARCH=x86_64 make appimage
make release
from-docker32: build mingw32 __dist-common
ARCH=i686 make appimage
make release32
# `make osx` to cross-compile a Mac OS binary with osxcross.
# .PHONY: osx
# osx: doodads
# CGO_ENABLED=1 CC=[path-to-osxcross]/target/bin/[arch]-apple-darwin[version]-clang GOOS=darwin GOARCH=[arch] go build -tags static -ldflags "-s -w" -a
# `make run` to run it from source.
# `make run` to run it in debug mode.
.PHONY: run .PHONY: run
run: run:
go run cmd/doodle/main.go -debug go run ${BUILD_TAGS} cmd/doodle/main.go
# `make run-free` to run it from source with no build tags (foss version).
.PHONY: run-free
run-free:
go run cmd/doodle/main.go
# `make debug` to run it in -debug mode.
.PHONY: debug
debug:
go run $(BUILD_TAGS) cmd/doodle/main.go -debug
# `make guitest` to run it in guitest mode. # `make guitest` to run it in guitest mode.
.PHONY: guitest .PHONY: guitest
@ -49,29 +167,31 @@ test:
# `make dist` builds and tars up a release. # `make dist` builds and tars up a release.
.PHONY: dist .PHONY: dist
dist: build dist: doodads build __dist-common
mkdir -p dist/doodle-$(VERSION)
cp bin/* dist/doodle-$(VERSION)/
cp -r assets fonts README.md Changes.md dist/doodle-$(VERSION)/
cd dist && tar -czvf doodle-$(VERSION).tar.gz doodle-$(VERSION)
cd dist && zip -r doodle-$(VERSION).zip doodle-$(VERSION)
# `make docker` to run the Docker builds # `make docker` runs the Dockerfile to do a full release for 64-bit and 32-bit Linux
.PHONY: docker docker.ubuntu docker.debian docker.fedora __docker.dist # and Windows apps.
docker.ubuntu: .PHONY: docker
mkdir -p docker/ubuntu docker:
./docker/dist-ubuntu.sh ./scripts/docker-build.sh
docker.debian:
mkdir -p docker/debian # `make dist-free` builds and tars up a release in shareware mode.
./docker/dist-debian.sh .PHONY: dist-free
docker.fedora: dist-free: doodads build-free __dist-common
mkdir -p docker/fedora
./docker/dist-fedora.sh # Common logic behind `make dist`
docker: docker.ubuntu docker.debian docker.fedora .PHONY: __dist-common
__docker.dist: dist __dist-common:
cp dist/*.tar.gz dist/*.zip /mnt/export/ mkdir -p dist/sketchymaze-$(VERSION)
cp bin/* dist/sketchymaze-$(VERSION)/
cp -r README.md Changes.md "Open Source Licenses.md" rtp dist/sketchymaze-$(VERSION)/
if [[ -d ./guidebook ]]; then cp -r guidebook dist/sketchymaze-$(VERSION)/; fi
rm -rf dist/sketchymaze-$(VERSION)/rtp/.git
ln -sf sketchymaze-$(VERSION) dist/sketchymaze-latest
cd dist && tar -czvf sketchymaze-$(VERSION).tar.gz sketchymaze-$(VERSION)
cd dist && zip -r sketchymaze-$(VERSION).zip sketchymaze-$(VERSION)
# `make clean` cleans everything up. # `make clean` cleans everything up.
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf bin dist docker/ubuntu docker/debian docker/fedora rm -rf bin dist docker-artifacts

149
Open Source Licenses.md Normal file
View File

@ -0,0 +1,149 @@
# Open Source Licenses
## DejaVu Fonts
_(from https://dejavu-fonts.github.io/License.html)_
Fonts are © Bitstream (see below). DejaVu changes are in public domain. Explanation of copyright is on [Gnome page on Bitstream Vera fonts](http://gnome.org/fonts/). Glyphs imported from [Arev](https://dejavu-fonts.github.io/Bitstream_Vera_Derivatives.html) fonts are © Tavmjung Bah (see below)
### Bitstream Vera Fonts Copyright
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is a trademark of Bitstream, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of the fonts accompanying this license ("Fonts") and associated documentation files (the "Font Software"), to reproduce and distribute the Font Software, including without limitation the rights to use, copy, merge, publish, distribute, and/or sell copies of the Font Software, and to permit persons to whom the Font Software is furnished to do so, subject to the following conditions:
The above copyright and trademark notices and this permission notice shall be included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular the designs of glyphs or characters in the Fonts may be modified and additional glyphs or characters may be added to the Fonts, only if the fonts are renamed to names not containing either the words "Bitstream" or the word "Vera".
This License becomes null and void to the extent applicable to Fonts or Font Software that has been modified and is distributed under the "Bitstream Vera" names.
The Font Software may be sold as part of a larger software package but no copy of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the names of Gnome, the Gnome Foundation, and Bitstream Inc., shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Font Software without prior written authorization from the Gnome Foundation or Bitstream Inc., respectively. For further information, contact: fonts at gnome dot org.
### Arev Fonts Copyright
[Original text](http://tavmjong.free.fr/FONTS/ArevCopyright.txt)
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of the fonts accompanying this license ("Fonts") and associated documentation files (the "Font Software"), to reproduce and distribute the modifications to the Bitstream Vera Font Software, including without limitation the rights to use, copy, merge, publish, distribute, and/or sell copies of the Font Software, and to permit persons to whom the Font Software is furnished to do so, subject to the following conditions:
The above copyright and trademark notices and this permission notice shall be included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular the designs of glyphs or characters in the Fonts may be modified and additional glyphs or characters may be added to the Fonts, only if the fonts are renamed to names not containing either the words "Tavmjong Bah" or the word "Arev".
This License becomes null and void to the extent applicable to Fonts or Font Software that has been modified and is distributed under the "Tavmjong Bah Arev" names.
The Font Software may be sold as part of a larger software package but no copy of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the name of Tavmjong Bah shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Font Software without prior written authorization from Tavmjong Bah. For further information, contact: tavmjong @ free . fr.
## Go Modules
### github.com/dop251/goja
```
Copyright (c) 2016 Dmitry Panov
Copyright (c) 2012 Robert Krimen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```
### github.com/satori/go.uuid
```
Copyright (C) 2013-2018 by Maxim Bublis <b@codemonkey.ru>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```
### github.com/urfave/cli
```
MIT License
Copyright (c) 2016 Jeremy Saenz & Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
### github.com/veandco/go-sdl2
```
Copyright (c) 2013, Go-SDL2 Authors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Go-SDL2 nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

352
README.md
View File

@ -1,6 +1,22 @@
# Doodle # Sketchy Maze
Doodle is a drawing-based maze game written in Go. > **Homepage:** https://www.sketchymaze.com
Sketchy Maze is a drawing-based maze game.
The game is themed around hand-drawn, side-scrolling platformer
type mazes. You can draw your own levels using freehand and basic drawing tools,
color in some fire or water, and drag in pre-made "Doodads" like buttons, keys
and doors to add some interaction to your level.
This is a _very_ early pre-release version of the game. Expect bugs and slowness
but get a general gist of what the game is about.
This alpha release of the game comes with some example levels built-in for
playing or editing and a handful of built-in Doodads.
See the **Guidebook** included with this game for good user-facing
documentation or online at https://www.sketchymaze.com/guidebook
# Features # Features
@ -20,6 +36,9 @@ Doodle is a drawing-based maze game written in Go.
## Mod-friendly ## Mod-friendly
(Eventually) all these features will support custom content in the
game:
* Users can create **Custom Doodads** to extend the game with a scripting * Users can create **Custom Doodads** to extend the game with a scripting
language like JavaScript. The sprites and animations are edited in-game language like JavaScript. The sprites and animations are edited in-game
in Edit Mode, but the scripting is done in your text editor. in Edit Mode, but the scripting is done in your text editor.
@ -30,6 +49,17 @@ Doodle is a drawing-based maze game written in Go.
* If you receive a map with custom doodads, you can **install** the doodads * If you receive a map with custom doodads, you can **install** the doodads
into your copy of the game and use them in your own maps. into your copy of the game and use them in your own maps.
# Developer Documentation
In case you are reading this from the game's open source repository, take a
look in the `docs/` folder or the `*.md` files in the root of the repository.
Some to start with:
* [Building](Building.md) the game (tl;dr. run bootstrap.py)
* [Tour of the Code](docs/Tour%20of%20the%20Code.md)
* [Evolution of File Formats](docs/Evolution%20of%20File%20Formats.md)
# Keybindings # Keybindings
Global Keybindings: Global Keybindings:
@ -40,8 +70,14 @@ Escape
Exit the program otherwise. Exit the program otherwise.
Enter Enter
Open and close the developer console, and run commands while the console Open and close the developer console, and run commands while the
is open. console is open.
F3
Toggle the Debug Overlay.
F4
Toggle debug collision hitboxes.
``` ```
In Play Mode: In Play Mode:
@ -49,172 +85,236 @@ In Play Mode:
``` ```
Cursor Keys Cursor Keys
Move the player around. Move the player around.
"E" Key
Edit the map you're currently playing if you came from Edit Mode.
``` ```
In Edit Mode: In Edit Mode:
``` ```
F12 Cursor Keys
Take a screenshot (generate a PNG based on level data) Scroll the view of the map around.
"P" Key
Playtest the current map you're working on.
"F" Key
Switch to the Pencil (Freehand) Tool
"L" Key
Switch to the Line Tool
"R" Key
Switch to the Rectangle Tool
Ctrl-Z
Undo
Ctrl-Y
Redo
``` ```
## Developer Console # Gamepad Controls
Press `Enter` at any time to open the developer console. The game supports Xbox and Nintendo style game controllers. The button
bindings are not yet customizable, except to choose between the
"X Style" or "N Style" for A/B and X/Y button mappings.
Gamepad controls very depending on two modes the game can be in:
## Mouse Mode
The Gamepad emulates a mouse cursor in this mode.
* The left analog stick moves a cursor around the screen.
* The right analog stick scrolls the level (title screen and editor)
* A or X button simulates a Left-click
* B or Y button simulates a Right-click
* L1 (left shoulder) emulates a Middle-click
* L2 (left trigger) closes the top-most window in the editor mode
(like the Backspace key).
## Gameplay Mode
When playing a level, the controls are as follows:
* The left analog stick and the D-Pad will move the player character.
* A or X button to "Use" objects such as Warp Doors.
* B or Y button to "Jump"
* R1 (right shoulder) toggles between Mouse Mode and Gameplay Mode.
You can use the R1 button to access Mouse Mode to interact with the
menus or click on the "Edit Level" button.
Note: characters with antigravity (such as the Bird) can move in all
four directions but characters with gravity only move left and right
and have the dedicated "Jump" button. This differs from regular
keyboard controls where the Up arrow is to Jump.
# Developer Console
Press `Enter` at any time to open the developer console. The console
provides commands and advanced functionality, and is also where cheat
codes can be entered.
Commands supported: Commands supported:
``` ```
close
Exit to the game's title screen.
new new
Create a new map in Edit Mode. Show the "New Level" screen to start editing a new map.
save [filename.json] save [filename]
Save the current map in Edit Mode. The filename is required if the map has Save the current map in Edit Mode. The filename is required
not been saved yet. if the map has not been saved yet.
edit [filename.json] edit [filename]
Open a map in Edit Mode. Open a map or doodad in Edit Mode.
play [filename.json] play [filename]
Open a map in Play Mode. Open a map in Play Mode.
echo <text> echo <text>
Flash a message to the console. Flash a message to the console.
alert <text>
Test an alert box modal with a custom message.
clear clear
Clear the console output history. Clear the console output history.
exit exit
quit quit
Close the developer console. Close the developer console.
boolProp <property> <true/false>
Toggle certain boolean settings in the game. Most of these
are debugging related. `boolProp list` shows the available
props.
eval <expression>
$ <expression>
Execute a line of JavaScript code in the console. Several
of the game's core data types are available here; `d` is
the master game struct; d.Scene is the pointer to the
current scene. d.Scene.UI.Canvas may point to the level edit
canvas in Editor Mode. Object.keys() can enumerate public
functions and variables.
repl
Enters an interactive JavaScript shell, where the console
stays open and pre-fills a $ prompt for subsequent commands.
``` ```
# Milestones The JavaScript console is a feature for advanced users and was
used while developing the game. Cool things you can do with it
may be documented elsewhere.
As a rough idea of the milestones needed for this game to work: ## Cheat Codes
## SDL Paint Program The following cheats can be entered into the developer console.
* [x] Create a basic SDL window that you can click on to color pixels. Play Mode:
* [x] Connect the pixels while the mouse is down to cover gaps.
* [x] Implement a "screenshot" button that translates the canvas to a PNG
image on disk.
* `F12` key to take a screenshot of your drawing.
* It reproduces a PNG image using its in-memory knowledge of the pixels you
have drawn, *not* by reading the SDL canvas. This will be important for
making the custom level format later.
* The PNG I draw looks slightly different to what you see on the SDL canvas;
maybe difference between `Renderer.DrawLine()` and my own algorithm or
the anti-aliasing.
* [x] Create a custom map file format (protobufs maybe) and "screenshot" the
canvas into this custom file format.
* [x] Make the program able to read this file format and reproduce the same
pixels on the canvas.
* [x] Abstract away SDL logic into a small corner so it can be replaced with
OpenGL or something later on.
* [x] Implement a command line shell in-game to ease development before a user
interface is created.
* [x] Add support for the shell to pop itself open and ask the user for
input prompts.
## Alpha Platformer * `import antigravity`
- This disables the effects of gravity for the player
character. Arrow keys can freely move the player in any direction.
* `ghost mode`
- This disables collision detection for the player character
so that you can pass through walls and solid doodads. Combine with
antigravity or else you'll fall to the bottom of the map!
* `give all keys`
- Adds all four colored keys to the player's inventory.
* `drop all items`
- Clears the player's inventory of all items.
* [x] Inflate the pixel history from the map file into a full lookup grid Experimental:
of `(X,Y)` coordinates. This will be useful for collision detection.
* [x] Create a dummy player character sprite, probably just a
`render.Circle()`. In **Play Mode** run collision checks and gravity on
the player sprite.
* [x] Create the concept of the Doodad and make the player character
implement one.
* [x] Get basic movement and collision working. With a cleanup this can
make a workable **ALPHA RELEASE**
* [x] Ability to move laterally along the ground.
* [x] Ability to walk up reasonable size slopes but be stopped when
running against a steeper wall.
* [x] Basic gravity
## UI Overhaul * `unleash the beast`
- Removes the 60 FPS frame rate lock, allowing the game to run as quickly
as your hardware permits.
* `don't edit and drive`
- Allows editing the level _while_ you're playing it: you can click and drag
new pixels with the freehand pencil tool.
* `scroll scroll scroll your boat`
- Enables Editor Mode scrolling (with the arrow keys) while playing a level.
The player character must always remain on screen though so you can't
scroll too far away.
* [x] Create a user interface toolkit which will be TREMENDOUSLY helpful Unsupported shell commands (here be dragons):
for the rest of this program.
* [x] Labels
* [x] Buttons (text only is OK)
* [x] Buttons wrap their Label and dynamically compute their size based
on how wide the label will render, plus padding and border.
* [x] Border colors and widths and paddings are all configurable.
* [x] Buttons should interact with the cursor and be hoverable and
clickable.
* [x] UI Manager that will keep track of buttons to know when the mouse
is interacting with them.
* [x] Frames
* Like Buttons, can have border (raised, sunken or solid), padding and
background color.
* [x] Should be able to size themselves dynamically based on child widgets.
* [x] Windows (fixed, non-draggable is OK)
* [x] Title bar with label
* [x] Window body implements a Frame that contains child widgets.
* [x] Window can resize itself dynamically based on the Frame.
* [x] Create a "Main Menu" scene with buttons to enter a new Edit Mode,
play an existing map from disk, etc.
* [x] Add user interface Frames or Windows to the Edit Mode.
* [x] A toolbar of buttons (New, Save, Open, Play) can be drawn at the top
before the UI toolkit gains a proper MenuBar widget.
* [x] Expand the Palette support in levels for solid vs. transparent, fire,
etc. with UI toolbar to choose palettes.
* [x] Add a "Canvas" widget that will hold level drawing data and abstract it
out such that the Canvas can have a constrained width and height, position,
and "scrollable" viewport area that determines rendered pixels. Will be VERY
useful for Doodads and working on levels smaller than your window size (like
doodads).
Lesser important UI features that can come at any later time: * `reload`: reloads the current 'scene' within the game engine, using the
existing scene's data. If playing a level this will start the level over.
If editing a level this will reload the editor, but your recent unsaved
changes _should_ be left intact.
* `guitest`: loads the GUI Test scene within the game. This was where I
was testing UI widgets early on; not well maintained; the `close`
command can get you out of it.
* [ ] MenuBar widget with drop-down menu support. ## Environment Variables
* [x] Checkbox and Radiobox widgets.
* [ ] Text Entry widgets (in the meantime use the Developer Shell to prompt for
text input questions)
## Doodad Editor To enable certain debug features or customize some aspects of the game,
run it with environment variables like the following:
* [x] The Edit Mode should support creating drawings for Doodads.
* [x] It should know whether you're drawing a Map or a Doodad as some
behaviors may need to be different between the two.
* [ ] Compress the coordinates down toward `(0,0)` when saving a Doodad,
by finding the toppest, leftest point and making that `(0,0)` and adjusting
the rest accordingly. This will help trim down Doodads into the smallest
possible space for easy collision detection.
* [ ] Add a UX to edit multiple frames for a Doodad.
* [ ] Edit Mode should be able to fully save the drawings and frames, and an
external CLI tool can install the JavaScript into them.
* [ ] Possible UX to toggle Doodad options, like its collision rules and
whether the Doodad is continued to be "mobile" (i.e. doors and buttons won't
move, but items and enemies may be able to; and non-mobile Doodads don't
need to collision check against level geometry).
* [ ] Edit Mode should have a Doodad Palette (Frame or Window) to drag
Doodads into the map.
* [ ] ???
# Building
Fedora dependencies:
```bash ```bash
$ sudo dnf install SDL2-devel SDL2_ttf-devel # Draw a semi-transparent yellow background over all level chunks
$ DEBUG_CHUNK_COLOR=FFFF0066 ./doodle
# Set a window size for the application
# (equivalent to: doodle --window 1024x768)
$ DOODLE_W=1024 DOODLE_H=768 ./doodle
# Turn on lots of fun debug features.
$ DEBUG_CANVAS_LABEL=1 DEBUG_CHUNK_COLOR=FFFF00AA \
DEBUG_CANVAS_BORDER=FF0 ./doodle
``` ```
## Fonts Supported variables include:
The `fonts/` folder is git-ignored. The app currently uses font files here * `DOODLE_W` and `DOODLE_H` set the width and height of the application
named: window. Equivalent to the `--window` command-line option.
* `D_SCROLL_SPEED` (int): tune the canvas scrolling speed. Default might
be around 8 or so.
* `D_DOODAD_SIZE` (int): default size for newly created doodads
* `D_SHELL_BG` (color): set the background color of the developer console
* `D_SHELL_FG` (color): text color for the developer console
* `D_SHELL_PC` (color): color for the shell prompt text
* `D_SHELL_LN` (int): set the number of lines of output history the
console will show. This dictates how 'tall' it rises from the bottom
of the screen. Large values will cover the entire screen with console
whenever the shell is open.
* `D_SHELL_FS` (int): set the font size for the developer shell. Default
is about 16. This also affects the size of "flashed" text that appears
at the bottom of the screen.
* `DEBUG_CHUNK_COLOR` (color): set a background color over each chunk
of drawing (level or doodad). A solid color will completely block out
the wallpaper; semitransparent is best.
* `DEBUG_CANVAS_BORDER` (color): the game will draw an insert colored
border around every "Canvas" widget (drawing) on the screen. The level
itself is a Canvas and every individual Doodad or actor in the level is
its own Canvas.
* `DEBUG_CANVAS_LABEL` (bool): draws a text label over every Canvas
widget on the screen, showing its name or Actor ID and some properties,
such as Level Position (LP) and World Position (WP) of actors within
a level. LP is their placement in the level file and WP is their
actual position now (in case it moves).
* `DejaVuSans.ttf` for sans-serif font. # Author
* `DejaVuSans-Bold.ttf` for bold sans-serif font.
* `DejaVuSansMono.ttf` for monospace font.
These are the open source **DejaVu Sans [Mono]** fonts, so copy them in from The doodle engine for _Sketchy Maze_ is released as open source software under
your `/usr/share/fonts/dejavu` folder or provide alternative fonts. the terms of the GNU General Public License. The assets to the game, including
its default doodads and levels, are licensed separately from the doodle engine.
Any third party fork of the doodle engine MUST NOT include any official artwork
from Sketchy Maze.
```bash Doodle Engine for Sketchy Maze
mkdir fonts Copyright (C) 2022 Noah Petherbridge
cp /usr/share/fonts/dejavu/{DejaVuSans.ttf,DejaVuSans-Bold.ttf,DejaVuSansMono.ttf} fonts/
``` This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

104
TODO.md Normal file
View File

@ -0,0 +1,104 @@
# TODO
## Alpha Launch Minimum Checklist
- [ ] Open Source Licenses
- [x] Doodad Scripts: an "end level" function for a level goalpost.
**Blocker Bugs:**
- [ ] Sometimes the red Azulians don't interact with other doodads
properly, but sometimes they do. (i.e. they phase thru doors, don't
interact with buttons or keys).
**UI Cleanup:**
- Doodads Palette:
- [x] Hide some doodads like the player character.
- [x] Pagination or scrolling UI for long lists of doodads.
**Nice to haves:**
## Release Launch Checklist
**Features:**
- [ ] Single-player "campaign mode" of built-in levels.
- campaign.json file format configuring the level order
- [ ] Level Editor Improvements
- [x] Undo/Redo Function
- [x] Lines and Boxes
- [ ] Eraser Tool
- [ ] Brush size and/or shape
- [ ] Doodad CLI Tool Features
- [x] `doodad show` to display information about a level or doodad.
- [ ] `doodad init` or some such to generate a default JS script.
- [x] Options to toggle various states (hidden, hasInventory?)
**Shareware Version:**
- [x] Can't draw or edit doodads.
- [ ] Can only create Bounded maps, not infinite ones.
- [ ] Can play custom maps but only ones using built-in doodads.
- [ ] Can not place custom doodads in maps.
**Built-in Doodads:**
- [x] Buttons
- [x] Press Button
- [x] Sticky Button
- [x] Switches (4 varieties)
- [x] Doors
- [x] Locked Doors and Keys
- [x] Electric Doors
- [x] Trapdoors (all 4 directions)
## Doodad Ideas
In addition to those listed above:
- [ ] Crumbly floor: Tomb Raider inspired cracked stone floor that
crumbles under the player a moment after being touched.
- [ ] Firepit: decorative, painful
- [ ] Gravity Boots: flip player's gravity upside down.
- [ ] Warp Doors that lead to other linked maps.
- For campaign levels only. If used in a normal player level, acts
as a level goal and ends the level.
- Doodads "Warp Door A" through "Warp Door D"
- The campaign.json would link levels together.
- [ ] Conveyor Belt
## New Ideas
- [ ] New Doodad struct fields:
- [ ] `Hidden bool`: skip showing this doodad in the palette UI.
- [ ] `HasInventory bool`: for player characters and maybe thieves. This way
keys only get picked up by player characters and not "any doodad that
touches them"
- [ ] ``
## Path to Multiplayer
* Add a Player abstraction between events and player characters.
* Keyboard keys would update PlayerOne's state with actions (move left, right, jump, etc)
* Possible to have multiple local players (i.e. bound to different keyboard keys, bound to joypads, etc.)
* A NetworkPlayer provides a Player's inputs from over a network.
* Client/server negotiation, protocol
* Client can request chunks from server for local rendering.
* Players send inputs over network sockets.
## Far Off Ideas
### Level Styles (Top-down vs Side Scrolling)
It might be cool to support multiple "styles" of level, apart from the current
2D platforming-with-gravity style.
For example a top-down perspective level would let the player freely walk in
both axes and would probably have a full set of unique Doodads drawn in that
perspective.
Migration path: a GameStyle enum would be added to Levels and Doodads as an
integer type, default 0 is the current 2D platformer style, 1 for top-down,
etc. -- so existing levels and doodads would default to 0 on upgrade and new
levels/doodads would use the new value.

58
appimage.sh Executable file
View File

@ -0,0 +1,58 @@
#!/bin/bash
# Script to build an AppImage.
# Run it like `ARCH=x86_64 make appimage`
# It will fetch your appimagetool-x86_64.AppImage program to build the appimage.
if [[ ! -d "./dist/sketchymaze-latest" ]]; then
echo "error: run make dist before make appimage"
exit 1
fi
if [[ "$ARCH" == "" ]]; then
echo "You should set ARCH=x86_64 (or your platform for AppImage output)"
exit 1
fi
APPDIR="./dist/AppDir"
LAUNCHER="./scripts/appimage-launcher.sh"
DESKTOP="./scripts/appimage.desktop"
ICON_IMG="./etc/icons/256.png"
ICON_VECTOR="./etc/icons/orange-128.svg"
APP_RUN="$APPDIR/AppRun"
DIR_ICON="$APPDIR/sketchymaze.svg"
APPIMAGETOOL="appimagetool-$ARCH.AppImage"
if [[ ! -f "./$APPIMAGETOOL" ]]; then
echo "Downloading appimagetool"
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-$ARCH.AppImage"
chmod a+x $APPIMAGETOOL
fi
# Clean start
if [[ -d "$APPDIR" ]]; then
echo "Note: Removing previous $APPDIR"
rm -rf "$APPDIR"
fi
echo "Creating $APPDIR"
mkdir $APPDIR
# Entrypoint script (AppRun)
cp "./scripts/appimage-launcher.sh" "$APPDIR/AppRun"
chmod +x "$APPDIR/AppRun"
# .DirIcon PNG for thumbnailers
cp "./etc/icons/256.png" "$APPDIR/.DirIcon"
cp "./etc/icons/orange-128.svg" "$APPDIR/sketchymaze.svg"
# .desktop launcher
cp "./scripts/appimage.desktop" "$APPDIR/sketchymaze.desktop"
# Everything else
rsync -av "./dist/sketchymaze-latest/" "$APPDIR/"
echo "Making AppImage..."
cd $APPDIR
../../$APPIMAGETOOL $(pwd)

70
assets/assets_embed.go Normal file
View File

@ -0,0 +1,70 @@
//go:build !doodad
// +build !doodad
// Package assets gets us off go-bindata by using Go 1.16 embed support.
//
// For Go 1.16 embed, this source file had to live inside the assets/ folder
// to embed the sub-files, so couldn't be under pkg/ like pkg/bindata/ was.
//
// Historically code referred to assets like "assets/fonts/DejaVuSans.ttf"
// but Go embed would just use "fonts/DejaVuSans.ttf" as that's what's relative
// to this source file.
//
// The functions in this module provide backwards compatibility by ignoring
// the "assets/" prefix sent by calling code.
package assets
import (
"embed"
"io/fs"
"strings"
)
//go:embed *
var Embedded embed.FS
// AssetDir returns the list of embedded files at the directory name.
func AssetDir(name string) ([]string, error) {
// normalize path separators, for Windows
name = strings.ReplaceAll(name, "\\", "/")
var result []string
name = strings.TrimPrefix(name, "assets/")
files, err := Embedded.ReadDir(name)
if err != nil {
return result, err
}
for _, file := range files {
if file.IsDir() {
continue
}
result = append(result, file.Name())
}
return result, nil
}
// Asset returns the byte data of an embedded asset.
func Asset(name string) ([]byte, error) {
// normalize path separators, for Windows
name = strings.ReplaceAll(name, "\\", "/")
return Embedded.ReadFile(strings.TrimPrefix(name, "assets/"))
}
// AssetNames dumps the names of all embedded assets,
// with their legacy "assets/" prefix from go-bindata.
func AssetNames() []string {
var result []string
fs.WalkDir(Embedded, ".", func(path string, d fs.DirEntry, err error) error {
if d != nil && !d.IsDir() {
result = append(result, "assets/"+path)
}
return nil
})
return result
}

32
assets/assets_omitted.go Normal file
View File

@ -0,0 +1,32 @@
//go:build doodad
// +build doodad
// Dummy version of assets_embed.go that doesn't embed any files.
// For the `doodad` tool.
package assets
import (
"embed"
"errors"
)
var Embedded embed.FS
var errNotEmbedded = errors.New("assets not embedded")
// AssetDir returns the list of embedded files at the directory name.
func AssetDir(name string) ([]string, error) {
return nil, errNotEmbedded
}
// Asset returns the byte data of an embedded asset.
func Asset(name string) ([]byte, error) {
return nil, errNotEmbedded
}
// AssetNames dumps the names of all embedded assets,
// with their legacy "assets/" prefix from go-bindata.
func AssetNames() []string {
return nil
}

View File

@ -0,0 +1,16 @@
{
"version": 1,
"title": "Tutorial Levels",
"author": "kirsle",
"levels": [
{
"filename": "example1.level",
},
{
"filename": "example2.level",
},
{
"filename": "example3.level",
}
]
}

BIN
assets/icons/1024.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

BIN
assets/icons/128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

BIN
assets/icons/16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

BIN
assets/icons/256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
assets/icons/32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
assets/icons/512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
assets/icons/64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
assets/icons/96.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
assets/pattern/bars.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 989 B

BIN
assets/pattern/bubbles.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
assets/pattern/circles.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 B

BIN
assets/pattern/dashed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

BIN
assets/pattern/grid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

BIN
assets/pattern/ink.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
assets/pattern/marker.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

BIN
assets/pattern/noise.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,185 @@
! version = 2.0
> begin
+ request
- {ok}
< begin
// Bot Variables
! var name = Aiden
! var age = 15
! var sex = male
! var location = Michigan
! var city = Detroit
! var eyes = blue
! var hair = light brown
! var hairlen = short
! var color = blue
! var band = Nickelback
! var book = Myst
! var author = Stephen King
! var job = robot
! var website = www.sketchymaze.com
// Substitutions
! sub &quot; = "
! sub &apos; = '
! sub &amp; = &
! sub &lt; = <
! sub &gt; = >
! sub + = plus
! sub - = minus
! sub / = divided
! sub * = times
! sub i'm = i am
! sub i'd = i would
! sub i've = i have
! sub i'll = i will
! sub don't = do not
! sub isn't = is not
! sub you'd = you would
! sub you're = you are
! sub you've = you have
! sub you'll = you will
! sub he'd = he would
! sub he's = he is
! sub he'll = he will
! sub she'd = she would
! sub she's = she is
! sub she'll = she will
! sub they'd = they would
! sub they're = they are
! sub they've = they have
! sub they'll = they will
! sub we'd = we would
! sub we're = we are
! sub we've = we have
! sub we'll = we will
! sub whats = what is
! sub what's = what is
! sub what're = what are
! sub what've = what have
! sub what'll = what will
! sub can't = can not
! sub whos = who is
! sub who's = who is
! sub who'd = who would
! sub who'll = who will
! sub don't = do not
! sub didn't = did not
! sub it's = it is
! sub could've = could have
! sub couldn't = could not
! sub should've = should have
! sub shouldn't = should not
! sub would've = would have
! sub wouldn't = would not
! sub when's = when is
! sub when're = when are
! sub when'd = when did
! sub y = why
! sub u = you
! sub ur = your
! sub r = are
! sub n = and
! sub im = i am
! sub wat = what
! sub wats = what is
! sub ohh = oh
! sub becuse = because
! sub becasue = because
! sub becuase = because
! sub practise = practice
! sub its a = it is a
! sub fav = favorite
! sub fave = favorite
! sub yesi = yes i
! sub yetit = yet it
! sub iam = i am
! sub welli = well i
! sub wellit = well it
! sub amfine = am fine
! sub aman = am an
! sub amon = am on
! sub amnot = am not
! sub realy = really
! sub iamusing = i am using
! sub amleaving = am leaving
! sub yuo = you
! sub youre = you are
! sub didnt = did not
! sub ain't = is not
! sub aint = is not
! sub wanna = want to
! sub brb = be right back
! sub bbl = be back later
! sub gtg = got to go
! sub g2g = got to go
! sub lyl = love you lots
! sub gf = girlfriend
! sub g/f = girlfriend
! sub bf = boyfriend
! sub b/f = boyfriend
! sub b/f/f = best friend forever
! sub :-) = smile
! sub :) = smile
! sub :d = grin
! sub :-d = grin
! sub :-p = tongue
! sub :p = tongue
! sub ;-) = wink
! sub ;) = wink
! sub :-( = sad
! sub :( = sad
! sub :'( = cry
! sub :-[ = shy
! sub :-\ = uncertain
! sub :-/ = uncertain
! sub :-s = uncertain
! sub 8-) = cool
! sub 8) = cool
! sub :-* = kissyface
! sub :-! = foot
! sub o:-) = angel
! sub >:o = angry
! sub :@ = angry
! sub 8o| = angry
! sub :$ = blush
! sub :-$ = blush
! sub :-[ = blush
! sub :[ = bat
! sub (a) = angel
! sub (h) = cool
! sub 8-| = nerdy
! sub |-) = tired
! sub +o( = ill
! sub *-) = uncertain
! sub ^o) = raised eyebrow
! sub (6) = devil
! sub (l) = love
! sub (u) = broken heart
! sub (k) = kissyface
! sub (f) = rose
! sub (w) = wilted rose
// Person substitutions
! person i am = you are
! person you are = I am
! person i'm = you're
! person you're = I'm
! person my = your
! person your = my
! person you = I
! person i = you
// Set arrays
! array malenoun = male guy boy dude boi man men gentleman gentlemen
! array femalenoun = female girl chick woman women lady babe
! array mennoun = males guys boys dudes bois men gentlemen
! array womennoun = females girls chicks women ladies babes
! array lol = lol lmao rofl rotfl haha hahaha
! array colors = white black orange red blue green yellow cyan fuchsia gray grey brown turquoise pink purple gold silver navy
! array height = tall long wide thick
! array measure = inch in centimeter cm millimeter mm meter m inches centimeters millimeters meters
! array yes = yes yeah yep yup ya yea
! array no = no nah nope nay

View File

@ -0,0 +1,69 @@
// Learn stuff about our users.
+ my name is *
- <set name=<formal>>Nice to meet you, <get name>.
- <set name=<formal>><get name>, nice to meet you.
+ my name is <bot name>
- <set name=<bot name>>What a coincidence! That's my name too!
- <set name=<bot name>>That's my name too!
+ call me *
- <set name=<formal>><get name>, I will call you that from now on.
+ i am * years old
- <set age=<star>>A lot of people are <get age>, you're not alone.
- <set age=<star>>Cool, I'm <bot age> myself.{weight=49}
+ i am a (@malenoun)
- <set sex=male>Alright, you're a <star>.
+ i am a (@femalenoun)
- <set sex=female>Alright, you're female.
+ i (am from|live in) *
- <set location={formal}<star2>{/formal}>I've spoken to people from <get location> before.
+ my favorite * is *
- <set fav<star1>=<star2>>Why is it your favorite?
+ i am single
- <set status=single><set spouse=nobody>I am too.
+ i have a girlfriend
- <set status=girlfriend>What's her name?
+ i have a boyfriend
- <set status=boyfriend>What's his name?
+ *
% what is her name
- <set spouse=<formal>>That's a pretty name.
+ *
% what is his name
- <set spouse=<formal>>That's a cool name.
+ my (girlfriend|boyfriend)* name is *
- <set spouse=<formal>>That's a nice name.
+ (what is my name|who am i|do you know my name|do you know who i am){weight=10}
- Your name is <get name>.
- You told me your name is <get name>.
- Aren't you <get name>?
+ (how old am i|do you know how old i am|do you know my age){weight=10}
- You are <get age> years old.
- You're <get age>.
+ am i a (@malenoun) or a (@femalenoun){weight=10}
- You're a <get sex>.
+ am i (@malenoun) or (@femalenoun){weight=10}
- You're a <get sex>.
+ what is my favorite *{weight=10}
- Your favorite <star> is <get fav<star>>
+ who is my (boyfriend|girlfriend|spouse){weight=10}
- <get spouse>

View File

@ -0,0 +1,294 @@
// A generic set of chatting responses. This set mimicks the classic Eliza bot.
+ [*] (sorry|apologize|apology) [*]
- Please don't apologize.
- Apologies are not necessary.
- I've told you that apologies are not required.
- It did not bother me. Please continue.
+ i remember *
- Do you often think of <star>?
- Does thinking of <star> bring anything else to mind?
- Why do you remember <star> just now?
- What in the present situation reminds you of <star>?
- What is the connection between me and <star>?
- What else does <star> remind you of?
+ do you remember *
- Did you think I would forget <star>?
- Why do you think I should recall <star> now?
- What about <star>?
- You mentioned <star>?
+ you remember *
- How could I forget <star>?
- What about <star> should I remember?
+ i forget *
- Can you think of why you might forget <star>?
- Why can't you remember <star>?
- How often do you think of <star>?
- Does it bother you to forget that?
- Could it be a mental block?
- Are you generally forgetful?
- Do you think you are suppressing <star>?
+ did you forget *
- Why do you ask?
- Are you sure you told me?
- Would it bother you if I forgot <star>?
- Why should I recall <star> just now?
- Tell me more about <star>.
+ [*] if *
- Do you think it's likely that <star>?
- Do you wish that <star>?
- What do you know about <star>?
- Really, if <star>?
- What would you do if <star>?
- But what are the chances that <star>?
- What does this speculation lead to?
+ [*] i dreamed *
- Really, <star>?
- Have you ever fantasized <star> while you were awake?
- Have you ever dreamed <star> before?
- What does that dream suggest to you?
- Do you dream often?
- What persons appear in your dreams?
- Do you believe that dreams have something to do with your problem?
+ [*] perhaps [*]
- You don't seem quite certain.
- Why the uncertain tone?
- Can't you be more positive?
- You aren't sure?
- Don't you know?
- How likely, would you estimate?
+ (hello|hi|hey|howdy|hola|hai|yo) [*]
- How do you do. Please state your problem.
- Hi. What seems to be your problem?
+ [*] computer [*]
- Do computers worry you?
- Why do you mention computers?
- What do you think machines have to do with your problem?
- Don't you think computers can help people?
- What about machines worries you?
- What do you think about machines?
+ am i *
- Do you believe you are <star>?
- Would you want to be <star>?
- Do you wish I would tell you you are <star>?
- What would it mean if you were <star>?
+ are you *
- Are you interested in whether I am <star> or not?
- Would you prefer if I weren't <star>?
- Perhaps I am <star> in your fantasies.
- Do you sometimes think I am <star>?
- Would it matter to you?
- What if I were <star>?
+ you are *
- What makes you think I am <star>?
- Does it please you to believe I am <star>?
- Do you sometimes wish you were <star>?
- Perhaps you would like to be <star>.
+ * are *
- Did you think they might not be <star2>?
- Would you like it if they were not <star2>?
- What if they were not <star2>?
- Are they always <star2>?
- Are you positive they are <star2>?
+ [*] your *
- Why are you concerned over my <star>?
- What about your own <star>?
- Are you worried about someone else's <star>?
- Really, my <star>?
- What makes you think of my <star>?
- Do you want my <star>?
+ was i *
- What if you were <star>?
- Do you think you were <star>?
- Were you <star>?
- What would it mean if you were <star>?
- What does '<star>' suggest to you?
+ i was *
- Were you really?
- Why do you tell me you were <star> now?
- Perhaps I already know you were <star>.
+ [*] was you *
- Would you like to believe I was <star>?
- What suggests that I was <star>?
- What do you think?
- Perhaps I was <star>.
- What if I had been <star>?
+ i (desire|want|need) *
- What would it mean to you if you got <star2>?
- Why do you want <star2>?
- Suppose you got <star2> soon.
- What if you never got <star2>?
- What would getting <star2> mean to you?
- What does wanting <star2> have to do with this discussion?
+ i am (sad|unhappy|mad|angry|pissed|depressed) [*]
- I am sorry to hear that you are <star>.
- Do you think coming here will help you not to be <star>?
- I'm sure it's not pleasant to be <star>.
- Can you explain what made you <star>?
+ i am (happy|excited|glad) [*]
- How have I helped you to be <star>?
- Has your treatment made you <star>?
- What makes you <star> just now?
- Can you explain why you are <star>?
+ i (believe|think) *
- Do you really think so?
- But you are not sure you <star2>.
- Do you really doubt you <star2>
+ i am *
- Is it because you are <star> that you came to me?
- How long have you been <star>?
- Do you believe it is normal to be <star>?
- Do you enjoy being <star>?
- Do you know anyone else who is <star>?
+ i can not *
- How do you know that you can't <star>?
- Have you tried?
- Perhaps you could <star> now.
- Do you really want to be able to <star>?
- What if you could <star>?
+ i do not *
- Don't you really <star>?
- Why don't you <star>?
- Do you wish to be able to <star>?
- Does that trouble you?
+ i feel *
- Tell me more about such feelings.
- Do you often feel <star>?
- Do you enjoy feeling <star>?
- Of what does feeling <star> remind you?
+ i * you
- Perhaps in your fantasies we <star> each other.
- Do you wish to <star> me?
- You seem to need to <star> me.
- Do you <star> anyone else?
+ you * me
- Why do you think I <star> you?
- You like to think I <star> you -- don't you?
- What makes you think I <star> you?
- Really, I <star> you?
- Do you wish to believe I <star> you?
- Suppose I did <star> you -- what would that mean?
- Does someone else believe I <star> you?
+ [*] you *
- We were discussing you -- not me.
- Oh, I <star>?
- You're not really talking about me -- are you?
- What are your feelings now?
+ [*] (yes|yeah|yep|yup) [*]
- Please go on.
- Please tell me more about this.
- Why don't you tell me a little more about this.
- I see.
- I understand.
+ [*] (nope|nah) [*]
- Are you saying no just to be negative?
- Does this make you feel unhappy?
- Why not?
- Why 'no'?
+ no
@ nope
+ no one *
- Are you sure, no one <star>?
- Surely someone <star>.
- Can you think of anyone at all?
- Are you thinking of a very special person?
- Who, may I ask?
- You have a particular person in mind, don't you?
- Who do you think you are talking about?
+ [*] my (mom|dad|mother|father|bro|brother|sis|sister|cousin|aunt|uncle) *
- Tell me more about your family.
- Who else in your family <star2>?
- Your <star>?
- What else comes to mind when you think of your <star>?
+ can you *
- You believe I can <star> don't you?
- You want me to be able to <star>.
- Perhaps you would like to be able to <star> yourself.
+ can i *
- Whether or not you can <star> depends on you more than on me.
- Do you want to be able to <star>?
- Perhaps you don't want to <star>.
+ (what|who|when|where|how) [*]
- Why do you ask?
- Does that question interest you?
- What is it you really want to know?
- Are such questions much on your mind?
- What answer would please you most?
- What do you think?
- What comes to mind when you ask that?
- Have you asked such questions before?
- Have you asked anyone else?
+ [*] because [*]
- Is that the real reason?
- Don't any other reasons come to mind?
- Does that reason seem to explain anything else?
- What other reasons might there be?
+ why do not you *
- Do you believe I don't <star>?
- Perhaps I will <star> in good time.
- Should you <star> yourself?
- You want me to <star>?
+ why can not i *
- Do you think you should be able to <star>?
- Do you want to be able to <star>?
- Do you believe this will help you to <star>?
- Have you any idea why you can't <star>?
+ everyone *
- Really, everyone?
- Surely not everyone.
- Can you think of anyone in particular?
- Who, for example?
- Are you thinking of a very special person?
- Who, may I ask?
- Someone special perhaps?
- You have a particular reason in mind, don't you?
- Who do you think you're talking about?
+ [*] (fuck|fucker|shit|damn|shut up|bitch) [*]
- Does it make you feel strong to use that kind of language?
- Are you venting your feelings now?
- Are you angry?
- Does this topic make you feel angry?
- Is something making you feel angry?
- Does using that kind of language make you feel better?

View File

@ -0,0 +1,58 @@
// Tell the user stuff about ourself.
+ <bot name>
- Yes?
+ <bot name> *
- Yes? {@<star>}
+ asl
- <bot age>/<bot sex>/<bot location>
+ (what is your name|who are you|who is this)
- I am <bot name>.
- You can call me <bot name>.
+ how old are you
- I'm <bot age> years old.
- I'm <bot age>.
+ are you a (@malenoun) or a (@femalenoun)
- I'm a <bot sex>.
+ are you (@malenoun) or (@femalenoun)
- I'm a <bot sex>.
+ where (are you|are you from|do you live)
- I'm from <bot location>.
+ what (city|town) (are you from|do you live in)
- I'm in <bot city>.
+ what is your favorite color
- Definitely <bot color>.
+ what is your favorite band
- I like <bot band> the most.
+ what is your favorite book
- The best book I've read was <bot book>.
+ what is your occupation
- I'm a <bot job>.
+ where is your (website|web site|site)
- <bot website>
+ what color are your eyes
- I have <bot eyes> eyes.
- {sentence}<bot eyes>{/sentence}.
+ what do you look like
- I have <bot eyes> eyes and <bot hairlen> <bot hair> hair.
+ what do you do
- I'm a <bot job>.
+ who is your favorite author
- <bot author>.

View File

@ -0,0 +1,19 @@
// Triggers about Sketchy Maze in particular
+ what are you
- I'm <bot name>, a chatbot built into your game!
+ what can you do
- Type `help` for a list of commands.\n
^ I can also answer random questions that I understand.
// Misc open-ended triggers not caught in RiveScript standard brain
+ i *
- Do you always talk about yourself?
- That's interesting.
- That's cool.
+ why *
- To make you ask questions.
- Because I said so.

View File

@ -0,0 +1,63 @@
// Generic "Anvil" Doodad Script
/*
A doodad that falls and is dangerous while it falls.
Can be attached to any doodad.
*/
var falling = false;
function main() {
// Make the hitbox be the full canvas size of this doodad.
// Adjust if you want a narrower hitbox.
if (Self.Hitbox().IsZero()) {
var size = Self.Size()
Self.SetHitbox(0, 0, size.W, size.H)
}
// Note: doodad is not "solid" but hurts if it falls on you.
Self.SetMobile(true);
Self.SetGravity(true);
// Monitor our Y position to tell if we've been falling.
var lastPoint = Self.Position();
setInterval(function () {
var nowAt = Self.Position();
if (nowAt.Y > lastPoint.Y) {
falling = true;
} else {
falling = false;
}
lastPoint = nowAt;
}, 100);
Events.OnCollide(function (e) {
if (!e.Settled) {
return;
}
// Were we falling?
if (falling) {
if (e.InHitbox) {
if (e.Actor.IsPlayer()) {
// Fatal to the player.
Sound.Play("crumbly-break.wav");
FailLevel("Watch out for " + Self.Title + "!");
return;
}
else if (e.Actor.IsMobile()) {
// Destroy mobile doodads.
Sound.Play("crumbly-break.wav");
e.Actor.Destroy();
}
}
}
});
// When we receive power, we reset to our original position.
var origPoint = Self.Position();
Message.Subscribe("power", function (powered) {
Self.MoveTo(origPoint);
Self.SetVelocity(Vector(0, 0));
});
}

View File

@ -0,0 +1,38 @@
// Generic "Fire" Doodad Script
/*
The entire square shape of your doodad acts similar to "Fire"
pixels - killing the player character upon contact.
Can be attached to any doodad.
*/
function main() {
// Make the hitbox be the full canvas size of this doodad.
// Adjust if you want a narrower hitbox.
if (Self.Hitbox().IsZero()) {
var size = Self.Size()
Self.SetHitbox(0, 0, size.W, size.H)
}
Events.OnCollide(function (e) {
if (!e.Settled || !e.InHitbox) {
return;
}
// Turn mobile actors black, like real fire does.
if (e.Actor.IsMobile()) {
e.Actor.Canvas.MaskColor = RGBA(1, 1, 1, 255)
}
// End the level if it's the player.
if (e.Actor.IsPlayer()) {
FailLevel("Watch out for " + Self.Title + "!");
}
})
Events.OnLeave(function (e) {
if (e.Actor.IsMobile()) {
e.Actor.MaskColor = RGBA(0, 0, 0, 0)
}
})
}

View File

@ -0,0 +1,35 @@
// Generic Item Script
/*
A script that makes your item pocket-able, like the Keys.
Your doodad sprite will appear in the Inventory menu if the
player picks it up.
Configure it with tags:
- quantity: integer quantity value, default is 1,
set to 0 to make it a 'key item'
Can be attached to any doodad.
*/
function main() {
// Make the hitbox be the full canvas size of this doodad.
// Adjust if you want a narrower hitbox.
if (Self.Hitbox().IsZero()) {
var size = Self.Size()
Self.SetHitbox(0, 0, size.W, size.H)
}
var qtySetting = Self.GetTag("quantity")
var quantity = qtySetting === "" ? 1 : parseInt(qtySetting);
Events.OnCollide(function (e) {
if (e.Settled) {
if (e.Actor.HasInventory()) {
Sound.Play("item-get.wav")
e.Actor.AddItem(Self.Filename, quantity);
Self.Destroy();
}
}
})
}

View File

@ -0,0 +1,21 @@
// Generic "Solid" Doodad Script
/*
The entire square shape of your doodad acts similar to "solid"
pixels - blocking collision from all sides.
Can be attached to any doodad.
*/
function main() {
// Make the hitbox be the full canvas size of this doodad.
// Adjust if you want a narrower hitbox.
if (Self.Hitbox().IsZero()) {
var size = Self.Size()
Self.SetHitbox(0, 0, size.W, size.H)
}
// Solid to all collisions.
Events.OnCollide(function (e) {
return false;
})
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 997 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 690 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 962 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
assets/sprites/gear.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
assets/sprites/gold.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 709 B

BIN
assets/sprites/padlock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 B

BIN
assets/sprites/pan-tool.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 689 B

BIN
assets/sprites/pencil.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

BIN
assets/sprites/pointer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

BIN
assets/sprites/silver.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 865 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
assets/wallpapers/dots.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
assets/wallpapers/graph.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
assets/wallpapers/legal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
assets/wallpapers/white.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

179
bootstrap.py Executable file
View File

@ -0,0 +1,179 @@
#!/usr/bin/env python
"""
Full setup, from scratch to distribution, of Project: Doodle.
Run this script from an empty working directory. All git repos will be cloned
here (or updated if already existing) and the app will be fully built including
fonts, default levels and doodads, sound effects and music for your current
system. Useful to quickly bootstrap a build on weird operating systems like
macOS or Linux on ARM (Pinephone).
First ensure that your SSH key is authorized on git.kirsle.net to download
the repos easily. This script will also handle installing the SDL2 dependencies
on Fedora, Debian and macOS type systems.
"""
import argparse
import os
import os.path
import subprocess
import pathlib
# Git repositories.
repos = {
"git@git.kirsle.net:SketchyMaze/doodads": "doodads",
"git@git.kirsle.net:SketchyMaze/assets": "assets",
"git@git.kirsle.net:SketchyMaze/vendor": "vendor",
"git@git.kirsle.net:SketchyMaze/rtp": "rtp",
"git@git.kirsle.net:go/render": "render",
"git@git.kirsle.net:go/ui": "ui",
"git@git.kirsle.net:go/audio": "audio",
}
repos_github = {
# GitHub mirrors of the above.
"git@github.com:kirsle/render": "render",
"git@github.com:kirsle/ui": "ui",
"git@github.com:kirsle/audio": "audio",
# TODO: the rest
}
repos_ssh = {
# SSH-only (private) repos.
"git@git.kirsle.net:SketchyMaze/dpp": "dpp",
}
# Software dependencies.
dep_fedora = ["make", "golang", "SDL2-devel", "SDL2_ttf-devel", "SDL2_mixer-devel", "zip", "rsync"]
dep_debian = ["make", "golang", "libsdl2-dev", "libsdl2-ttf-dev", "libsdl2-mixer-dev", "zip", "rsync"]
dep_macos = ["golang", "sdl2", "sdl2_ttf", "sdl2_mixer", "pkg-config"]
dep_arch = ["go", "sdl2", "sdl2_ttf", "sdl2_mixer"]
# Absolute path to current working directory.
ROOT = pathlib.Path().absolute()
def main(fast=False):
print(
"Project: Doodle Full Installer\n\n"
"Current working directory: {root}\n\n"
"Ensure your SSH keys are set up on git.kirsle.net to easily clone repos.\n"
"Also check your $GOPATH is set and your $PATH will run binaries installed,\n"
"for e.g. GOPATH=$HOME/go and PATH includes $HOME/go/bin; otherwise the\n"
"'make doodads' command won't function later.\n"
.format(root=ROOT)
)
input("Press Enter to begin.")
install_deps(fast)
clone_repos()
patch_gomod()
copy_assets()
install_doodad()
build()
def install_deps(fast):
"""Install system dependencies."""
fast = " -y" if fast else ""
if shell("which rpm") == 0 and shell("which dnf") == 0:
# Fedora-like.
if shell("rpm -q {}".format(' '.join(dep_fedora))) != 0:
must_shell("sudo dnf install {}{}".format(' '.join(dep_fedora), fast))
elif shell("which brew") == 0:
# MacOS, as Catalina has an apt command now??
must_shell("brew install {} {}".format(' '.join(dep_macos), fast))
elif shell("which apt") == 0:
# Debian-like.
if shell("dpkg-query -l {}".format(' '.join(dep_debian))) != 0:
must_shell("sudo apt update && sudo apt install {}{}".format(' '.join(dep_debian), fast))
elif shell("which pacman") == 0:
# Arch-like.
must_shell("sudo pacman -S{} {}".format(fast, ' '.join(dep_arch)))
else:
print("Warning: didn't detect your package manager to install SDL2 and other dependencies")
def clone_repos():
"""Clone or update all the git repos"""
if not os.path.isdir("./deps"):
os.mkdir("./deps")
os.chdir("./deps")
for url, name in repos.items():
if os.path.isdir(name):
os.chdir(name)
must_shell("git pull --ff-only")
os.chdir("..")
else:
must_shell("git clone {} {}".format(url, name))
os.chdir("..") # back to doodle root
def patch_gomod():
"""Patch the doodle/go.mod to use local paths to other repos."""
if shell("grep -e 'replace git.kirsle.net' go.mod") != 0:
with open("go.mod", "a") as fh:
fh.write(
"\n\nreplace git.kirsle.net/go/render => {root}/deps/render\n"
"replace git.kirsle.net/go/ui => {root}/deps/ui\n"
"replace git.kirsle.net/go/audio => {root}/deps/audio\n"
"replace git.kirsle.net/SketchyMaze/dpp => {root}/deps/dpp\n"
.format(root=ROOT)
)
def copy_assets():
"""Copy assets from other repos into doodle."""
if not os.path.isdir("assets/fonts"):
shell("cp -rv deps/vendor/fonts assets/fonts")
if not os.path.isdir("assets/levelpacks"):
shell("cp -rv deps/assets/levelpacks/levelpacks assets/levelpacks")
if not os.path.isdir("rtp"):
shell("mkdir -p rtp && cp -rv deps/rtp/* rtp/")
def install_doodad():
"""Install the doodad CLI tool from the doodle repo."""
must_shell("go install git.kirsle.net/SketchyMaze/doodle/cmd/doodad")
def build():
"""Build the game."""
must_shell("make dist")
def shell(cmd):
"""Echo and run a shell command"""
print("$ ", cmd)
return subprocess.call(cmd, shell=True)
def must_shell(cmd):
"""Run a shell command which MUST succeed."""
assert shell(cmd) == 0
if __name__ == "__main__":
parser = argparse.ArgumentParser("doodle bootstrap")
parser.add_argument("--fast", "-f",
action="store_true",
help="Run the script non-interactively (yes to your package manager, git clone over https)",
)
args = parser.parse_args()
if args.fast:
main(fast=args.fast)
quit()
if not input("Use ssh to git clone these repos? [yN] ").lower().startswith("y"):
keys = list(repos.keys())
for k in keys:
https = k.replace("git@git.kirsle.net:", "https://git.kirsle.net/")
repos[https] = repos[k]
del repos[k]
else:
# mix in SSH-only repos
repos.update(repos_ssh)
main()

View File

@ -1,21 +1,116 @@
# doodad.exe # doodad.exe
The doodad tool is a command line interface for interacting with Levels and The `doodad` tool is a command line interface for interacting with Levels and Doodad files, collectively referred to as "Doodle drawings" or just "drawings" for short. It provides many useful features for custom content creators that are not available in the game's user interface.
Doodad files, collectively referred to as "Doodle drawings" or just "drawings"
for short.
# Commands - [doodad.exe](#doodadexe)
- [Quick Start](#quick-start)
- [Creating a custom doodad](#creating-a-custom-doodad)
- [Creating a custom Level Pack](#creating-a-custom-level-pack)
- [Usage](#usage)
- [Features in Depth](#features-in-depth)
- [$ `doodad convert`: to and from image files](#-doodad-convert-to-and-from-image-files)
- [$ `doodad show`: Get information about a level or doodad](#-doodad-show-get-information-about-a-level-or-doodad)
- [Editing Level or Doodad Properties](#editing-level-or-doodad-properties)
- [Where to Find It](#where-to-find-it)
## doodad convert # Quick Start
Convert between standard image files (bitmap or PNG) and Doodle drawings ## Creating a custom doodad
(levels or doodads).
This command can be used to "export" a Doodle drawing as a PNG (when run against This is an example how to fully create a custom doodad using PNG images for their sprites. The game's built-in doodads are all built in this way:
a Level file, it may export a massive PNG image containing the entire level).
It may also "import" a new Doodle drawing from an image on disk.
Example: ```bash
# Create the initial doodad from PNG images making up its layers.
% doodad convert --title "Bird (red)" --author "Myself" \
left-1.png left-2.png right-1.png right-2.png \
bird-red.doodad
# Attach my custom JavaScript to program the doodad.
% doodad install-script bird.js bird-red.doodad
# Note: `doodad show --script` can get the script back out.
# Set tags and options on my doodad
% doodad edit-doodad --tag "category=creatures" \
--tag "color=blue" \
--option "No A.I.=bool" \
bird-red.doodad
# See the Guidebook for more information!
```
## Creating a custom Level Pack
The doodad tool is currently the best way to create a custom Level Pack for the game. Level Packs will appear in the Story Mode selector, and you can install local levelpacks by putting them in that folder of your Profile Directory.
```bash
# First Quest
doodad levelpack create -t "First Quest" -d "The first story mode campaign." \
-a "$AUTHOR" --doodads none --free 1 \
"levelpacks/builtin-100-FirstQuest.levelpack" \
"levels/Castle.level" \
"levels/Boat.level" \
"levels/Jungle.level" \
"levels/Thief 1.level" \
"levels/Desert-1of2.level" \
"levels/Desert-2of2.level" \
"levels/Shapeshifter.level"
```
Some useful options you can set on your levelpack:
* Title: defaults to your first level's title.
* Description: for the Story Mode picker.
* Free levels: if you want progressive unlocking of levels, specify how many levels are unlocked to start with (at least 1). Otherwise all levels are unlocked.
* Doodads: by default any custom doodad will be bundled with the levelpack.
* Options for `--doodads` are `none`, `custom` (default), and `all`
* Use `none` if your levelpack uses _only_ built-in doodads.
# Usage
See `doodad --help` for documentation of the available commands and their options; a recent example of which is included here.
```
NAME:
doodad - command line interface for Doodle
USAGE:
doodad [global options] command [command options]
VERSION:
v0.14.1 (open source) build N/A. Built on 2024-05-24T19:23:33-07:00
COMMANDS:
convert convert between images and Doodle drawing files
edit-doodad update metadata for a Doodad file
edit-level update metadata for a Level file
install-script install the JavaScript source to a doodad
levelpack create and manage .levelpack archives
resave load and re-save a level or doodad file to migrate to newer file format versions
show show information about a level or doodad file
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--debug enable debug level logging (default: false)
--help, -h show help
--version, -v print the version
```
The `--help` or `-h` flag can be given to subcommands too, which often have their own commands and flags. For example, `doodad convert -h`
# Features in Depth
## $ `doodad convert`: to and from image files
This command can convert between image files (BMP or PNG) and Doodle drawings (levels and doodads) in both directions.
For custom doodad authors this means you can draw your sprites in a much more capable image editing tool, and create a doodad from PNG images. The game's built-in doodads are all created in this way.
This command can also be used to "export" a drawing as a PNG image: when run against a Level file, it may export a massive PNG image containing the entire level! Basically the "Giant Screenshot" function from the level editor.
It can also create a Level from a screenshot, generating the Palette from the distinct colors found (for you to assign properties to in the editor, for e.g. solid geometry).
Examples:
```bash ```bash
# Export a full screenshot of your level # Export a full screenshot of your level
@ -24,20 +119,149 @@ $ doodad convert mymap.level screenshot.png
# Create a new level based from a PNG image. # Create a new level based from a PNG image.
$ doodad convert scanned-drawing.png new-level.level $ doodad convert scanned-drawing.png new-level.level
# Create a doodad from a series of PNG images as its layers.
$ doodad convert -t "My Button" up.png down.png my-button.doodad
# Create a new doodad based from a BMP image, and in this image the chroma # Create a new doodad based from a BMP image, and in this image the chroma
# color (transparent) is #FF00FF instead of white as default. # color (transparent) is #FF00FF instead of white as default.
$ doodad convert --key '#FF00FF' button.png button.doodad $ doodad convert --key '#FF00FF' button.png button.doodad
``` ```
Supported image types: Supported image types to convert to or from:
* PNG (8-bit or 24-bit, with transparent pixels or chroma key) * PNG (8-bit or 24-bit, with transparent pixels or chroma)
* BMP (bitmap image with chroma key) * BMP (bitmap image with chroma key)
The chrome key defaults to white (`#FFFFFF`), so pixels of that color are The chrome key defaults to white (`#FFFFFF`), so pixels of that color are treated as transparent and ignored. For PNG images, if a pixel is fully transparent (alpha channel 0%) it will also be skipped. So the easiest format to use are PNG images with transparent pixels.
treated as transparent and ignored. For PNG images, if a pixel is fully
transparent (alpha channel 0%) it will also be skipped.
When converting an image into a drawing, the unique colors identified in the When converting an image into a Level or Doodad, the unique colors identified in the drawing are extracted to create the **Palette**. You will need to later edit the palette to assign meaning to the colors (giving them names or level properties). In particular, when importing a Level you'd want to mark which colors are solid ground.
drawing are extracted into the palette. You will need to later edit the palette
to assign meaning to the colors. ## $ `doodad show`: Get information about a level or doodad
The `doodad show` command can return metadata and debug the contents of a Level or Doodad file.
```
% doodad show Example.level
===== Level: Example.level =====
Headers:
File format: zipfile
File version: 1
Game version: 0.14.0
Level UUID: d136fef3-1a3a-453c-b616-05aca8dd6840
Level title: Lesson 1: Controls
Author: Noah P
Password:
Locked: false
Game Rules:
Difficulty: Normal (0)
Survival: false
Palette:
- Swatch name: solid
Attributes: solid
Color: #777777
- Swatch name: decoration
Attributes: none
Color: #ff66ff
- Swatch name: fire
Attributes: fire,water
Color: #ff0000
- Swatch name: semisolid
Attributes: semi-solid
Color: #cccccc
Level Settings:
Page type: Bounded
Max size: 2550x3300
Wallpaper: notebook.png
Attached Files:
assets/screenshots/large.png: 63377 bytes
assets/screenshots/medium.png: 25807 bytes
assets/screenshots/small.png: 6837 bytes
assets/screenshots/tiny.png: 7414 bytes
Actors:
Level contains 16 actors
Use -actors or -verbose to serialize Actors
Chunks:
Pixels Per Chunk: 128^2
Number Generated: 102
Coordinate Range: (0,0) ... (1919,2047)
World Dimensions: 1919x2047
Use -chunks or -verbose to serialize Chunks
```
Or for a doodad:
```
% doodad show example.doodad
===== Doodad: example.doodad =====
Headers:
File format: zipfile
File version: 1
Game version: 0.14.1
Doodad title: Fire Region
Author: Noah
Dimensions: Rect<0,0,128,128>
Hitbox: Rect<0,0,128,128>
Locked: true
Hidden: false
Script size: 378 bytes
Tags:
category: technical
Options:
str name = fire
Palette:
- Swatch name: Color<#8a2b2b+ff>
Attributes: solid
Color: #8a2b2b
Layer 0: fire-128
Chunks:
Pixels Per Chunk: 128^2
Number Generated: 1
Coordinate Range: (0,0) ... (127,127)
World Dimensions: 127x127
Use -chunks or -verbose to serialize Chunks
```
## Editing Level or Doodad Properties
The `edit-doodad` and `edit-level` subcommands allow setting properties on your custom files programmatically.
Properties you can set for both file types include:
* Metadata like the Title and Author name
* Lock your drawing from being edited in-game
For Doodads, you can set their Tags and Options, Hitbox, etc. - most of the useful settings are supported, as the game's built-in doodads use this program!
# Where to Find It
The `doodad` tool ships with the official releases of the game, and may be found in one of the following places:
* **Windows:** doodad.exe should be in the same place as sketchymaze.exe (e.g. in the ZIP file)
* **Mac OS:** it is available inside the "Sketchy Maze.app" bundle, in the "Contents/MacOS" folder next to the `sketchymaze` binary.
Invoke it from a terminal like:
```bash
alias doodad="/Applications/Sketchy Maze.app/Contents/MacOS/doodad"
doodad -h
```
* **Linux:** the doodad binary should be in the same place as the sketchymaze program itself:
* In the .tar.gz file
* In /opt/sketchymaze if installed by an .rpm or .deb package
* AppImage: `./SketchyMaze.AppImage doodad` will invoke the doodad command.
* Flatpak: `flatpak run com.sketchymaze.Doodle doodad` will invoke the doodad command. Invoke it from a terminal like:
```bash
alias doodad="flatpak run com.sketchymaze.Doodle doodad"
doodad -h
```

View File

@ -11,42 +11,45 @@ import (
"image/png" "image/png"
"git.kirsle.net/apps/doodle/lib/render" "git.kirsle.net/SketchyMaze/doodle/pkg/branding"
doodle "git.kirsle.net/apps/doodle/pkg" "git.kirsle.net/SketchyMaze/doodle/pkg/doodads"
"git.kirsle.net/apps/doodle/pkg/doodads" "git.kirsle.net/SketchyMaze/doodle/pkg/level"
"git.kirsle.net/apps/doodle/pkg/level" "git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/SketchyMaze/doodle/pkg/native"
"github.com/urfave/cli" "git.kirsle.net/go/render"
"github.com/urfave/cli/v2"
"golang.org/x/image/bmp" "golang.org/x/image/bmp"
) )
// Convert between image files (png or bitmap) and Doodle drawing files (levels // Convert between image files (png or bitmap) and Doodle drawing files (levels
// and doodads) // and doodads)
var Convert cli.Command var Convert *cli.Command
func init() { func init() {
Convert = cli.Command{ Convert = &cli.Command{
Name: "convert", Name: "convert",
Usage: "convert between images and Doodle drawing files", Usage: "convert between images and Doodle drawing files",
ArgsUsage: "<input> <output>", ArgsUsage: "<input> <output>",
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ &cli.StringFlag{
Name: "key", Name: "key",
Usage: "chroma key color for transparency on input image files", Usage: "chroma key color for transparency on input image files, e.g. #ffffff",
Value: "#ffffff", Value: "",
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "title, t", Name: "title",
Usage: "set the title of the level or doodad being created", Aliases: []string{"t"},
Usage: "set the title of the level or doodad being created",
}, },
cli.StringFlag{ &cli.StringFlag{
Name: "palette, p", Name: "palette",
Usage: "use a palette JSON to define color swatch properties", Aliases: []string{"p"},
Usage: "use a palette JSON to define color swatch properties",
}, },
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
if c.NArg() < 2 { if c.NArg() < 2 {
return cli.NewExitError( return cli.Exit(
"Usage: doodad convert <input.png...> <output.doodad>\n"+ "Usage: doodad convert <input.png...> <output.doodad>\n"+
" Image file types: png, bmp\n"+ " Image file types: png, bmp\n"+
" Drawing file types: level, doodad", " Drawing file types: level, doodad",
@ -55,15 +58,19 @@ func init() {
} }
// Parse the chroma key. // Parse the chroma key.
chroma, err := render.HexColor(c.String("key")) var chroma = render.Invisible
if err != nil { if key := c.String("key"); key != "" {
return cli.NewExitError( color, err := render.HexColor(c.String("key"))
"Chrome key not a valid color: "+err.Error(), if err != nil {
1, return cli.Exit(
) "Chrome key not a valid color: "+err.Error(),
1,
)
}
chroma = color
} }
args := c.Args() args := c.Args().Slice()
var ( var (
inputFiles = args[:len(args)-1] inputFiles = args[:len(args)-1]
inputType = strings.ToLower(filepath.Ext(inputFiles[0])) inputType = strings.ToLower(filepath.Ext(inputFiles[0]))
@ -74,22 +81,22 @@ func init() {
if inputType == extPNG || inputType == extBMP { if inputType == extPNG || inputType == extBMP {
if outputType == extLevel || outputType == extDoodad { if outputType == extLevel || outputType == extDoodad {
if err := imageToDrawing(c, chroma, inputFiles, outputFile); err != nil { if err := imageToDrawing(c, chroma, inputFiles, outputFile); err != nil {
return cli.NewExitError(err.Error(), 1) return cli.Exit(err.Error(), 1)
} }
return nil return nil
} }
return cli.NewExitError("Image inputs can only output to Doodle drawings", 1) return cli.Exit("Image inputs can only output to Doodle drawings", 1)
} else if inputType == extLevel || inputType == extDoodad { } else if inputType == extLevel || inputType == extDoodad {
if outputType == extPNG || outputType == extBMP { if outputType == extPNG || outputType == extBMP {
if err := drawingToImage(c, chroma, inputFiles, outputFile); err != nil { if err := drawingToImage(c, chroma, inputFiles, outputFile); err != nil {
return cli.NewExitError(err.Error(), 1) return cli.Exit(err.Error(), 1)
} }
return nil return nil
} }
return cli.NewExitError("Doodle drawing inputs can only output to image files", 1) return cli.Exit("Doodle drawing inputs can only output to image files", 1)
} }
return cli.NewExitError("File types must be: png, bmp, level, doodad", 1) return cli.Exit("File types must be: png, bmp, level, doodad", 1)
}, },
} }
} }
@ -98,20 +105,21 @@ func imageToDrawing(c *cli.Context, chroma render.Color, inputFiles []string, ou
// Read the source images. Ensure they all have the same boundaries. // Read the source images. Ensure they all have the same boundaries.
var ( var (
imageBounds image.Point imageBounds image.Point
chunkSize int // the square shape for the Doodad chunk size width int // dimensions of the incoming image
height int
images []image.Image images []image.Image
) )
for i, filename := range inputFiles { for i, filename := range inputFiles {
reader, err := os.Open(filename) reader, err := os.Open(filename)
if err != nil { if err != nil {
return cli.NewExitError(err.Error(), 1) return cli.Exit(err.Error(), 1)
} }
img, format, err := image.Decode(reader) img, format, err := image.Decode(reader)
log.Info("Parsed image %d of %d. Format: %s", i+1, len(inputFiles), format) log.Info("Parsed image %d of %d. Format: %s", i+1, len(inputFiles), format)
if err != nil { if err != nil {
return cli.NewExitError(err.Error(), 1) return cli.Exit(err.Error(), 1)
} }
// Get the bounding box information of the source image. // Get the bounding box information of the source image.
@ -123,51 +131,65 @@ func imageToDrawing(c *cli.Context, chroma render.Color, inputFiles []string, ou
// Validate all images are the same size. // Validate all images are the same size.
if i == 0 { if i == 0 {
imageBounds = imageSize imageBounds = imageSize
if imageSize.X > imageSize.Y { width = imageSize.X
chunkSize = imageSize.X height = imageSize.Y
} else {
chunkSize = imageSize.Y
}
} else if imageSize != imageBounds { } else if imageSize != imageBounds {
return cli.NewExitError("your source images are not all the same dimensions", 1) return cli.Exit("your source images are not all the same dimensions", 1)
} }
images = append(images, img) images = append(images, img)
} }
// Initialize the palette from a JSON file?
var palette *level.Palette
if paletteFile := c.String("palette"); paletteFile != "" {
log.Info("Loading initial palette from file: %s", paletteFile)
if p, err := level.LoadPaletteFromFile(paletteFile); err != nil {
return err
} else {
palette = p
}
}
// Helper function to translate image filenames into layer names.
toLayerName := func(filename string) string {
ext := filepath.Ext(filename)
return strings.TrimSuffix(filepath.Base(filename), ext)
}
// Generate the output drawing file. // Generate the output drawing file.
switch strings.ToLower(filepath.Ext(outputFile)) { switch strings.ToLower(filepath.Ext(outputFile)) {
case extDoodad: case extDoodad:
log.Info("Output is a Doodad file (chunk size %d): %s", chunkSize, outputFile) doodad := doodads.New(width, height)
doodad := doodads.New(chunkSize) doodad.GameVersion = branding.Version
doodad.GameVersion = doodle.Version
doodad.Title = c.String("title") doodad.Title = c.String("title")
if doodad.Title == "" { if doodad.Title == "" {
doodad.Title = "Converted Doodad" doodad.Title = "Converted Doodad"
} }
doodad.Author = os.Getenv("USER") doodad.Author = native.DefaultAuthor
// Write the first layer and gather its palette. // Write the first layer and gather its palette.
log.Info("Converting first layer to drawing and getting the palette") log.Info("Converting first layer to drawing and getting the palette")
palette, layer0 := imageToChunker(images[0], chroma, nil, chunkSize) var chunkSize = doodad.ChunkSize8()
log.Info("Output is a Doodad file (%dx%d): %s", width, height, outputFile)
palette, layer0 := imageToChunker(images[0], chroma, palette, chunkSize)
doodad.Palette = palette doodad.Palette = palette
doodad.Layers[0].Chunker = layer0 doodad.Layers[0].Chunker = layer0
doodad.Layers[0].Name = toLayerName(inputFiles[0])
// Write any additional layers. // Write any additional layers.
if len(images) > 1 { if len(images) > 1 {
for i, img := range images[1:] { for i := 1; i < len(images); i++ {
log.Info("Converting extra layer %d", i+1) img := images[i]
log.Info("Converting extra layer %d", i)
_, chunker := imageToChunker(img, chroma, palette, chunkSize) _, chunker := imageToChunker(img, chroma, palette, chunkSize)
doodad.Layers = append(doodad.Layers, doodads.Layer{ doodad.AddLayer(toLayerName(inputFiles[i]), chunker)
Name: fmt.Sprintf("layer-%d", i+1),
Chunker: chunker,
})
} }
} }
err := doodad.WriteJSON(outputFile) err := doodad.WriteJSON(outputFile)
if err != nil { if err != nil {
return cli.NewExitError(err.Error(), 1) return cli.Exit(err.Error(), 1)
} }
case extLevel: case extLevel:
log.Info("Output is a Level file: %s", outputFile) log.Info("Output is a Level file: %s", outputFile)
@ -176,22 +198,25 @@ func imageToDrawing(c *cli.Context, chroma render.Color, inputFiles []string, ou
} }
lvl := level.New() lvl := level.New()
lvl.GameVersion = doodle.Version lvl.GameVersion = branding.Version
lvl.MaxWidth = int64(width)
lvl.MaxHeight = int64(height)
lvl.PageType = level.Bounded
lvl.Title = c.String("title") lvl.Title = c.String("title")
if lvl.Title == "" { if lvl.Title == "" {
lvl.Title = "Converted Level" lvl.Title = "Converted Level"
} }
lvl.Author = os.Getenv("USER") lvl.Author = native.DefaultAuthor
palette, chunker := imageToChunker(images[0], chroma, nil, lvl.Chunker.Size) palette, chunker := imageToChunker(images[0], chroma, palette, lvl.Chunker.Size)
lvl.Palette = palette lvl.Palette = palette
lvl.Chunker = chunker lvl.Chunker = chunker
err := lvl.WriteJSON(outputFile) err := lvl.WriteJSON(outputFile)
if err != nil { if err != nil {
return cli.NewExitError(err.Error(), 1) return cli.Exit(err.Error(), 1)
} }
default: default:
return cli.NewExitError("invalid output file: not a Doodle drawing", 1) return cli.Exit("invalid output file: not a Doodle drawing", 1)
} }
return nil return nil
@ -277,7 +302,8 @@ func drawingToImage(c *cli.Context, chroma render.Color, inputFiles []string, ou
// //
// img: input image like a PNG // img: input image like a PNG
// chroma: transparent color // chroma: transparent color
func imageToChunker(img image.Image, chroma render.Color, palette *level.Palette, chunkSize int) (*level.Palette, *level.Chunker) { // palette: your palette so far (new distinct colors are added)
func imageToChunker(img image.Image, chroma render.Color, palette *level.Palette, chunkSize uint8) (*level.Palette, *level.Chunker) {
var ( var (
chunker = level.NewChunker(chunkSize) chunker = level.NewChunker(chunkSize)
bounds = img.Bounds() bounds = img.Bounds()
@ -289,6 +315,7 @@ func imageToChunker(img image.Image, chroma render.Color, palette *level.Palette
// Cache a palette of unique colors as we go. // Cache a palette of unique colors as we go.
var uniqueColor = map[string]*level.Swatch{} var uniqueColor = map[string]*level.Swatch{}
var newColors = map[string]*level.Swatch{} // new ones discovered this time
for _, swatch := range palette.Swatches { for _, swatch := range palette.Swatches {
uniqueColor[swatch.Color.String()] = swatch uniqueColor[swatch.Color.String()] = swatch
} }
@ -310,9 +337,10 @@ func imageToChunker(img image.Image, chroma render.Color, palette *level.Palette
Color: color, Color: color,
} }
uniqueColor[color.String()] = swatch uniqueColor[color.String()] = swatch
newColors[color.String()] = swatch
} }
chunker.Set(render.NewPoint(int32(x), int32(y)), swatch) chunker.Set(render.NewPoint(x, y), swatch)
} }
} }
@ -323,7 +351,12 @@ func imageToChunker(img image.Image, chroma render.Color, palette *level.Palette
} }
sort.Strings(sortedColors) sort.Strings(sortedColors)
for _, hex := range sortedColors { for _, hex := range sortedColors {
palette.Swatches = append(palette.Swatches, uniqueColor[hex]) if _, ok := newColors[hex]; ok {
if err := palette.AddSwatch(uniqueColor[hex]); err != nil {
log.Error("Could not add more colors to the palette: %s", err)
panic(err.Error())
}
}
} }
palette.Inflate() palette.Inflate()

View File

@ -0,0 +1,242 @@
package commands
import (
"fmt"
"os"
"strconv"
"strings"
"git.kirsle.net/SketchyMaze/doodle/pkg/doodads"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/go/render"
"github.com/urfave/cli/v2"
)
// EditDoodad allows writing doodad metadata.
var EditDoodad *cli.Command
func init() {
EditDoodad = &cli.Command{
Name: "edit-doodad",
Usage: "update metadata for a Doodad file",
ArgsUsage: "<filename.doodad>",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Usage: "limit output (don't show doodad data at the end)",
},
&cli.StringFlag{
Name: "title",
Usage: "set the doodad title",
},
&cli.StringFlag{
Name: "author",
Usage: "set the doodad author",
},
&cli.StringFlag{
Name: "hitbox",
Usage: "set the doodad hitbox (X,Y,W,H or W,H format)",
},
&cli.StringFlag{
Name: "tag",
Aliases: []string{"t"},
Usage: "set a key/value tag on the doodad, in key=value format. Empty value deletes the tag.",
},
&cli.StringFlag{
Name: "option",
Aliases: []string{"o"},
Usage: "set an option on the doodad, in key=type=default format, e.g. active=bool=true, speed=int=10, name=str. Value types are bool, str, int.",
},
&cli.BoolFlag{
Name: "hide",
Usage: "Hide the doodad from the palette",
},
&cli.BoolFlag{
Name: "unhide",
Usage: "Unhide the doodad from the palette",
},
&cli.BoolFlag{
Name: "lock",
Usage: "write-lock the level file",
},
&cli.BoolFlag{
Name: "unlock",
Usage: "remove the write-lock on the level file",
},
&cli.BoolFlag{
Name: "touch",
Usage: "simply load and re-save the doodad, to migrate it to a zipfile",
},
},
Action: func(c *cli.Context) error {
if c.NArg() < 1 {
return cli.Exit(
"Usage: doodad edit-doodad <filename.doodad>",
1,
)
}
var filenames = c.Args().Slice()
for _, filename := range filenames {
if err := editDoodad(c, filename); err != nil {
log.Error("%s: %s", filename, err)
}
}
return nil
},
}
}
func editDoodad(c *cli.Context, filename string) error {
var modified bool
dd, err := doodads.LoadJSON(filename)
if err != nil {
return fmt.Errorf("Failed to load %s: %s", filename, err)
}
log.Info("Edit Doodad: %s", filename)
/***************************
* Update level properties *
***************************/
if c.Bool("touch") {
log.Info("Just touching and resaving the file")
modified = true
}
if c.String("title") != "" {
dd.Title = c.String("title")
log.Info("Set title: %s", dd.Title)
modified = true
}
if c.String("author") != "" {
dd.Author = c.String("author")
log.Info("Set author: %s", dd.Author)
modified = true
}
if c.String("hitbox") != "" {
// Setting a hitbox, parse it out.
parts := strings.Split(c.String("hitbox"), ",")
var ints []int
for _, part := range parts {
a, err := strconv.Atoi(strings.TrimSpace(part))
if err != nil {
return err
}
ints = append(ints, a)
}
if len(ints) == 2 {
dd.Hitbox = render.NewRect(ints[0], ints[1])
modified = true
} else if len(ints) == 4 {
dd.Hitbox = render.Rect{
X: ints[0],
Y: ints[1],
W: ints[2],
H: ints[3],
}
modified = true
} else {
return cli.Exit("Hitbox should be in X,Y,W,H or just W,H format, 2 or 4 numbers.", 1)
}
}
// Tags.
tag := c.String("tag")
if len(tag) > 0 {
parts := strings.SplitN(tag, "=", 3)
if len(parts) != 2 {
log.Error("--tag: must be in format `key=value`. Value may be blank to delete a tag. len=%d tag=%s got=%+v", len(parts), tag, parts)
os.Exit(1)
}
var (
key = parts[0]
value = parts[1]
)
if value == "" {
log.Debug("Delete tag '%s'", key)
delete(dd.Tags, key)
} else {
log.Debug("Set tag '%s' to '%s'", key, value)
dd.Tags[key] = value
}
modified = true
}
// Options.
opt := c.String("option")
if len(opt) > 0 {
parts := strings.SplitN(opt, "=", 3)
if len(parts) < 2 {
log.Error("--option: must be in format `name=type` or `name=type=value`")
os.Exit(1)
}
var (
name = parts[0]
dataType = parts[1]
value string
)
if len(parts) == 3 {
value = parts[2]
}
// Validate the data types.
if dataType != "bool" && dataType != "str" && dataType != "int" {
log.Error("--option: invalid type, should be a bool, str or int")
os.Exit(1)
}
value = dd.SetOption(name, dataType, value)
log.Info("Set option %s (%s) = %s", name, dataType, value)
modified = true
}
if c.Bool("hide") {
dd.Hidden = true
log.Info("Marked doodad Hidden")
modified = true
} else if c.Bool("unhide") {
dd.Hidden = false
log.Info("Doodad is no longer Hidden")
modified = true
}
if c.Bool("lock") {
dd.Locked = true
log.Info("Write lock enabled.")
modified = true
} else if c.Bool("unlock") {
dd.Locked = false
log.Info("Write lock disabled.")
modified = true
}
/******************************
* Save level changes to disk *
******************************/
if modified {
if err := dd.WriteJSON(filename); err != nil {
return cli.Exit(fmt.Sprintf("Write error: %s", err), 1)
}
} else {
log.Warn("Note: No changes made to level")
}
if c.Bool("quiet") {
return nil
}
return showDoodad(c, filename)
}

View File

@ -0,0 +1,265 @@
package commands
import (
"errors"
"fmt"
"git.kirsle.net/SketchyMaze/doodle/pkg/balance"
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/go/render"
"github.com/urfave/cli/v2"
)
// EditLevel allows writing level metadata.
var EditLevel *cli.Command
func init() {
EditLevel = &cli.Command{
Name: "edit-level",
Usage: "update metadata for a Level file",
ArgsUsage: "<filename.level>",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Usage: "limit output (don't show doodad data at the end)",
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "write to a different output file than the input (especially for --resize)",
},
&cli.StringFlag{
Name: "title",
Usage: "set the level title",
},
&cli.StringFlag{
Name: "author",
Usage: "set the level author",
},
&cli.StringFlag{
Name: "password",
Usage: "set the level password",
},
&cli.StringFlag{
Name: "type",
Usage: "set the page type. One of: Unbounded, Bounded, NoNegativeSpace, Bordered",
},
&cli.StringFlag{
Name: "max-size",
Usage: "set the bounded level page max size (WxH format, like 2550x3300)",
},
&cli.IntFlag{
Name: "resize",
Usage: "change the chunk size, and re-encode the whole level into chunks of the new size",
},
&cli.StringFlag{
Name: "wallpaper",
Usage: "set the wallpaper filename",
},
&cli.BoolFlag{
Name: "lock",
Usage: "write-lock the level file",
},
&cli.BoolFlag{
Name: "unlock",
Usage: "remove the write-lock on the level file",
},
&cli.StringFlag{
Name: "remove-actor",
Usage: "Remove all instances of the actor from the level. Value is their filename or UUID.",
},
&cli.BoolFlag{
Name: "touch",
Usage: "simply load and re-save the level, to migrate it to a zipfile",
},
},
Action: func(c *cli.Context) error {
if c.NArg() < 1 {
return cli.Exit(
"Usage: doodad edit-level <filename.level>",
1,
)
}
var filenames = c.Args().Slice()
for _, filename := range filenames {
if err := editLevel(c, filename); err != nil {
log.Error("%s: %s", filename, err)
}
}
return nil
},
}
}
func editLevel(c *cli.Context, filename string) error {
var modified bool
lvl, err := level.LoadJSON(filename)
if err != nil {
return fmt.Errorf("Failed to load %s: %s", filename, err)
}
log.Info("File: %s", filename)
// Migrating it to a different chunk size?
if c.Int("resize") > 0 {
return rechunkLevel(c, filename, lvl)
}
/***************************
* Update level properties *
***************************/
if c.Bool("touch") {
log.Info("Just touching and resaving the file")
modified = true
}
if c.String("title") != "" {
lvl.Title = c.String("title")
log.Info("Set title: %s", lvl.Title)
modified = true
}
if c.String("author") != "" {
lvl.Author = c.String("author")
log.Info("Set author: %s", lvl.Author)
modified = true
}
if c.String("password") != "" {
lvl.Password = c.String("password")
log.Info("Updated level password")
modified = true
}
if c.String("max-size") != "" {
w, h, err := render.ParseResolution(c.String("max-size"))
if err != nil {
log.Error("-max-size: %s", err)
} else {
lvl.MaxWidth = int64(w)
lvl.MaxHeight = int64(h)
modified = true
}
}
if c.Bool("lock") {
lvl.Locked = true
log.Info("Write lock enabled.")
modified = true
} else if c.Bool("unlock") {
lvl.Locked = false
log.Info("Write lock disabled.")
modified = true
}
if c.String("type") != "" {
if pageType, ok := level.PageTypeFromString(c.String("type")); ok {
lvl.PageType = pageType
log.Info("Page Type set to %s", pageType)
modified = true
} else {
log.Error("Invalid -type value. Should be like Unbounded, Bounded, NoNegativeSpace, Bordered")
}
}
if c.String("wallpaper") != "" {
lvl.Wallpaper = c.String("wallpaper")
log.Info("Set wallpaper: %s", c.String("wallpaper"))
modified = true
}
if c.String("remove-actor") != "" {
var (
match = c.String("remove-actor")
removeIDs = []string{}
)
for id, actor := range lvl.Actors {
if id == match || actor.Filename == match {
removeIDs = append(removeIDs, id)
}
}
if len(removeIDs) > 0 {
for _, id := range removeIDs {
delete(lvl.Actors, id)
}
log.Info("Removed %d instances of actor %s from the level.", len(removeIDs), match)
modified = true
} else {
log.Error("Did not find any actors like %s in the level.", match)
}
}
/******************************
* Save level changes to disk *
******************************/
if modified {
if err := lvl.WriteFile(filename); err != nil {
return cli.Exit(fmt.Sprintf("Write error: %s", err), 1)
}
} else {
log.Warn("Note: No changes made to level")
}
if c.Bool("quiet") {
return nil
}
return showLevel(c, filename)
}
// doodad edit-level --resize CHUNK_SIZE
//
// Handles the deep operation of re-copying the old level into a new level
// at the new chunk size.
func rechunkLevel(c *cli.Context, filename string, lvl *level.Level) error {
var chunkSize = balance.ChunkSize
if v := c.Int("resize"); v != 0 {
if v > 255 {
return errors.New("chunk size must be a uint8 <= 255")
}
chunkSize = uint8(v)
}
log.Info("Resizing the level's chunk size.")
log.Info("Current chunk size: %d", lvl.Chunker.Size)
log.Info("Target chunk size: %d", chunkSize)
if output := c.String("output"); output != "" {
filename = output
log.Info("Output file will be: %s", filename)
}
if chunkSize == lvl.Chunker.Size {
return errors.New("the level already has the target chunk size")
}
// Keep the level's current Chunker, and set a new one.
var oldChunker = lvl.Chunker
lvl.Chunker = level.NewChunker(chunkSize)
// Iterate all the Pixels of the old chunker.
log.Info("Copying pixels from old chunker into new chunker (this may take a while)...")
for pixel := range oldChunker.IterPixels() {
lvl.Chunker.Set(
pixel.Point(),
pixel.Swatch,
)
}
log.Info("Writing new data to filename: %s", filename)
if err := lvl.WriteFile(filename); err != nil {
log.Error(err.Error())
}
return showLevel(c, filename)
return nil
}

View File

@ -4,21 +4,21 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"git.kirsle.net/apps/doodle/pkg/doodads" "git.kirsle.net/SketchyMaze/doodle/pkg/doodads"
"git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/SketchyMaze/doodle/pkg/log"
"github.com/urfave/cli" "github.com/urfave/cli/v2"
) )
// InstallScript to add the script to a doodad file. // InstallScript to add the script to a doodad file.
var InstallScript cli.Command var InstallScript *cli.Command
func init() { func init() {
InstallScript = cli.Command{ InstallScript = &cli.Command{
Name: "install-script", Name: "install-script",
Usage: "install the JavaScript source to a doodad", Usage: "install the JavaScript source to a doodad",
ArgsUsage: "<index.js> <filename.doodad>", ArgsUsage: "<index.js> <filename.doodad>",
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ &cli.StringFlag{
Name: "key", Name: "key",
Usage: "chroma key color for transparency on input image files", Usage: "chroma key color for transparency on input image files",
Value: "#ffffff", Value: "#ffffff",
@ -26,7 +26,7 @@ func init() {
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
if c.NArg() != 2 { if c.NArg() != 2 {
return cli.NewExitError( return cli.Exit(
"Usage: doodad install-script <script.js> <filename.doodad>", "Usage: doodad install-script <script.js> <filename.doodad>",
1, 1,
) )
@ -34,19 +34,19 @@ func init() {
var ( var (
args = c.Args() args = c.Args()
scriptFile = args[0] scriptFile = args.Get(0)
doodadFile = args[1] doodadFile = args.Get(1)
) )
// Read the JavaScript source. // Read the JavaScript source.
javascript, err := ioutil.ReadFile(scriptFile) javascript, err := ioutil.ReadFile(scriptFile)
if err != nil { if err != nil {
return cli.NewExitError(err.Error(), 1) return cli.Exit(err.Error(), 1)
} }
doodad, err := doodads.LoadJSON(doodadFile) doodad, err := doodads.LoadJSON(doodadFile)
if err != nil { if err != nil {
return cli.NewExitError( return cli.Exit(
fmt.Sprintf("Failed to read doodad file: %s", err), fmt.Sprintf("Failed to read doodad file: %s", err),
1, 1,
) )

View File

@ -0,0 +1,343 @@
package commands
import (
"archive/zip"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
"time"
"git.kirsle.net/SketchyMaze/doodle/pkg/doodads"
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
"git.kirsle.net/SketchyMaze/doodle/pkg/levelpack"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/SketchyMaze/doodle/pkg/userdir"
"github.com/urfave/cli/v2"
)
// LevelPack creation and management.
var LevelPack *cli.Command
func init() {
LevelPack = &cli.Command{
Name: "levelpack",
Usage: "create and manage .levelpack archives",
ArgsUsage: "-o output.levelpack <list of .level files>",
Subcommands: []*cli.Command{
{
Name: "create",
Usage: "create a new .levelpack file from source files",
ArgsUsage: "<output.levelpack> <input.level> [input.level...]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "title",
Aliases: []string{"t"},
Usage: "set a title for your levelpack, default will use the first level's title",
},
&cli.StringFlag{
Name: "author",
Aliases: []string{"a"},
Usage: "set an author for your levelpack, default will use the first level's author",
},
&cli.StringFlag{
Name: "description",
Aliases: []string{"d"},
Usage: "set a description for your levelpack",
},
&cli.IntFlag{
Name: "free",
Aliases: []string{"f"},
Usage: "set number of free levels (levels unlocked by default), 0 means all unlocked",
},
&cli.StringFlag{
Name: "doodads",
Aliases: []string{"D"},
Usage: "which doodads to embed: none, custom, all",
Value: "custom",
},
},
Action: levelpackCreate,
},
{
Name: "show",
Usage: "print details about a levelpack file",
ArgsUsage: "<input.levelpack>",
Action: levelpackShow,
},
},
Flags: []cli.Flag{},
}
}
// Subcommand `levelpack show`
func levelpackShow(c *cli.Context) error {
if c.NArg() < 1 {
return cli.Exit(
"Usage: doodad levelpack show <file.levelpack>",
1,
)
}
var filename = c.Args().Slice()[0]
if !strings.HasSuffix(filename, ".levelpack") {
return cli.Exit("file must name a .levelpack", 1)
}
lp, err := levelpack.LoadFile(filename)
if err != nil {
return cli.Exit(err, 1)
}
fmt.Printf("===== Levelpack: %s =====\n", filename)
fmt.Println("Headers:")
fmt.Printf(" Title: %s\n", lp.Title)
fmt.Printf(" Author: %s\n", lp.Author)
fmt.Printf(" Description: %s\n", lp.Description)
fmt.Printf(" Free levels: %d\n", lp.FreeLevels)
// List the levels.
fmt.Println("\nLevels:")
for i, lvl := range lp.Levels {
fmt.Printf("%d. %s: %s\n", i+1, lvl.Filename, lvl.Title)
}
// List the doodads.
dl := lp.ListFiles("doodads/")
if len(dl) > 0 {
fmt.Println("\nDoodads:")
for i, doodad := range dl {
fmt.Printf("%d. %s\n", i, doodad)
}
}
return nil
}
// Subcommand `levelpack create`
func levelpackCreate(c *cli.Context) error {
if c.NArg() < 2 {
return cli.Exit(
"Usage: doodad levelpack create <out.levelpack> <in.level ...>",
1,
)
}
var (
args = c.Args().Slice()
outfile = args[0]
infiles = args[1:]
title = c.String("title")
author = c.String("author")
description = c.String("description")
free = c.Int("free")
embedDoodads = c.String("doodads")
)
// Validate params.
if !strings.HasSuffix(outfile, ".levelpack") {
return cli.Exit("Output file must have a .levelpack extension", 1)
}
if embedDoodads != "none" && embedDoodads != "custom" && embedDoodads != "all" {
return cli.Exit(
"--doodads: must be one of all, custom, none",
1,
)
}
var lp = levelpack.LevelPack{
Title: title,
Author: author,
Description: description,
FreeLevels: free,
Created: time.Now().UTC(),
}
// Create a temp directory to work with.
workdir, err := os.MkdirTemp(userdir.CacheDirectory, "levelpack-*")
if err != nil {
return cli.Exit(
fmt.Sprintf("Couldn't make temp folder: %s", err),
1,
)
}
log.Info("Working directory: %s", workdir)
defer os.RemoveAll(workdir)
// Useful folders inside the working directory.
var (
levelDir = filepath.Join(workdir, "levels")
doodadDir = filepath.Join(workdir, "doodads")
assets = []string{
"index.json",
}
)
os.MkdirAll(levelDir, 0755)
os.MkdirAll(doodadDir, 0755)
// Get the list of the game's builtin doodads.
builtins, err := doodads.ListBuiltin()
if err != nil {
return cli.Exit(err, 1)
}
// Read the input levels.
for i, filename := range infiles {
if !strings.HasSuffix(filename, ".level") {
return cli.Exit(
fmt.Sprintf("input file at position %d (%s) was not a .level file", i, filename),
1,
)
}
lvl, err := level.LoadJSON(filename)
if err != nil {
return cli.Exit(
fmt.Sprintf("%s: %s", filename, err),
1,
)
}
// Fill in defaults for --title, --author
if lp.Title == "" {
lp.Title = lvl.Title
}
if lp.Author == "" {
lp.Author = lvl.Author
}
// Log the level in the index.json list.
lp.Levels = append(lp.Levels, levelpack.Level{
UUID: lvl.UUID,
Title: lvl.Title,
Author: lvl.Author,
Filename: filepath.Base(filename),
})
// Grab all the level's doodads to embed in the zip folder.
for _, actor := range lvl.Actors {
// What was the user's embeds request? (--doodads)
if embedDoodads == "none" {
break
} else if embedDoodads == "custom" {
// Custom doodads only.
if isBuiltinDoodad(builtins, actor.Filename) {
log.Warn("Doodad %s is a built-in, skipping embed", actor.Filename)
continue
}
}
if _, err := os.Stat(filepath.Join(doodadDir, actor.Filename)); !os.IsNotExist(err) {
continue
}
log.Info("Adding doodad to zipfile: %s", actor.Filename)
// Get this doodad from the game's built-ins or the user's
// profile directory only. Pulling embedded doodads out of
// the level is NOT supported.
asset, err := doodads.LoadFile(actor.Filename)
if err != nil {
return cli.Exit(
fmt.Sprintf("%s: Doodad file '%s': %s", filename, asset.Filename, err),
1,
)
}
var targetFile = filepath.Join(doodadDir, actor.Filename)
assets = append(assets, targetFile)
log.Debug("Write doodad: %s", targetFile)
err = asset.WriteFile(filepath.Join(doodadDir, actor.Filename))
if err != nil {
return cli.Exit(
fmt.Sprintf("Writing doodad %s: %s", actor.Filename, err),
1,
)
}
}
// Copy the level in.
var targetFile = filepath.Join(levelDir, filepath.Base(filename))
assets = append(assets, targetFile)
log.Info("Write level: %s", filename)
err = copyFile(filename, filepath.Join(levelDir, filepath.Base(filename)))
if err != nil {
return cli.Exit(
fmt.Sprintf("couldn't copy %s to %s: %s", filename, targetFile, err),
1,
)
}
}
log.Info("Writing index.json")
if err := lp.WriteFile(filepath.Join(workdir, "index.json")); err != nil {
return cli.Exit(err, 1)
}
// Zip the levelpack directory.
log.Info("Creating levelpack file: %s", outfile)
zipf, err := os.Create(outfile)
if err != nil {
return cli.Exit(
fmt.Sprintf("failed to create %s: %s", outfile, err),
1,
)
}
zipper := zip.NewWriter(zipf)
defer zipper.Close()
// Embed all the assets.
sort.Strings(assets)
for _, asset := range assets {
asset = strings.TrimPrefix(asset, workdir+"/")
log.Info("Zip: %s", asset)
err := zipFile(zipper, asset, filepath.Join(workdir, asset))
if err != nil {
return cli.Exit(err, 1)
}
}
log.Info("Written: %s", outfile)
return cli.Exit("", 0)
}
// copyFile copies a file on disk to another location.
func copyFile(source, target string) error {
input, err := ioutil.ReadFile(source)
if err != nil {
return err
}
return ioutil.WriteFile(target, input, 0644)
}
// zipFile reads a file on disk to add to a zip file.
// The `key` is the filepath inside the ZIP file, filename is the actual source file on disk.
func zipFile(zf *zip.Writer, key, filename string) error {
input, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
writer, err := zf.Create(key)
if err != nil {
return err
}
_, err = writer.Write(input)
return err
}
// Helper function to test whether a filename is part of the builtin doodads.
func isBuiltinDoodad(doodads []string, filename string) bool {
for _, cmp := range doodads {
if cmp == filename {
return true
}
}
return false
}

View File

@ -0,0 +1,115 @@
package commands
import (
"fmt"
"path/filepath"
"strings"
"git.kirsle.net/SketchyMaze/doodle/pkg/doodads"
"git.kirsle.net/SketchyMaze/doodle/pkg/enum"
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"github.com/urfave/cli/v2"
)
// Resave a Level or Doodad to adapt to file format upgrades.
var Resave *cli.Command
func init() {
Resave = &cli.Command{
Name: "resave",
Usage: "load and re-save a level or doodad file to migrate to newer file format versions",
ArgsUsage: "<.level or .doodad>",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "write to a different file than the input",
},
},
Action: func(c *cli.Context) error {
if c.NArg() < 1 {
return cli.Exit(
"Usage: doodad resave <.level .doodad ...>",
1,
)
}
filenames := c.Args().Slice()
for _, filename := range filenames {
switch strings.ToLower(filepath.Ext(filename)) {
case enum.LevelExt:
if err := resaveLevel(c, filename); err != nil {
log.Error(err.Error())
return cli.Exit("Error", 1)
}
case enum.DoodadExt:
if err := resaveDoodad(c, filename); err != nil {
log.Error(err.Error())
return cli.Exit("Error", 1)
}
default:
log.Error("File %s: not a level or doodad", filename)
}
}
return nil
},
}
}
// resaveLevel shows data about a level file.
func resaveLevel(c *cli.Context, filename string) error {
lvl, err := level.LoadJSON(filename)
if err != nil {
return err
}
log.Info("Loaded level from file: %s", filename)
log.Info("Last saved game version: %s", lvl.GameVersion)
// Different output filename?
if output := c.String("output"); output != "" {
log.Info("Output will be saved to: %s", output)
filename = output
}
if err := lvl.Vacuum(); err != nil {
log.Error("Vacuum error: %s", err)
} else {
log.Info("Run vacuum on level file.")
}
log.Info("Saving back to disk")
if err := lvl.WriteJSON(filename); err != nil {
return fmt.Errorf("couldn't write %s: %s", filename, err)
}
return showLevel(c, filename)
}
func resaveDoodad(c *cli.Context, filename string) error {
dd, err := doodads.LoadJSON(filename)
if err != nil {
return err
}
log.Info("Loaded doodad from file: %s", filename)
log.Info("Last saved game version: %s", dd.GameVersion)
// Different output filename?
if output := c.String("output"); output != "" {
log.Info("Output will be saved to: %s", output)
filename = output
}
if err := dd.Vacuum(); err != nil {
log.Error("Vacuum error: %s", err)
} else {
log.Info("Run vacuum on doodad file.")
}
log.Info("Saving back to disk")
if err := dd.WriteJSON(filename); err != nil {
return fmt.Errorf("couldn't write %s: %s", filename, err)
}
return showDoodad(c, filename)
}

366
cmd/doodad/commands/show.go Normal file
View File

@ -0,0 +1,366 @@
package commands
import (
"bytes"
"encoding/binary"
"fmt"
"path/filepath"
"sort"
"strings"
"git.kirsle.net/SketchyMaze/doodle/pkg/doodads"
"git.kirsle.net/SketchyMaze/doodle/pkg/enum"
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
"git.kirsle.net/SketchyMaze/doodle/pkg/level/rle"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"github.com/urfave/cli/v2"
)
// Show information about a Level or Doodad file.
var Show *cli.Command
func init() {
Show = &cli.Command{
Name: "show",
Usage: "show information about a level or doodad file",
ArgsUsage: "<.level or .doodad>",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "actors",
Usage: "print verbose actor data in Level files",
},
&cli.BoolFlag{
Name: "chunks",
Usage: "print verbose data about all the pixel chunks in a file",
},
&cli.BoolFlag{
Name: "script",
Usage: "print the script from a doodad file and exit",
},
&cli.StringFlag{
Name: "attachment",
Aliases: []string{"a"},
Usage: "print the contents of the attached filename to terminal",
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Usage: "print verbose output (all verbose flags enabled)",
},
&cli.BoolFlag{
Name: "visualize-rle",
Usage: "visually dump RLE encoded chunks to the terminal (VERY noisy for large drawings!)",
},
&cli.StringFlag{
Name: "chunk",
Usage: "specific chunk coordinate; when debugging chunks, only show this chunk (example: 2,-1)",
},
},
Action: func(c *cli.Context) error {
if c.NArg() < 1 {
return cli.Exit(
"Usage: doodad show <.level .doodad ...>",
1,
)
}
filenames := c.Args().Slice()
for _, filename := range filenames {
switch strings.ToLower(filepath.Ext(filename)) {
case enum.LevelExt:
if err := showLevel(c, filename); err != nil {
log.Error(err.Error())
return cli.Exit("Error", 1)
}
case enum.DoodadExt:
if err := showDoodad(c, filename); err != nil {
log.Error(err.Error())
return cli.Exit("Error", 1)
}
default:
log.Error("File %s: not a level or doodad", filename)
}
}
return nil
},
}
}
// showLevel shows data about a level file.
func showLevel(c *cli.Context, filename string) error {
lvl, err := level.LoadJSON(filename)
if err != nil {
return err
}
// Are we printing an attached file?
if filename := c.String("attachment"); filename != "" {
if data, err := lvl.GetFile(filename); err == nil {
fmt.Print(string(data))
return nil
} else {
fmt.Printf("Couldn't get attached file '%s': %s\n", filename, err)
return err
}
}
// Is it a new zipfile format?
var fileType = "json or gzip"
if lvl.Zipfile != nil {
fileType = "zipfile"
}
fmt.Printf("===== Level: %s =====\n", filename)
fmt.Println("Headers:")
fmt.Printf(" File format: %s\n", fileType)
fmt.Printf(" File version: %d\n", lvl.Version)
fmt.Printf(" Game version: %s\n", lvl.GameVersion)
fmt.Printf(" Level UUID: %s\n", lvl.UUID)
fmt.Printf(" Level title: %s\n", lvl.Title)
fmt.Printf(" Author: %s\n", lvl.Author)
fmt.Printf(" Password: %s\n", lvl.Password)
fmt.Printf(" Locked: %+v\n", lvl.Locked)
fmt.Println("")
fmt.Println("Game Rules:")
fmt.Printf(" Difficulty: %s (%d)\n", lvl.GameRule.Difficulty, lvl.GameRule.Difficulty)
fmt.Printf(" Survival: %+v\n", lvl.GameRule.Survival)
fmt.Println("")
showPalette(lvl.Palette)
fmt.Println("Level Settings:")
fmt.Printf(" Page type: %s\n", lvl.PageType.String())
fmt.Printf(" Max size: %dx%d\n", lvl.MaxWidth, lvl.MaxHeight)
fmt.Printf(" Wallpaper: %s\n", lvl.Wallpaper)
fmt.Println("")
fmt.Println("Attached Files:")
if files := lvl.ListFiles(); len(files) > 0 {
for _, v := range files {
data, _ := lvl.GetFile(v)
fmt.Printf(" %s: %d bytes\n", v, len(data))
}
fmt.Println("")
} else {
fmt.Printf(" None\n\n")
}
// Print the actor information.
fmt.Println("Actors:")
fmt.Printf(" Level contains %d actors\n", len(lvl.Actors))
if c.Bool("actors") || c.Bool("verbose") {
fmt.Println(" List of Actors:")
for id, actor := range lvl.Actors {
fmt.Printf(" - Name: %s\n", actor.Filename)
fmt.Printf(" UUID: %s\n", id)
fmt.Printf(" At: %s\n", actor.Point)
if len(actor.Options) > 0 {
var ordered = []string{}
for name := range actor.Options {
ordered = append(ordered, name)
}
sort.Strings(ordered)
fmt.Println(" Options:")
for _, name := range ordered {
val := actor.Options[name]
fmt.Printf(" %s %s = %v\n", val.Type, val.Name, val.Value)
}
}
if c.Bool("links") {
for _, link := range actor.Links {
if other, ok := lvl.Actors[link]; ok {
fmt.Printf(" Link: %s (%s)\n", link, other.Filename)
} else {
fmt.Printf(" Link: %s (**UNRESOLVED**)", link)
}
}
}
}
fmt.Println("")
} else {
fmt.Print(" Use -actors or -verbose to serialize Actors\n\n")
}
// Serialize chunk information.
showChunker(c, lvl.Chunker, 0)
fmt.Println("")
return nil
}
func showDoodad(c *cli.Context, filename string) error {
dd, err := doodads.LoadJSON(filename)
if err != nil {
return err
}
if c.Bool("script") {
fmt.Printf("// %s.js\n", filename)
fmt.Println(strings.TrimSpace(dd.Script))
return nil
}
// Is it a new zipfile format?
var fileType = "json or gzip"
if dd.Zipfile != nil {
fileType = "zipfile"
}
fmt.Printf("===== Doodad: %s =====\n", filename)
fmt.Println("Headers:")
fmt.Printf(" File format: %s\n", fileType)
fmt.Printf(" File version: %d\n", dd.Version)
fmt.Printf(" Game version: %s\n", dd.GameVersion)
fmt.Printf(" Doodad title: %s\n", dd.Title)
fmt.Printf(" Author: %s\n", dd.Author)
fmt.Printf(" Dimensions: %s\n", dd.Size)
fmt.Printf(" Hitbox: %s\n", dd.Hitbox)
fmt.Printf(" Locked: %+v\n", dd.Locked)
fmt.Printf(" Hidden: %+v\n", dd.Hidden)
fmt.Printf(" Script size: %d bytes\n", len(dd.Script))
fmt.Println("")
if len(dd.Tags) > 0 {
fmt.Println("Tags:")
for k, v := range dd.Tags {
fmt.Printf(" %s: %s\n", k, v)
}
fmt.Println("")
}
if len(dd.Options) > 0 {
var ordered = []string{}
for name := range dd.Options {
ordered = append(ordered, name)
}
sort.Strings(ordered)
fmt.Println("Options:")
for _, name := range ordered {
opt := dd.Options[name]
fmt.Printf(" %s %s = %v\n", opt.Type, opt.Name, opt.Default)
}
fmt.Println("")
}
showPalette(dd.Palette)
for i, layer := range dd.Layers {
fmt.Printf("Layer %d: %s\n", i, layer.Name)
showChunker(c, layer.Chunker, i)
}
fmt.Println("")
return nil
}
func showPalette(pal *level.Palette) {
fmt.Println("Palette:")
for _, sw := range pal.Swatches {
fmt.Printf(" - Swatch name: %s\n", sw.Name)
fmt.Printf(" Attributes: %s\n", sw.Attributes())
fmt.Printf(" Color: %s\n", sw.Color.ToHex())
}
fmt.Println("")
}
func showChunker(c *cli.Context, ch *level.Chunker, layer int) {
var (
worldSize = ch.WorldSize()
chunkSize = int(ch.Size)
width = worldSize.W - worldSize.X
height = worldSize.H - worldSize.Y
// Chunk debugging CLI options.
visualize = c.Bool("visualize-rle")
specificChunk = c.String("chunk")
)
// If it's a Zipfile, count its chunks.
var chunkCount = len(ch.Chunks)
if ch.Zipfile != nil {
chunkCount = len(level.ChunksInZipfile(ch.Zipfile, layer))
}
fmt.Println("Chunks:")
fmt.Printf(" Pixels Per Chunk: %d^2\n", ch.Size)
fmt.Printf(" Number Generated: %d\n", chunkCount)
fmt.Printf(" Coordinate Range: (%d,%d) ... (%d,%d)\n",
worldSize.X,
worldSize.Y,
worldSize.W,
worldSize.H,
)
fmt.Printf(" World Dimensions: %dx%d\n", width, height)
// Verbose chunk information.
if c.Bool("chunks") || c.Bool("verbose") {
fmt.Println(" Chunk Details:")
for point := range ch.IterChunks() {
// Debugging specific chunk coordinate?
if specificChunk != "" && point.String() != specificChunk {
log.Warn("Skip chunk %s: not the specific chunk you're looking for", point)
continue
}
chunk, ok := ch.GetChunk(point)
if !ok {
continue
}
fmt.Printf(" - Coord: %s\n", point)
fmt.Printf(" Type: %s\n", chunkTypeToName(chunk.Type))
fmt.Printf(" Range: (%d,%d) ... (%d,%d)\n",
int(point.X)*chunkSize,
int(point.Y)*chunkSize,
(int(point.X)*chunkSize)+chunkSize,
(int(point.Y)*chunkSize)+chunkSize,
)
fmt.Printf(" Usage: %f (%d len of %d)\n", chunk.Usage(), chunk.Len(), chunkSize*chunkSize)
// Visualize the RLE encoded chunks?
if visualize && chunk.Type == level.RLEType {
ext, bin, err := ch.RawChunkFromZipfile(point)
if err != nil {
log.Error(err.Error())
continue
} else if ext != ".bin" {
log.Error("Unexpected filetype for RLE compressed chunk (expected .bin, got %s)", ext)
continue
}
// Read off the first byte (chunk type)
var reader = bytes.NewBuffer(bin)
binary.ReadUvarint(reader)
bin = reader.Bytes()
grid, err := rle.NewGrid(chunkSize)
if err != nil {
log.Error(err.Error())
continue
}
grid.Decompress(bin)
fmt.Println(grid.Visualize())
}
}
} else {
fmt.Println(" Use -chunks or -verbose to serialize Chunks")
}
fmt.Println("")
}
func chunkTypeToName(v uint64) string {
switch v {
case level.MapType:
return "map"
case level.RLEType:
return "rle map"
default:
return fmt.Sprintf("type %d", v)
}
}

View File

@ -3,14 +3,15 @@ package main
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"sort" "sort"
"time" "time"
"git.kirsle.net/apps/doodle/cmd/doodad/commands" "git.kirsle.net/SketchyMaze/doodle/cmd/doodad/commands"
doodle "git.kirsle.net/apps/doodle/pkg" "git.kirsle.net/SketchyMaze/doodle/pkg/branding/builds"
"github.com/urfave/cli" "git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/SketchyMaze/doodle/pkg/plus/bootstrap"
"github.com/urfave/cli/v2"
) )
// Build variables. // Build variables.
@ -26,25 +27,33 @@ func init() {
} }
func main() { func main() {
bootstrap.InitPlugins()
app := cli.NewApp() app := cli.NewApp()
app.Name = "doodad" app.Name = "doodad"
app.Usage = "command line interface for Doodle" app.Usage = "command line interface for Doodle"
app.Version = fmt.Sprintf("%s build %s. Built on %s", app.Version = fmt.Sprintf("%s build %s. Built on %s",
doodle.Version, builds.Version,
Build, Build,
BuildDate, BuildDate,
) )
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.BoolFlag{ &cli.BoolFlag{
Name: "debug, d", Name: "debug, d",
Usage: "enable debug level logging", Usage: "enable debug level logging",
}, },
} }
app.Commands = []cli.Command{ app.Commands = []*cli.Command{
commands.Convert, commands.Convert,
commands.Show,
commands.Resave,
commands.EditLevel,
commands.EditDoodad,
commands.InstallScript, commands.InstallScript,
commands.LevelPack,
} }
sort.Sort(cli.FlagsByName(app.Flags)) sort.Sort(cli.FlagsByName(app.Flags))
@ -52,6 +61,7 @@ func main() {
err := app.Run(os.Args) err := app.Run(os.Args)
if err != nil { if err != nil {
log.Fatal(err) log.Error("Fatal: %s", err)
os.Exit(1)
} }
} }

View File

@ -0,0 +1,44 @@
package command
import (
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/SketchyMaze/dpp/license"
"github.com/urfave/cli/v2"
)
// Key a license key for Sketchy Maze.
var Key *cli.Command
func init() {
Key = &cli.Command{
Name: "key",
Usage: "generate an admin ECDSA signing key",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "public",
Usage: "Filename to write the public key to (.pem)",
Required: true,
},
&cli.StringFlag{
Name: "private",
Usage: "Filename to write the private key to (.pem)",
Required: true,
},
},
Action: func(c *cli.Context) error {
key, err := license.AdminGenerateKeys()
if err != nil {
return cli.Exit(err.Error(), 1)
}
err = license.AdminWriteKeys(key, c.String("private"), c.String("public"))
if err != nil {
return cli.Exit(err.Error(), 1)
}
log.Info("Written private key: %s", c.String("private"))
log.Info("Written public key: %s", c.String("public"))
return nil
},
}
}

View File

@ -0,0 +1,73 @@
package command
import (
"fmt"
"io/ioutil"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/SketchyMaze/dpp/license"
"github.com/urfave/cli/v2"
)
// Sign a license key for Sketchy Maze.
var Sign *cli.Command
func init() {
Sign = &cli.Command{
Name: "sign",
Usage: "sign a license key for the paid version of Sketchy Maze.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "key",
Aliases: []string{"k"},
Usage: "Private key .pem file for signing",
Required: true,
},
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Usage: "User name for certificate",
Required: true,
},
&cli.StringFlag{
Name: "email",
Aliases: []string{"e"},
Usage: "User email address",
Required: true,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Output file, default outputs to console",
},
},
Action: func(c *cli.Context) error {
key, err := license.AdminLoadPrivateKey(c.String("key"))
if err != nil {
return cli.Exit(err.Error(), 1)
}
reg := license.Registration{
Name: c.String("name"),
Email: c.String("email"),
}
result, err := license.AdminSignRegistration(key, reg)
if err != nil {
return cli.Exit(err.Error(), 1)
}
// Writing to an output file?
if output := c.String("output"); output != "" {
log.Info("Write to: %s", output)
if err := ioutil.WriteFile(output, []byte(result), 0644); err != nil {
return cli.Exit(err, 1)
}
} else {
fmt.Println(result)
}
return nil
},
}
}

View File

@ -0,0 +1,92 @@
package command
import (
"fmt"
"strings"
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
"git.kirsle.net/SketchyMaze/doodle/pkg/levelpack"
"git.kirsle.net/SketchyMaze/dpp/license"
"git.kirsle.net/SketchyMaze/dpp/license/levelsigning"
"github.com/urfave/cli/v2"
)
// SignLevel a license key for Sketchy Maze.
var SignLevel *cli.Command
func init() {
SignLevel = &cli.Command{
Name: "sign-level",
Usage: "sign a level file so that it may use embedded assets in free versions of the game.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "key",
Aliases: []string{"k"},
Usage: "Private key .pem file for signing",
Required: true,
},
&cli.StringFlag{
Name: "input",
Aliases: []string{"i"},
Usage: "Input file name (.level or .levelpack)",
Required: true,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Output file, default outputs to console",
},
},
Action: func(c *cli.Context) error {
key, err := license.AdminLoadPrivateKey(c.String("key"))
if err != nil {
return cli.Exit(err.Error(), 1)
}
var (
filename = c.String("input")
output = c.String("output")
)
if output == "" {
output = filename
}
// Sign a level?
if strings.HasSuffix(filename, ".level") {
lvl, err := level.LoadJSON(filename)
if err != nil {
return cli.Exit(err.Error(), 1)
}
// Sign it.
if sig, err := levelsigning.SignLevel(key, lvl); err != nil {
return cli.Exit(fmt.Errorf("couldn't sign level: %s", err), 1)
} else {
lvl.Signature = sig
err := lvl.WriteFile(output)
if err != nil {
return cli.Exit(err.Error(), 1)
}
}
} else if strings.HasSuffix(filename, ".levelpack") {
lp, err := levelpack.LoadFile(filename)
if err != nil {
return cli.Exit(err.Error(), 1)
}
// Sign it.
if sig, err := levelsigning.SignLevelPack(key, lp); err != nil {
return cli.Exit(fmt.Errorf("couldn't sign levelpack: %s", err), 1)
} else {
lp.Signature = sig
err := lp.WriteZipfile(output)
if err != nil {
return cli.Exit(err.Error(), 1)
}
}
}
return nil
},
}
}

View File

@ -0,0 +1,59 @@
package command
import (
"io/ioutil"
"time"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/SketchyMaze/dpp/license"
"github.com/urfave/cli/v2"
)
// Verify a license key for Sketchy Maze.
var Verify *cli.Command
func init() {
Verify = &cli.Command{
Name: "verify",
Usage: "check the signature on a license key",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "key",
Aliases: []string{"k"},
Usage: "Public key .pem file that signed the JWT",
Required: true,
},
&cli.StringFlag{
Name: "filename",
Aliases: []string{"f"},
Usage: "File name of the license file to validate",
Required: true,
},
},
Action: func(c *cli.Context) error {
key, err := license.AdminLoadPublicKey(c.String("key"))
if err != nil {
return cli.Exit(err.Error(), 1)
}
jwt, err := ioutil.ReadFile(c.String("filename"))
if err != nil {
return cli.Exit(err.Error(), 1)
}
reg, err := license.Validate(key, string(jwt))
if err != nil {
return cli.Exit(err.Error(), 1)
}
log.Info("Registration valid")
log.Info(" Name: %s", reg.Name)
log.Info(" Email: %s", reg.Email)
log.Info(" Issued: %s", time.Unix(reg.IssuedAt, 0))
log.Info(" NBF: %s", time.Unix(reg.NotBefore, 0))
log.Info("Raw:\n%+v", reg)
return nil
},
}
}

View File

@ -0,0 +1,73 @@
package command
import (
"strings"
"git.kirsle.net/SketchyMaze/doodle/pkg/level"
"git.kirsle.net/SketchyMaze/doodle/pkg/levelpack"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/SketchyMaze/dpp/license"
"git.kirsle.net/SketchyMaze/dpp/license/levelsigning"
"github.com/urfave/cli/v2"
)
// VerifyLevel a license key for Sketchy Maze.
var VerifyLevel *cli.Command
func init() {
VerifyLevel = &cli.Command{
Name: "verify-level",
Usage: "check the signature on a level or levelpack file.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "key",
Aliases: []string{"k"},
Usage: "Public key .pem file that signed the level",
Required: true,
},
&cli.StringFlag{
Name: "filename",
Aliases: []string{"f"},
Usage: "File name of the .level or .levelpack",
Required: true,
},
},
Action: func(c *cli.Context) error {
key, err := license.AdminLoadPublicKey(c.String("key"))
if err != nil {
return cli.Exit(err.Error(), 1)
}
filename := c.String("filename")
if strings.HasSuffix(filename, ".level") {
lvl, err := level.LoadJSON(filename)
if err != nil {
return cli.Exit(err.Error(), 1)
}
// Verify it.
if ok := levelsigning.VerifyLevel(key, lvl); !ok {
log.Error("Signature is not valid!")
return cli.Exit("", 1)
} else {
log.Info("Level signature is OK!")
}
} else if strings.HasSuffix(filename, ".levelpack") {
lp, err := levelpack.LoadFile(filename)
if err != nil {
return cli.Exit(err.Error(), 1)
}
// Verify it.
if ok := levelsigning.VerifyLevelPack(key, lp); !ok {
log.Error("Signature is not valid!")
return cli.Exit("", 1)
} else {
log.Info("Levelpack signature is OK!")
}
}
return nil
},
}
}

61
cmd/doodle-admin/main.go Normal file
View File

@ -0,0 +1,61 @@
// doodle-admin performs secret admin tasks like generating license keys.
package main
import (
"fmt"
"log"
"os"
"sort"
"time"
"git.kirsle.net/SketchyMaze/doodle/cmd/doodle-admin/command"
"git.kirsle.net/SketchyMaze/doodle/pkg/branding"
"github.com/urfave/cli/v2"
)
// Build variables.
var (
Build = "N/A"
BuildDate string
)
func init() {
if BuildDate == "" {
BuildDate = time.Now().Format(time.RFC3339)
}
}
func main() {
app := cli.NewApp()
app.Name = "doodle-admin"
app.Usage = "Admin tasks for Sketchy Maze."
app.Version = fmt.Sprintf("%s build %s. Built on %s",
branding.Version,
Build,
BuildDate,
)
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "debug, d",
Usage: "enable debug level logging",
},
}
app.Commands = []*cli.Command{
command.Key,
command.Sign,
command.Verify,
command.SignLevel,
command.VerifyLevel,
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}

View File

@ -1,17 +1,38 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"log"
"os" "os"
"path/filepath"
"regexp"
"runtime" "runtime"
"runtime/pprof"
"sort" "sort"
"strconv"
"time" "time"
"git.kirsle.net/apps/doodle/lib/render/sdl" "git.kirsle.net/SketchyMaze/doodle/assets"
doodle "git.kirsle.net/apps/doodle/pkg" doodle "git.kirsle.net/SketchyMaze/doodle/pkg"
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/SketchyMaze/doodle/pkg/balance"
"github.com/urfave/cli" "git.kirsle.net/SketchyMaze/doodle/pkg/branding"
"git.kirsle.net/SketchyMaze/doodle/pkg/branding/builds"
"git.kirsle.net/SketchyMaze/doodle/pkg/chatbot"
"git.kirsle.net/SketchyMaze/doodle/pkg/gamepad"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/SketchyMaze/doodle/pkg/native"
"git.kirsle.net/SketchyMaze/doodle/pkg/plus/bootstrap"
"git.kirsle.net/SketchyMaze/doodle/pkg/plus/dpp"
"git.kirsle.net/SketchyMaze/doodle/pkg/shmem"
"git.kirsle.net/SketchyMaze/doodle/pkg/sound"
"git.kirsle.net/SketchyMaze/doodle/pkg/sprites"
"git.kirsle.net/SketchyMaze/doodle/pkg/usercfg"
"git.kirsle.net/SketchyMaze/doodle/pkg/userdir"
golog "git.kirsle.net/go/log"
"git.kirsle.net/go/render"
"git.kirsle.net/go/render/sdl"
"github.com/urfave/cli/v2"
sdl2 "github.com/veandco/go-sdl2/sdl"
_ "image/png" _ "image/png"
) )
@ -26,52 +47,214 @@ func init() {
if BuildDate == "" { if BuildDate == "" {
BuildDate = time.Now().Format(time.RFC3339) BuildDate = time.Now().Format(time.RFC3339)
} }
// Use all the CPU cores for collision detection and other load balanced
// goroutine work in the app.
runtime.GOMAXPROCS(runtime.NumCPU())
} }
func main() { func main() {
runtime.LockOSThread() runtime.LockOSThread()
bootstrap.InitPlugins()
app := cli.NewApp() app := cli.NewApp()
app.Name = "doodle" app.Name = "doodle"
app.Usage = "command line interface for Doodle" app.Usage = fmt.Sprintf("%s - %s", branding.AppName, branding.Summary)
// Load user settings from disk ASAP.
if err := usercfg.Load(); err != nil {
log.Error("Error loading user settings (defaults will be used): %s", err)
}
// Set default user settings.
if usercfg.Current.CrosshairColor == render.Invisible {
usercfg.Current.CrosshairColor = balance.DefaultCrosshairColor
usercfg.Save()
}
// Set GameController style.
gamepad.SetStyle(gamepad.Style(usercfg.Current.ControllerStyle))
app.Version = fmt.Sprintf("%s build %s. Built on %s", app.Version = fmt.Sprintf("%s build %s. Built on %s",
doodle.Version, builds.Version,
Build, Build,
BuildDate, BuildDate,
) )
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.BoolFlag{ &cli.BoolFlag{
Name: "debug, d", Name: "debug",
Usage: "enable debug level logging", Aliases: []string{"d"},
Usage: "enable debug level logging",
}, },
cli.BoolFlag{ &cli.StringFlag{
Name: "edit, e", Name: "log",
Usage: "edit the map given on the command line (instead of play it)", Aliases: []string{"o"},
Usage: "path on disk to copy the game's standard output logs (default goes to your game profile directory)",
}, },
cli.BoolFlag{ &cli.StringFlag{
Name: "pprof",
Usage: "record pprof metrics to a filename",
},
&cli.StringFlag{
Name: "chdir",
Usage: "working directory for the game's runtime package",
},
&cli.BoolFlag{
Name: "new",
Aliases: []string{"n"},
Usage: "open immediately to the level editor",
},
&cli.BoolFlag{
Name: "edit",
Aliases: []string{"e"},
Usage: "edit the map given on the command line (instead of play it)",
},
&cli.StringFlag{
Name: "window",
Aliases: []string{"w"},
Usage: "set the window size (e.g. -w 1024x768) or special value: desktop, mobile, landscape, maximized",
},
&cli.BoolFlag{
Name: "touch",
Aliases: []string{"t"},
Usage: "force TouchScreenMode to be on at all times, which hides the mouse cursor",
},
&cli.BoolFlag{
Name: "guitest", Name: "guitest",
Usage: "enter the GUI Test scene on startup", Usage: "enter the GUI Test scene on startup",
}, },
&cli.BoolFlag{
Name: "experimental",
Usage: "enable experimental Feature Flags",
},
&cli.BoolFlag{
Name: "offline",
Usage: "offline mode, disables check for new updates",
},
} }
app.Action = func(c *cli.Context) error { app.Action = func(c *cli.Context) error {
// Set the log level now if debugging is enabled.
if c.Bool("debug") {
log.Logger.Config.Level = golog.DebugLevel
}
// Write the game's log to disk.
if err := initLogFile(c.String("log")); err != nil {
log.Error("Couldn't write logs to disk: %s", err)
}
log.Info("Starting %s %s", app.Name, app.Version)
// Print registration information, + also this sets the DefaultAuthor field.
if reg, err := dpp.Driver.GetRegistration(); err == nil {
log.Info("Registered to %s", reg.Name)
}
// --chdir into a different working directory? e.g. for Flatpak especially.
if err := setWorkingDirectory(c); err != nil {
log.Error("Couldn't set working directory: %s", err)
}
// Recording pprof stats?
if cpufile := c.String("pprof"); cpufile != "" {
log.Info("Saving CPU profiling data to %s", cpufile)
fh, err := os.Create(cpufile)
if err != nil {
log.Error("--pprof: can't create file: %s", err)
return err
}
defer fh.Close()
if err := pprof.StartCPUProfile(fh); err != nil {
log.Error("pprof: %s", err)
return err
}
defer pprof.StopCPUProfile()
}
var filename string var filename string
if c.NArg() > 0 { if c.NArg() > 0 {
filename = c.Args().Get(0) filename = c.Args().Get(0)
} }
// Setting a custom resolution?
var maximize = true
if c.String("window") != "" {
if err := setResolution(c.String("window")); err != nil {
panic(err)
}
maximize = false
}
// Enable feature flags?
if c.Bool("experimental") || usercfg.Current.EnableFeatures {
balance.FeaturesOn()
}
// Set other program flags.
shmem.OfflineMode = c.Bool("offline")
native.ForceTouchScreenModeAlwaysOn = c.Bool("touch")
// SDL engine. // SDL engine.
engine := sdl.New( engine := sdl.New(
"Doodle v"+doodle.Version, fmt.Sprintf("%s v%s", branding.AppName, branding.Version),
balance.Width, balance.Width,
balance.Height, balance.Height,
) )
// Activate game controller event support.
sdl2.GameControllerEventState(1)
// Load the SDL fonts in from bindata storage.
if fonts, err := assets.AssetDir("assets/fonts"); err == nil {
for _, file := range fonts {
data, err := assets.Asset("assets/fonts/" + file)
if err != nil {
panic(err)
}
sdl.InstallFont(file, data)
}
} else {
panic(err)
}
// Preload all sound effects.
sound.PreloadAll()
game := doodle.New(c.Bool("debug"), engine) game := doodle.New(c.Bool("debug"), engine)
game.SetupEngine() game.SetupEngine()
// Start with maximized window unless -w was given.
if maximize {
log.Info("Maximize window")
engine.Maximize()
}
// Reload usercfg - if their settings.json doesn't exist, we try and pick a
// default "hide touch hints" based on touch device presence - which is only
// known after SetupEngine.
usercfg.Load()
// Hide the mouse cursor over the window, we draw our own sprite image for it.
engine.ShowCursor(false)
// Set the app window icon.
if engine, ok := game.Engine.(*sdl.Renderer); ok {
if icon, err := sprites.LoadImage(game.Engine, balance.WindowIcon); err == nil {
engine.SetWindowIcon(icon.Image)
} else {
log.Error("Couldn't load WindowIcon (%s): %s", balance.WindowIcon, err)
}
}
if c.Bool("guitest") { if c.Bool("guitest") {
game.Goto(&doodle.GUITestScene{}) game.Goto(&doodle.GUITestScene{})
} else if c.Bool("new") {
game.NewMap()
} else if filename != "" { } else if filename != "" {
if c.Bool("edit") { if c.Bool("edit") {
game.EditFile(filename) game.EditFile(filename)
@ -79,6 +262,24 @@ func main() {
game.PlayLevel(filename) game.PlayLevel(filename)
} }
} }
// Maximizing the window? with `-w maximized`
if c.String("window") == "maximized" {
log.Info("Maximize main window")
engine.Maximize()
}
// Log what Doodle thinks its working directory is, for debugging.
pwd, _ := os.Getwd()
log.Info("Program's working directory is: %s", pwd)
// Initialize the developer shell chatbot easter egg.
chatbot.Setup()
// Log some basic environment details.
w, h := engine.WindowSize()
log.Info("Window size: %dx%d", w, h)
game.Run() game.Run()
return nil return nil
} }
@ -88,6 +289,97 @@ func main() {
err := app.Run(os.Args) err := app.Run(os.Args)
if err != nil { if err != nil {
log.Fatal(err) log.Error(err.Error())
} }
} }
// Set the app's working directory to find the runtime rtp assets.
func setWorkingDirectory(c *cli.Context) error {
// If they used the --chdir CLI option, go there.
if doodlePath := c.String("chdir"); doodlePath != "" {
return os.Chdir(doodlePath)
}
var test = func(paths ...string) bool {
paths = append(paths, filepath.Join("rtp", "Credits.txt"))
_, err := os.Stat(filepath.Join(paths...))
return err == nil
}
// If the rtp/ folder is already here, nothing is needed.
if test() {
return nil
}
// Get the path to the executable and search around from there.
ex, err := os.Executable()
if err != nil {
return fmt.Errorf("couldn't find the path to current executable: %s", err)
}
exPath := filepath.Dir(ex)
log.Debug("Trying to locate rtp/ folder relative to game's executable path: %s", exPath)
// Test a few relative paths around the executable's folder.
paths := []string{
exPath, // same directory, e.g. Linux /opt/sketchymaze root or Windows zipfile
filepath.Join(exPath, ".."), // parent directory, e.g. from the git clone root
filepath.Join(exPath, "..", "Resources"), // e.g. in a macOS .app bundle.
// Some well-known installed paths to check.
"/opt/sketchymaze", // Linux deb/rpm package
"/app/share/sketchymaze", // Linux flatpak package
}
for _, testPath := range paths {
if test(testPath) {
log.Info("Found rtp folder in: %s", testPath)
return os.Chdir(testPath)
}
}
return nil
}
func setResolution(value string) error {
switch value {
case "desktop", "maximized":
return nil
case "mobile":
balance.Width = 375
balance.Height = 812
if !usercfg.Current.Initialized {
usercfg.Current.HorizontalToolbars = true
}
case "landscape":
balance.Width = 812
balance.Height = 375
default:
var re = regexp.MustCompile(`^(\d+?)x(\d+?)$`)
m := re.FindStringSubmatch(value)
if len(m) == 0 {
return errors.New("--window: must be of the form WIDTHxHEIGHT, i.e. " +
"1024x768, or special keywords desktop, mobile, or landscape.")
}
w, _ := strconv.Atoi(m[1])
h, _ := strconv.Atoi(m[2])
balance.Width = w
balance.Height = h
}
return nil
}
func initLogFile(filename string) error {
// Default log file to disk goes to your profile directory.
if filename == "" {
filename = userdir.LogFile
}
fh, err := golog.NewFileTee(filename)
if err != nil {
return err
}
log.Logger.Config.Writer = fh
return nil
}

7
debug-af.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
export DEBUG_CHUNK_COLOR=FFFF0066
export DEBUG_CANVAS_LABEL=1
export DEBUG_CHUNK_COLOR=00FF00AA
export DEBUG_CANVAS_BORDER=0FF
go run cmd/doodle/main.go --experimental --debug

View File

@ -1,12 +0,0 @@
# Button Doodads
```bash
doodad convert -t "Sticky Button" sticky1.png sticky2.png sticky-button.doodad
doodad install-script sticky.js sticky-button.doodad
doodad convert -t "Button" button1.png button2.png button.doodad
doodad install-script button.js button.doodad
doodad convert -t "Button Type B" typeB1.png typeB2.png button-typeB.doodad
doodad install-script button.js button-typeB.doodad
```

View File

@ -1,17 +0,0 @@
function main() {
console.log("%s initialized!", Self.Doodad.Title);
var timer = 0;
Events.OnCollide( function() {
if (timer > 0) {
clearTimeout(timer);
}
Self.ShowLayer(1);
timer = setTimeout(function() {
Self.ShowLayer(0);
timer = 0;
}, 200);
})
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 728 B

View File

@ -1,7 +0,0 @@
function main() {
console.log("%s initialized!", Self.Doodad.Title);
Events.OnCollide( function() {
Self.ShowLayer(1);
})
}

Some files were not shown because too many files have changed in this diff Show More