📜 ⬆️ ⬇️

Using Ångström Style System in real projects

What is the Ångström Style System (ÅSS)? This is the second version of the style library for native iOS applications written by Shurak Babayev (@bealex). Recently there was a new version on Swift, which is called S2, but we have not yet had time to try it, so I will tell you about the actual use of ÅSS on one of our current projects.

Hooray! A game!


I do different game projects. In the process of creating each game, a game design setting is required, one has to take into account a huge amount of nuances. If you are also developing “PvZ-inspired” games, then you will need to think about how to effectively organize the settings. How? Read on.


In such a game it is quite difficult to quickly and accurately work out the balance. Gaming objects are usually a dozen or two, each has a set of basic parameters (attack speed, attack power, defense, movement speed, number of health units, etc.) and maybe some specific parameters (mana amount, luck ratio, etc.), each The object can be placed in any (or not) place of the screen and the general scheme is very complicated.

To understand all these parameters, you must be able to quickly change them. And not only them, but also some test configurations. For example, we check if two attacking objects can fire one defensive (and how fast). We picked up the parameters, launched the application, put two objects here, one there ... for a long time. Need faster. It's nice if you can:
')

This logic makes it possible to quickly test the game balance, adjust various parameters. And if you also assign quantifiable tasks here (adjust the parameters so that the balance of the stone-paper-scissors type is statistically obtained, for example, and change the parameters (generate the config) automatically, then you can either adjust the balance or rebuild it if necessary .

To speed up work (and other parameters of effective labor) it is convenient for us to use ÅSS.

An example of working with ÅSS to customize game parameters


So, what do we need from the system that will download game parameters?


Consider the example of a simple file, then you can scale it as you like. In the file I set the parameters of the game itself, and for several game objects, the file can be called styles_game.json :

{ "debug": { "level": "GMDebugLevelAll", "gameSpeed": 100, } "game": { "objects": [ { "id": "Attacker 1", "speed": 1, "attack": 2, "defence": 0.5, "health": 100 }, { "id": "Defence 1", "speed": 0, "attack": 0, "defence": 2.5, "health": 1000 } ], "parameters": { "linesCount": 5, "lineLength": 30 } } } 

To put this file on the server, you need to create a main style file, which we will call styles_main.json :

 { "@include.game": { "inApp": "styles_main.json", "remote": "https://cdn.server.com/styles_main.json" } } 

Then we configure ÅSS in the application. Details on how to do this are in the library's developer blog (@bealex), here I assume that what is said in that article, in the “Working with Styler” section, has been completed. Let us turn to the parts specific to my application.

Auto update


The article only catch a glimpse of the remarkable feature of ÅSS - the ability to update on the fly. We always make the button “update styles” for our projects either in the menu or directly on the screen (if the update is very, very frequent). You can also bind to any gesture, but since we create games, gestures are often used in the gameplay, and the debug button is much simpler / more convenient. So, auto update. To connect it, you need to write something like this:

 MyGameSettings *style = [[MyGameSettings alloc] initWithStyleReloadedCallback: ^{ [self updateGameSettings]; }]; 

And we attach the code to the button:

 ASStyler *styler = [ASStyler sharedInstance]; [styler reloadStylesFromURL:@"styles_main.json"]; 

As a result, each time the user clicks on the button, the styles are updated and after the update (and downloading the remote file), the updateGameSettings code is called where you need to carefully update the parameters of all objects and restart the game (or continue the current one).

findings


ÅSS is a good solution for working with configurations. I tried several other solutions, but some of them are tied to visual styles (for example, those that are about CSS), others (like DB5 ) require rebuilding the application, which slows down the development.

Also, this kind of system is very helpful in a distributed team, or in any other team where the game designer sits separately from the developer. The developer makes a test build, gives out a game designer and continues to develop, at the same time, the game designer has fun with the settings of the parameters of objects, looking for the perfect balance. If he needs some more parameters, he asks the developer to connect them.

Source: https://habr.com/ru/post/279425/


All Articles