pickardj79 / bga-galaxytrucker

Other
1 stars 0 forks source link

Implement one source of constants for frontend and backend #32

Open kuwizard opened 3 years ago

kuwizard commented 3 years ago

Currently if we need a backend constant (type) to be understandable by code and by dev we define a frontend constant which is a copy of a backend one. We need to find a way to use a single source for constants and they are to be defined everywhere automatically

kuwizard commented 3 years ago

What I mean - see modules/GTFE_Goods.js:48:

    const CARD_PLANETS = 8;
    if (cardType['type'] === CARD_PLANETS) {...}

And what might be a solution: backend:

$myConstants = [
  'SOME' => 12,
  'OPTION_MYOPTION' => 13,
];

foreach($myConstants as $key => $value){
  define($key, $value);
}

On backend part we also add all constants to gamedatas.

frontend:

for(var key in gamedatas.constants){
  window[key] = gamedatas.constants[key];
}

Kudos to Tisaac for the suggestion (however nobody proved it working :D)