mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
add new_uid script function
This commit is contained in:
@@ -109,6 +109,7 @@ These functions are built into the program, other [[type:function]]s can be defi
|
|||||||
|
|
||||||
! Cards <<<
|
! Cards <<<
|
||||||
| [[fun:new_card]] Construct a new [[type:card]] object.
|
| [[fun:new_card]] Construct a new [[type:card]] object.
|
||||||
|
| [[fun:new_uid]] Construct a new uid.
|
||||||
| [[fun:add_card_to_set]] Add a [[type:card]] to a [[type:set]].
|
| [[fun:add_card_to_set]] Add a [[type:card]] to a [[type:set]].
|
||||||
| [[fun:get_card_styling]] Get the styling data of a [[type:card]].
|
| [[fun:get_card_styling]] Get the styling data of a [[type:card]].
|
||||||
| [[fun:get_card_stylesheet]] Get the stylesheet of a [[type:card]].
|
| [[fun:get_card_stylesheet]] Get the stylesheet of a [[type:card]].
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
Function: new_uid
|
||||||
|
|
||||||
|
--Usage--
|
||||||
|
> new_uid()
|
||||||
|
|
||||||
|
Returns a new card uid, a string of 32 random digits, which is guaranteed to not exist in the set.
|
||||||
|
|
||||||
|
--Parameters--
|
||||||
|
! Parameter Type Description
|
||||||
|
| @set@ [[type:set]] The set in which to look for uid conflicts. This can be omitted since 'set' is a predefined variable.
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#include <data/game.hpp>
|
#include <data/game.hpp>
|
||||||
#include <data/stylesheet.hpp>
|
#include <data/stylesheet.hpp>
|
||||||
#include <data/card.hpp>
|
#include <data/card.hpp>
|
||||||
|
#include <util/uid.hpp>
|
||||||
#include <util/error.hpp>
|
#include <util/error.hpp>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : new_card
|
// ----------------------------------------------------------------------------- : new_card
|
||||||
@@ -168,9 +169,20 @@ SCRIPT_FUNCTION(add_card_to_set) {
|
|||||||
SCRIPT_RETURN(false);
|
SCRIPT_RETURN(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SCRIPT_FUNCTION(new_uid) {
|
||||||
|
SCRIPT_PARAM_C(Set*, set);
|
||||||
|
String uid = generate_uid();
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
if (set->card_uids.find(uid) == set->card_uids.end()) break;
|
||||||
|
uid = generate_uid();
|
||||||
|
}
|
||||||
|
SCRIPT_RETURN(uid);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Init
|
// ----------------------------------------------------------------------------- : Init
|
||||||
|
|
||||||
void init_script_construction_functions(Context& ctx) {
|
void init_script_construction_functions(Context& ctx) {
|
||||||
ctx.setVariable(_("new_card"), script_new_card);
|
ctx.setVariable(_("new_card"), script_new_card);
|
||||||
|
ctx.setVariable(_("new_uid"), script_new_uid);
|
||||||
ctx.setVariable(_("add_card_to_set"), script_add_card_to_set);
|
ctx.setVariable(_("add_card_to_set"), script_add_card_to_set);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user