Suggestion: blueprint tag with customizable text

Discussions related to the forums itself. Call for moderators. Trash Posts area.
Post Reply
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Suggestion: blueprint tag with customizable text

Post by boskid »




With "bp" tag there is always "Copy blueprint string". My suggestion is to allow customization of this text. There are 2 ways it could be done:
1/ By using "bp=TEXT" tag syntax
2/ Or by parsing blueprint and extracting its name (in case of blueprint book, also change icon from blueprint into blueprint book)

Either way it would be awesome as with this it would be easier to find blueprints in forum posts without need to read text above and below

edit:
bp-tag-how-it-could-look-like.png
bp-tag-how-it-could-look-like.png (42.54 KiB) Viewed 1830 times

slippycheeze
Filter Inserter
Filter Inserter
Posts: 587
Joined: Sun Jun 09, 2019 10:40 pm
Contact:

Re: Suggestion: blueprint tag with customizable text

Post by slippycheeze »

Blueprint tag that extracts the title from the book and/or blueprint. I suspect Wube have the code for that, somehow, even if they would have to port it to PHP.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Suggestion: blueprint tag with customizable text

Post by boskid »

Nothing to port to PHP :)

Code: Select all

<?php
    function bp_label($bp) {
        $default_bp = ['icon' => 'https://wiki.factorio.com/images/Blueprint.png', 'label' => 'Copy blueprint string'];
        
        /* BP string version check */
        if(strlen($bp) < 1) {
            return $default_bp;
        }
        if($bp[0] != '0') {
            return $default_bp;
        }
        $bp = substr($bp, 1);
        
        /* base64 decode */
        $bp = base64_decode($bp, true);
        if(!$bp) {
            return $default_bp;
        }
        
        /* zlib inflate */
        $bp = zlib_decode($bp);
        if(!$bp) {
            return $default_bp;
        }
        
        /* JSON decode */
        $bp = json_decode($bp, true);
        if(!$bp) {
            return $default_bp;
        }

        /* Extract label */
        if(isset($bp['blueprint']) && isset($bp['blueprint']['label'])) {
            return ['icon' => 'https://wiki.factorio.com/images/Blueprint.png', 'label' => $bp['blueprint']['label']];

        } else if(isset($bp['blueprint_book']) && isset($bp['blueprint_book']['label'])) {
            return ['icon' => 'https://wiki.factorio.com/images/Blueprint_book.png', 'label' => $bp['blueprint_book']['label']];

        } else if(isset($bp['deconstruction_planner'])) {
            return ['icon' => 'https://wiki.factorio.com/images/Deconstruction_planner.png', 'label' => 'Deconstruction planner'];

        } else if(isset($bp['upgrade_planner'])) {
            return ['icon' => 'https://wiki.factorio.com/images/Upgrade_planner.png', 'label' => 'Upgrade planner'];

        } else {
            return $default_bp;
        }
    }

    $bp = '0eNqV0s0KwjAMAOBXkZwr7E+nPbuDMH9APYlIp0EKbTfWKo7Rd7ebIIJT5qmkJF8TmhoyccWi5MoArYGfcqWB7mvQ/KKYaO5MVSBQ4AYlEFBMNpGWTIihYLIAS4CrM96B+vZAAJXhhuNTaYPqqK4yw9IldNUTKHLtSnLVvOaYoUur3BFYSz6IoBfxSwj/acLvEqJ+QtAKXpcw+mOKzhbGvQDvOxD3Al4juI9tF4C+7QsBwTJ0OwKbVbrbzlfLQTCYL9ZpskiW22TmEm5Y6laLQ8+fhPHYn0bWPgDv/M0M';
    print_r(bp_label($bp));
    $bp = '0eNqVkk1rwzAMhv9K0NmBfHTNltvGfCg0zaAdO4wRnM4MM3+E2C0LJf99jkuXQt2RnoykV48k/B6g5jvatEyaqlbqG/LDmNGQv5+FQ41tlTymNfuShA850zUUcmCGCkAgiRgiLQjnISeigR4Bk5/0B/K4/0BApWGG0SPFBV0ld6KmrRX4+hE0StsWJYdpFhNaWWefpO/RBSKZhPiPkN6yROwjzKYREkeIfIS7G67wrjCfBIiuA7JJgL8T7Mc6A+RnfkHASU2tR2BdLl83i3IVJMGieFniAq82+NkK9rTVjpalUXyfZvP4YTb6JfJhQ+fTkf10KgRDIXh8w+uywFZAtobtaXViXRnW/wKl+Pxw';
    print_r(bp_label($bp));
?>
Result:

Code: Select all

Array
(
    [icon] => https://wiki.factorio.com/images/Blueprint.png
    [label] => SOLUTION 2 IMPLEMENTED
)
Array
(
    [icon] => https://wiki.factorio.com/images/Blueprint_book.png
    [label] => Blueprint book AWESOME
)

User avatar
Sanqui
Factorio Staff
Factorio Staff
Posts: 266
Joined: Mon May 07, 2018 7:22 pm
Contact:

Re: Suggestion: blueprint tag with customizable text

Post by Sanqui »

I had a quick go at the first solution and I have to conclude that it's not possible because of phpBB's idiotic bbcode handling. (Optional parameters require xslt conditions to handle them which for some reason only accept block elements in them, not button or script. I ran into this problem when migrating old spoiler tags. I had to use divs and style them to be inline. *facepalm*) There's no PHP involved. (I try to avoid making direct modifications to phpBB source.)

The rest of the bp button handling is done in JavaScript and I think I'm not sure if I want to parse blueprints client-side, since it could be on the heavier side - but I could be convinced otherwise.
ovo

Post Reply

Return to “This Forum”