Author Topic: Transform all of 1 kind of block at once  (Read 840 times)

Tirello

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    1
    • View Profile
on: February 12, 2019, 06:10:24 PM
Is there any way to transform all of one kind of block to another?

Example transforming all iron armor to titanium armor at once.




SneakyTacts

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    105
    • View Profile
on: February 15, 2019, 06:45:04 PM
I have not tried this, but maybe it's possible. Try hiding all blocks that are not one shape of armor,  then select them all (by using a selection tool) and try to transform them into anything by using the 'transform' tool or the 'upgrade ship' tool. Those might not be the correct names for the tools but I hope I got the idea across.



aiko

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    1
    • View Profile
on: February 16, 2019, 03:36:08 AM
I have not tried this, but maybe it's possible. Try hiding all blocks that are not one shape of armor,  then select them all (by using a selection tool) and try to transform them into anything by using the 'transform' tool or the 'upgrade ship' tool. Those might not be the correct names for the tools but I hope I got the idea across.

Afaik, it does not work that way, at least not the last time I tried. But it would be a nice idea to implement it just as you said, it would be userfriendly and probably easy to implement.

However, there is currently a possible solution which is quite convenient imho (I mean, as far as it can get in this case ;)), but still only worth it, if you believe manual editing takes you more time than reading and applying my following textblob :D

  • You need a text editor which supports posix regular expressions for find&replace operations.
    I usually use Sublime Text for such things, but any supporting should do.

  • Navigate to %APPDATA%/Roaming/Avorion/ships (or Linux ~/.avorion/ships) and open the xml ship design you wish to edit in your editor of choice - even better, make a backup copy of it beforehands, in case something goes wrong or save under a different filename.

  • As you see in the file, the format is neat and structured, every item containing a block is one element you possibly want to replace if it meets your specfic conditions. In your example those are all blocks which are made of iron (material="0") and of type armor (index="1|8|104|105|106") and they all should change material to 1 for titanium. The simple apprach would be now to press Strg+H and replace 5 times 'material="0" index="type"' with 'material="1" index="type"', once for each block, but this would neglect the color, meaning, your ship would be made out of the new materials but still look like before which might not always be desired. Also, nobody likes repeating dull tasks  ;)

    That is where regular expressions are saving the day:
    Start Find&Replace (Ctrl+H), ensure Regex-Support is enabled (in Sublime a small button left to the find operation field) and copy&paste the following 2 lines:
Find:
Code: [Select]
index="(1|8|104|105|106)" material="0"\s+look="(\d)"\s+up="(\d)"\s+color="[0-9a-fA-F]+"Replace:
Code: [Select]
index="\1" material="1" look="\2" up="\3" color="bfbfbfbf"
That's it.

Don't be confused if the design to apply does not directly show the new color in the preview, because the preview was seperatly saved as a png file and only updates when saving the ship, not by just changing the xml file like you just did.

These were the instructions to replace all iron armor on a ship template with titanium armor, but more generally speaking:
- material ranges from 0 to 6 from iron to avorion
- index as the block type is easilly to obtain if you make a new 'dummy ship' out of the blocks which interest you, save it and look into the xml file
- color="[0-9a-fA-F]+" means any color - you can also replace blocks only from a specific color; here the current basic material ones for reference:
  • iron ffbfaea3
  • titanium bfbfbfbf
  • naonite ffa3bfa3
  • trinium ffa3afbf
  • xanion ffbfbfa3
  • ogonite ffbfada3
  • avorion ffbc9f9f
This is of course extensible, but I will not go into regexes any further unless necassary, as this is not really the scope of my post anymore (and waaay too much for me).
Hope this may save a few player's time editing rather complex ship designs, for simpler cases or if you are totally not into editing loose files, this was probably overkill...  ;D
« Last Edit: February 16, 2019, 06:02:23 AM by aiko »



MetalLaires

  • Jr. Member
  • **
  • Status:
    Offline
    Posts:
    85
    • View Profile
on: February 22, 2019, 11:21:05 PM
I would copy the entire ship to your 'saved blocks' section and after that place it on your new ship. You only have to check the material button in the top right corner of the materials-screen. Choose the material that you like and fin!



SneakyTacts

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    105
    • View Profile
on: February 25, 2019, 10:01:19 PM
I would copy the entire ship to your 'saved blocks' section and after that place it on your new ship. You only have to check the material button in the top right corner of the materials-screen. Choose the material that you like and fin!
An easier way to do something like that would be to use the 'modify entire ship' tool in the lower left corner. What either of our methods lack, though, is the ability to adjust certain things and not everything.