[OK] CSS Dynamique sous PHP.

Game development with Board Game Arena Studio
Post Reply
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

[OK] CSS Dynamique sous PHP.

Post by Rudolf »

Bonsoir,
petite question concernant l'ajout dynamique de classes css.
je voudrais automatiser la création d'une série de classes dont les noms sont proches et pratiques pour y mettre des boucles.
j'ai donc essayé d'insérer un code d'essai dans le view.php. au niveau du build_page()... avant la création de mes blocks (qui ont besoin de ces classes).
Lorsque j'ajoute ce code, tout ce que cela fait, c'est d'agrandir les player_board_div et le fond (premier effet indésirable)... et la classe n'est pas créée...
ce n'est donc surement pas la bonne méthode...
Auriez vous une méthode pour créer des classes via php dans le view (ou ailleur eventuellement)?
merci d'avance.

Code: Select all

function build_page()
{
        function buildClasses()
	{
			echo '<style type="text/css">';
			echo '.pbreducecard	{ width:99px; height:33px;background-size:840px; background-position: 0px 	-315px;  }';
			echo '</style>';
	}
 buildClasses();
[...]
}
Last edited by Rudolf on 12 August 2015, 13:01, edited 1 time in total.
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: CSS Dynamique sous PHP.

Post by Rudolf »

I've tried also this way:
In myproject.tpl

Code: Select all

<script type="text/javascript">
var jstpl_class='<style type="text/css">${classdef}</style>';
</script>
in myproject.js

Code: Select all

this.format_block( 'jstpl_class', { classdef: '.show { background-color:red;}'} );
somewhere else in myproject.js

Code: Select all

dojo.addClass( 'Mydiv', 'show' );
This compiled but does not run.(no blue square shown).
Is there a way to do something like that? To create dynamic class?
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: CSS Dynamique sous PHP.

Post by pikiou »

Admins always found a good way around and think it helps to keep the code simple and readable.
So it's not possible, and if you do there is a good chance your game won't work on some browsers, because style elements should be in the header and only there.

I seem I remember I used a workaround, once, but I can't find it again so I must have removed it because of some bug.

Can I help you find an alternative? What do you want dynamic CSS for?
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: CSS Dynamique sous PHP.

Post by Rudolf »

Hi again Pikiou,
I did a workaround, but I was wondering if I could simplify the css.

all my cards are class.... for example card_SEN_2 is a background position selector to select Sentinelle Card level 2.
So I've coded all the backgrounds and all the types as class... it's for me easy to use...
But the CSS is now long... and I was expecting a way to generate the classes automaticaly...
well nevermind. ;) ... now it's done.
User avatar
Coin-coin le Canapin
Posts: 163
Joined: 31 January 2013, 19:00

Re: CSS Dynamique sous PHP.

Post by Coin-coin le Canapin »

If I understand your problem maybe you can locally create a SASS file, you can use loops to create class names with it.
Then you upload the compiled (CSS) file on the BGA server. You can compile SASS files with Prepros for example.
http://sass-lang.com/
http://stackoverflow.com/questions/2123 ... vice-versa
http://stackoverflow.com/questions/1908 ... separating
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: CSS Dynamique sous PHP.

Post by pikiou »

Well, the best way to handle cards is to use the Stock component: http://en.studio.boardgamearena.com/#!doc/Stock
You give it your image sprite file, the size of the cards, the number of cards per row, and it does all the sprite cutting for you. If you need to add anything more to each card, it's even possible!
It also handles selecting (multiple) cards, moving them from a hand of cards to another or even arranging them in a specific order.
It's a very handy tool that can be used for anything you visualy handle like cards.
Only $9.99 if you order now.

Edit: I meant Stock component, not Deck component.
Last edited by pikiou on 09 August 2015, 20:05, edited 1 time in total.
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

Re: CSS Dynamique sous PHP.

Post by Rudolf »

:)
Thanks for SASS info.
:)
I've tried the Deck, but I prefer to manage with my own class this time... to shuffle only a part of the deck, etc...
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: CSS Dynamique sous PHP.

Post by pikiou »

Er sorry I mentioned the Deck component but I meant the Stock one. I don't use the Deck component either.
The Stock handles card visuals on the client side : http://en.studio.boardgamearena.com/#!doc/Stock
Post Reply

Return to “Developers”