Kartones Blog

Be the change you want to see in this world

Web Speech API

I recently learned that there's a pretty decent Web Speech API, and I have the perfect (although outdated) pet project for it, my choose your adventure system: Lots of text that, with minimal cleaning, make for a nice reading.

There is a very practical online demo that will also give you a feeling of how good or bad the speech synthesizer will sound. And trust me, you should test it, as at least under Ubuntu Linux, Firefox sounds quite terrible, meanwhile Chrome is decent enough that I decided to target that browser for speech.

Most of the API consists on two objects, a single SpeechSynthesis instance to handle the main configuration, and then one SpeechSynthesisUtterance instance per sentence you wish to get read by the API.

I won't enter in the details of how to use it, because I merely followed the nice explanations and checked the source code of the demo (which are concise and good), but I will warn about one issue that I'm having with Chrome: If the sentence is too long, it gets cut, and the API seems to hang, not playing any further sound until closing and re-opening again the browser application!

In order to workaround the length limitation, I am applying the following simple split:

fullText.split(/[.,\:;!\?]| - /).forEach((textFragment) => {
    const text = textFragment.trim();
    if (text.length > 0) {
      const utterance = new SpeechSynthesisUtterance(text);
      utterance.voice = desiredVoice;
      utterance.pitch = pitchValue;
      utterance.rate = rateValue;
      synth.speak(utterance);
    }
  });

You can perfectly enqueue any number of "sentences" (utterances), just make sure that each is not too big.

I might improve the logic a bit in the future, mostly if I still find too big sentences I will try to discern the aprox. max length and split to the previous full word. Also note that when reading numbers (e.g. 5.6) it will split them. But overall, it is a nice first step, and really simple to use.


The Planet Crafter savegame editing

Note: This post refers to version 0.4 of the game.

I sometimes purchase early access videogames (not yet finished and sometimes even in alpha state) to support game developers. I don't do it often, though, because being an early adopter usually means coping with a lot of bugs and sometimes having to reset your game progress.

I am enjoying the slow, calm, and non-violent pace of The Planet Crafter, but with a recent update I faced a hard choice: start a new game to experience the new content, or keep with the old game and focus on finishing all the things I can... still eventually having to begin anew.

I decided to do something in the middle: Create a new savegame, but see how to alter the file and "cheat" by transferring as much as possible.

First of all, make a backup of the Survival-X.json file located at C:\Users\<your-username>\AppData\LocalLow\MijuGames\Planet Crafter folder (or a different drive if not installed in C:).

If you open that file, you will notice that is some kind of ndjson file, but using \n@\n as the line separator.

Useful tweaks

Terraform levels

You can recover your old terraforming levels by editing the first group in the file:

{"unitOxygenLevel":156052032.0,"unitHeatLevel":52146160.0,"unitPressureLevel":7044543.5,"unitBiomassLevel":5064053.0}

Unlocked things

Another of the first blocks contains a property called "unlockedGroups", if you also set that to your old values, when you reach the corresponding terraforming levels you will have again the extra unlocks (I think they are blueprint-based). Combined with the previous tweak it's a nice progress recovery. I for example had the following value:

"unlockedGroups":"MultiToolMineSpeed1,BootsSpeed1,HudCompass,MultiToolMineSpeed2,BootsSpeed2,podAngle,MultiToolMineSpeed3,RecyclingMachine,InsideLamp1,ScreenMap1,RocketMap1,Destructor1,Jetpack2,RocketMap2,MultiToolMineSpeed4,BootsSpeed3,DisplayCase,Pod4x,Jetpack3,MultiToolLight2,RocketMap3,RocketInformations1"

How items and inventory work

For context, this is how an item description line looks like:

{"id":204986269,"gId":"Backpack5","liId":0,"liGrps":"","pos":"0,0,0","rot":"0,0,0,0","wear":0,"pnls":"","color":"","text":"","grwth":0}|

And this is how a group looks:

{"id":1,"woIds":"209872472,202646469,202558410,202173013,204755405,202003892,204986269,206167325,202455419,203517384,205709091","size":12}|

From my research on the files, the basic rules are:

  • Biomes have their items inside, but until you pick, harvest, or deconstruct them, they "don't exist" as individual items in the save file
  • An item seems to be either placed in the world (when it has a non-zero "pos" attribute value), or inside a container ("liId" property is non-zero)
  • A container can be a storage item, your inventory, the items you're wearing
  • All normal items, including storage items, have an entry as an item
  • Storage items also have an entry as an item
  • Item ids seem to be unique, but I haven't tried crafting new ones or reusing the same id
  • A group represents a container item or a special container (equipment in use and inventory)
  • A group has an id attribute, which contained items will have set as their liId attribute
  • A group contains a woIds attribute that contains a comma-separated list of item ids
  • Inventory is a special group with "id":1
  • Equipment in use is a special group with "id":2
  • All items and groups except the last one have at the end of the line a | character

I played safe and didn't altered group "size" attribute, and just in case didn't messed with the equipment in use group. Instead I placed the desired items in the inventory, booted the game and equipped them in-game.

As I haven't added new items, what I do when I want to convert an item into another is to go pick some generic materials, save and exit, and edit, replacing them by my desired item. This in practice is just changing the "gId" attribute of the item.

This is a partial list of item gIds. (there's a bigger list at NexusMods) Note that they seem to be case sensitive, and sometimes contain typos or have case inconsistencies 😅:

  • Alloy
  • Aluminium
  • astrofood
  • Backpack1
  • Backpack2
  • Backpack3
  • Backpack4
  • Backpack5
  • Bacteria1
  • Bioplastic1
  • Cobalt
  • EquipmentIncrease1
  • EquipmentIncrease2
  • FabricBlue
  • Fertilizer1
  • Fertilizer2
  • FusionEnergyCell
  • HudCompass
  • ice
  • Iridium
  • Iron
  • Jetpack1
  • Jetpack2
  • Jetpack3
  • Magnesium
  • Mutagen1
  • MultiBuild
  • MultiDeconstruct
  • MultiToolLight
  • MultiToolLight2
  • MultiToolMineSpeed1
  • MultiToolMineSpeed2
  • MultiToolMineSpeed3
  • MultiToolMineSpeed4
  • Osmium
  • OxygenCapsule1
  • OxygenTank1
  • OxygenTank2
  • OxygenTank3
  • OxygenTank4
  • PulsarShard
  • PulsarQuartz
  • RedPowder1
  • Rod-alloy
  • Rod-iridium
  • Rod-uranium
  • Seed0
  • Seed1
  • Seed2
  • Seed3
  • Seed4
  • Seed5
  • Seed6
  • SeedGold
  • Silicon
  • Sulfur
  • Titanium
  • TreeRoot
  • Tree0Seed
  • Tree1Seed
  • Tree2Seed
  • Tree3Seed
  • Tree4Seed
  • Tree5Seed
  • Tree6Seed
  • Tree7Seed
  • Tree8Seed
  • Uranim
  • Vegetable0Seed
  • Vegetable1Seed
  • Vegetable2Seed
  • Vegetable3Seed
  • WaterBottle1
  • Zeolite

Summary

Being able to recover the old terraforming parameters and unlocks, your old equipment, and optionally altering items to ease things like having your nuclear power plants and labs again, makes it kind of similar to a "new game+" mode: You maintain your progress for all practical purposes, but you will still need to rebuild your base, and gather and grow plants and flora again.

Lately I'm having fun tweaking and modifying games when either I get a bit tired of them, I finish them but want to keep playing, or simply when faced with issues like progress resets, so expect similar posts on the topic in the near future.


Book Review: Core Bazel: Fast Builds For Busy People

Review

Core Bazel: Fast Builds For Busy People book cover

Title: Core Bazel: Fast Builds For Busy People

Author(s): Bogdan Mustiata

I wanted to learn more about Bazel, and I saw there are two books about it. Core Bazel looked like the most generic one, and while small (around 100 pages of content) I picked it up and read it.

Sadly, the results are a bit disappointing. I can cope with the book being two major versions behind (and as of May 2022 Bazel v6 is also nearing release), I can understand leaving certain important concepts (like package visibilities) out, but what I feel is done poorly on this title is the structure of its contents.

Usually, when you want to explain A->B->C you go through a process, explaining A, then B, then C, and you might mention the whole "flow" or parts, like A->B or B->C, and finally you explain what A->B->C does once you know the individual pieces and concepts. What you don't usually do is go explain the final results in extreme detail saying "we'll explain later what each piece does", because then you as a reader won't understand half of it, and once those details are explained will need to go back and re-read what was this all about. Another example: when you show the contents of a file, you usually put the file name before the contents block; Now imagine you're talking about a build system which fundamentally relies on input and output files and folders, and that can easily become complex to understand when learning (after all, we're talking about graphs and file trees). Instead of providing nice diagrams and file names before its contents, you get huge paragraphs of text mentioning inside "the data package", other times code dumps which are not clear from which BUILD file or WORKSPACE they come from... To summarize, I had to took notes and draw myself the examples folder and file structures to be able to follow up.

I wanted to read this book to learn the basics this tool, and apart from some core concepts, I felt like I went into a "medium difficulty level" simply because of the writing. The official website has simpler and better explanations, and even browsing some hello world repository is easier as you won't get lost in the file structure.

I recommend instead going to bazel.build/docs.


Courses Review: egghead.io

While reading books, code and quality articles is, in my opinion, the best way to learn, sometimes I'd rather have some audiovisual content to not spend the whole day reading, to provide more variety. I now have a subscription to egghead.io to hone up my web skills, so after two days of doing a few courses I wanted to write a small review with my initial thoughts.

The courses are short, ranging from ~20 minutes to 1.5 hours, and you can also directly do individual lessons, so the platform feels perfect for blocks of focused training. I won't do individual reviews of each course as else I'd flood the blog with posts, instead doing only this post and then keeping a full list at my reviews page.

Most items almost always go direct to the topic, without any setup instructions, which I like as otherwise you tend to see a dozen times the same "instal X, then Y, then Z" steps. But there are a few (and individual lessons) which do include setup guides, so fear not if you want them.

As for the things that could be better, there are mainly two areas:

In many cases the video is edited to go through the code so quickly that often is hard or impossible to fully follow what the speaker is saying at the same time. It is not always the case, but a general weird decision, I'd expect a slower pacing (and for those impatient the speed modifier is there).

Some courses are a bit outdated: One about testing uses Jest v15.0 (at the time of this writing there's 27.5 and 28.0 is on its way), another about Typescript is based on TS 2.7 and mentions to "the new 3.0 release" (currently at v4.6)... Not a huge deal as much of the content is still valid, though.

To wrap up, this is the list of courses I've done:

Notes:

[1] 90% of the content is non-Typescript specific

[2] 2/3 of the contents consists of an interview with the course author about his test framework, which uses Jest but it is not Jest


My Favourite command line tools

I am far from a power user regarding the terminal. In fact, until very recently I even was a bit reluctant to spend too much time fine-tuning it, to avoid additional steps when I upgrade the operating system (often via format & clean install) or setup a new machine (like at work). But I also appreciate the value of doing certain actions quicker and easier, so now I'm leaning towards a "try and integrate if adds value" approach.

The list might be incomplete, as I am also gathering a list of everything I've got either installed or used not long ago, but the plan is to keep it updated from now on.

My Command-Line Tools list

As always, additional suggestions are welcome!


Previous entries