Posted on 2022-08-04,
Updated 2022-08-06;
Tags:
javascript,
programming,
rust,
webassembly,
webdev
If you're just getting into compiling your Rust code into WebAssembly and want to load it in a web browser, you might be taken aback by the multitude of ways of doing so.
This seems to be due to the differing pace of web browsers implementing web platform features over the years.
A lot of entry-level guides to using Rust and WebAssembly make use of a JavaScript bundler for convenience, but this obscures the relationship between Rust, WebAssembly, JavaScript and HTML, so instead we're going to try doing this all by hand.
Specifically, we're going to compile some Rust code into WebAssembly and do a run-down of the ways to load it directly in a web page using just JavaScript.
If you want to follow along at home, make sure you have Rust installed and the wasm32-unknown-unknown
target:
rustup target add wasm32-unknown-unknown
We're going to look at these loading methods through the perspective of compatibility with three desktop web browsers: Chrome, Firefox and Safari.
I'll be consulting the extremely-helpful Can I use website for this info.
Ready?
Okay, let's go!
(Read more)
Posted on 2022-08-02;
Tags:
game-design,
gamedev
If you're designing a game with numeric hit points, attack and defense values, you'll eventually have to decide on a damage formula that determines the relationship between them.
The simplest approach possible is to calculate damage as just the difference between attack and defense; that is:
damage = attack - defense;
It's as simple as can be, but it has problems.
The above formula only produces satisfying damage values if attack is higher than defense.
Worse, damage will be zero if attack and defense are equal!
How can we fix this?
(Read more)
Posted on 2022-07-29;
Tags:
static-site-generation,
vim,
webdev,
zola
If you use Zola and use Vim to edit Markdown files in your content
directory, you may notice that the TOML front matter meta-data at the top of the file isn't syntax highlighted.
If you already have TOML syntax highlighting set up for Vim, you can fix that with the following configuration:
unlet b:current_syntax
syntax include @Toml syntax/toml.vim
syntax region tomlFrontMatter start=/\%^+++$/ end=/^+++$/ contains=@Toml
Put this in ~/.vim/after/syntax/markdown.vim
and the TOML front matter in your Markdown files should now be syntax highlighted.
The unlet
line is needed for the file inclusion on the next line to work properly.
The syntax include
line creates a cluster named @Toml
that contains every syntax rule in all paths ending with syntax/toml.vim
that Vim can find in its runtime path list.
The syntax region
line denotes a Vim syntax region that we've chosen to name tomlFrontMatter
.
The region starts if the very first line of the file matches +++
, and continues until a +++
line is found.
The whole region is marked as containing the @Toml
cluster from the previous line.
As a bonus, you can accomplish the same thing for YAML front matter in Jekyll with a similar configuration:
unlet b:current_syntax
syntax include @Yaml syntax/yaml.vim
syntax region yamlFrontMatter start=/\%^---$/ end=/^---$/ contains=@Yaml
Both of these configurations can co-exist in the same file too, applying either TOML or YAML syntax highlighting depending on whether +++
or ---
is present at the top of the file.