Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
9efe07b3
Commit
9efe07b3
authored
Dec 21, 2006
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cards dependencies, clearing order cache
parent
72d6958f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
7 deletions
+54
-7
src/data/set.cpp
src/data/set.cpp
+18
-1
src/data/set.hpp
src/data/set.hpp
+2
-0
src/script/dependency.hpp
src/script/dependency.hpp
+5
-0
src/script/functions.cpp
src/script/functions.cpp
+21
-1
src/script/script_manager.cpp
src/script/script_manager.cpp
+5
-2
src/script/value.hpp
src/script/value.hpp
+3
-3
No files found.
src/data/set.cpp
View file @
9efe07b3
...
@@ -129,7 +129,21 @@ ScriptValueP make_iterator(const Set& set) {
...
@@ -129,7 +129,21 @@ ScriptValueP make_iterator(const Set& set) {
}
}
void
mark_dependency_member
(
Set
*
value
,
const
String
&
name
,
const
Dependency
&
dep
)
{
void
mark_dependency_member
(
Set
*
value
,
const
String
&
name
,
const
Dependency
&
dep
)
{
// TODO
// is it the card list?
if
(
name
==
_
(
"cards"
))
{
value
->
game
->
dependent_scripts_cards
.
push_back
(
dep
);
return
;
}
// is it the keywords?
if
(
name
==
_
(
"keywords"
))
{
value
->
game
->
dependent_scripts_keywords
.
push_back
(
dep
);
return
;
}
// is it in the set data?
IndexMap
<
FieldP
,
ValueP
>::
const_iterator
it
=
value
->
data
.
find
(
name
);
if
(
it
!=
value
->
data
.
end
())
{
(
*
it
)
->
fieldP
->
dependent_scripts
.
push_back
(
dep
);
}
}
}
void
mark_dependency_member
(
const
SetP
&
value
,
const
String
&
name
,
const
Dependency
&
dep
)
{
void
mark_dependency_member
(
const
SetP
&
value
,
const
String
&
name
,
const
Dependency
&
dep
)
{
mark_dependency_member
(
value
.
get
(),
name
,
dep
);
mark_dependency_member
(
value
.
get
(),
name
,
dep
);
...
@@ -157,6 +171,9 @@ int Set::positionOfCard(const CardP& card, const ScriptValueP& order_by) {
...
@@ -157,6 +171,9 @@ int Set::positionOfCard(const CardP& card, const ScriptValueP& order_by) {
}
}
return
order
->
find
(
card
);
return
order
->
find
(
card
);
}
}
void
Set
::
clearOrderCache
()
{
order_cache
.
clear
();
}
// ----------------------------------------------------------------------------- : Styling
// ----------------------------------------------------------------------------- : Styling
...
...
src/data/set.hpp
View file @
9efe07b3
...
@@ -93,6 +93,8 @@ class Set : public Packaged {
...
@@ -93,6 +93,8 @@ class Set : public Packaged {
/// Find the position of a card in this set, when the card list is sorted using the given cirterium
/// Find the position of a card in this set, when the card list is sorted using the given cirterium
int
positionOfCard
(
const
CardP
&
card
,
const
ScriptValueP
&
order_by
);
int
positionOfCard
(
const
CardP
&
card
,
const
ScriptValueP
&
order_by
);
/// Clear the order_cache used by positionOfCard
void
clearOrderCache
();
protected:
protected:
virtual
String
typeName
()
const
;
virtual
String
typeName
()
const
;
...
...
src/script/dependency.hpp
View file @
9efe07b3
...
@@ -33,6 +33,11 @@ class Dependency {
...
@@ -33,6 +33,11 @@ class Dependency {
DependencyType
type
:
5
;
///< Type of the dependent script
DependencyType
type
:
5
;
///< Type of the dependent script
size_t
index
:
27
;
///< index into an IndexMap
size_t
index
:
27
;
///< index into an IndexMap
void
*
data
;
///< Extra pointer data
void
*
data
;
///< Extra pointer data
/// This dependency, but dependent on all cards instead of just one
inline
Dependency
makeCardIndependend
()
const
{
return
Dependency
(
type
==
DEP_CARD_FIELD
?
DEP_CARDS_FIELD
:
type
,
index
,
data
);
}
};
};
// ----------------------------------------------------------------------------- : EOF
// ----------------------------------------------------------------------------- : EOF
...
...
src/script/functions.cpp
View file @
9efe07b3
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include <script/value.hpp>
#include <script/value.hpp>
#include <script/context.hpp>
#include <script/context.hpp>
#include <script/dependency.hpp>
#include <util/tagged_string.hpp>
#include <util/tagged_string.hpp>
#include <data/set.hpp>
#include <data/set.hpp>
#include <wx/regex.h>
#include <wx/regex.h>
...
@@ -421,18 +422,37 @@ int position_in_vector(const ScriptValueP& of, const ScriptValueP& in, const Scr
...
@@ -421,18 +422,37 @@ int position_in_vector(const ScriptValueP& of, const ScriptValueP& in, const Scr
}
}
// finding positions, also of substrings
// finding positions, also of substrings
SCRIPT_FUNCTION
(
position_of
)
{
SCRIPT_FUNCTION
_DEP
(
position_of
)
{
ScriptValueP
of
=
ctx
.
getVariable
(
_
(
"of"
));
ScriptValueP
of
=
ctx
.
getVariable
(
_
(
"of"
));
ScriptValueP
in
=
ctx
.
getVariable
(
_
(
"in"
));
ScriptValueP
in
=
ctx
.
getVariable
(
_
(
"in"
));
ScriptValueP
order_by
=
ctx
.
getVariableOpt
(
_
(
"order by"
));
ScriptValueP
order_by
=
ctx
.
getVariableOpt
(
_
(
"order by"
));
SCRIPT_RETURN
(
position_in_vector
(
of
,
in
,
order_by
));
SCRIPT_RETURN
(
position_in_vector
(
of
,
in
,
order_by
));
}
}
ScriptValueP
ScriptBuildin_position_of
::
dependencies
(
Context
&
ctx
,
const
Dependency
&
dep
)
const
{
ScriptValueP
of
=
ctx
.
getVariable
(
_
(
"of"
));
ScriptValueP
in
=
ctx
.
getVariable
(
_
(
"in"
));
ScriptValueP
order_by
=
ctx
.
getVariableOpt
(
_
(
"order by"
));
ScriptObject
<
Set
*>*
s
=
dynamic_cast
<
ScriptObject
<
Set
*>*
>
(
in
.
get
());
ScriptObject
<
CardP
>*
c
=
dynamic_cast
<
ScriptObject
<
CardP
>*>
(
of
.
get
());
if
(
s
&&
c
)
{
// dependency on cards
mark_dependency_member
(
s
->
getValue
(),
_
(
"cards"
),
dep
);
if
(
order_by
)
{
// dependency on order_by function
order_by
->
dependencies
(
ctx
,
dep
.
makeCardIndependend
());
}
}
return
dependency_dummy
;
};
// finding sizes
// finding sizes
SCRIPT_FUNCTION
(
number_of_items
)
{
SCRIPT_FUNCTION
(
number_of_items
)
{
SCRIPT_RETURN
(
ctx
.
getVariable
(
_
(
"in"
))
->
itemCount
());
SCRIPT_RETURN
(
ctx
.
getVariable
(
_
(
"in"
))
->
itemCount
());
}
}
// ----------------------------------------------------------------------------- : Initialize functions
// ----------------------------------------------------------------------------- : Initialize functions
void
init_script_functions
(
Context
&
ctx
)
{
void
init_script_functions
(
Context
&
ctx
)
{
...
...
src/script/script_manager.cpp
View file @
9efe07b3
...
@@ -99,6 +99,7 @@ void SetScriptManager::onInit(const StyleSheetP& stylesheet, Context* ctx) {
...
@@ -99,6 +99,7 @@ void SetScriptManager::onInit(const StyleSheetP& stylesheet, Context* ctx) {
initDependencies
(
*
ctx
,
*
set
.
game
);
initDependencies
(
*
ctx
,
*
set
.
game
);
initDependencies
(
*
ctx
,
*
stylesheet
);
initDependencies
(
*
ctx
,
*
stylesheet
);
// apply scripts to everything
// apply scripts to everything
// TODO : don't updateAll here, it will be done repeatedly
updateAll
();
updateAll
();
}
catch
(
Error
e
)
{
}
catch
(
Error
e
)
{
handle_error
(
e
,
false
,
false
);
handle_error
(
e
,
false
,
false
);
...
@@ -195,7 +196,7 @@ void SetScriptManager::updateAllDependend(const vector<Dependency>& dependent_sc
...
@@ -195,7 +196,7 @@ void SetScriptManager::updateAllDependend(const vector<Dependency>& dependent_sc
}
}
void
SetScriptManager
::
updateRecursive
(
deque
<
ToUpdate
>&
to_update
,
Age
starting_age
)
{
void
SetScriptManager
::
updateRecursive
(
deque
<
ToUpdate
>&
to_update
,
Age
starting_age
)
{
// set->order_cache.clear
(); // clear caches before evaluating a round of scripts
set
.
clearOrderCache
();
// clear caches before evaluating a round of scripts
while
(
!
to_update
.
empty
())
{
while
(
!
to_update
.
empty
())
{
updateToUpdate
(
to_update
.
front
(),
to_update
,
starting_age
);
updateToUpdate
(
to_update
.
front
(),
to_update
,
starting_age
);
to_update
.
pop_front
();
to_update
.
pop_front
();
...
@@ -226,8 +227,10 @@ void SetScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Depen
...
@@ -226,8 +227,10 @@ void SetScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Depen
if
(
card
)
{
if
(
card
)
{
ValueP
value
=
card
->
data
.
at
(
d
.
index
);
ValueP
value
=
card
->
data
.
at
(
d
.
index
);
to_update
.
push_back
(
ToUpdate
(
value
.
get
(),
card
));
to_update
.
push_back
(
ToUpdate
(
value
.
get
(),
card
));
}
break
;
break
;
}
else
{
// There is no card, so the update should affect all cards (fall through).
}
}
case
DEP_CARDS_FIELD
:
{
}
case
DEP_CARDS_FIELD
:
{
// something invalidates a card value for all cards, so all cards need updating
// something invalidates a card value for all cards, so all cards need updating
FOR_EACH
(
card
,
set
.
cards
)
{
FOR_EACH
(
card
,
set
.
cards
)
{
...
...
src/script/value.hpp
View file @
9efe07b3
...
@@ -314,16 +314,16 @@ inline ScriptValueP toScript(const shared_ptr<T>& v) { return new_intrusive1<Scr
...
@@ -314,16 +314,16 @@ inline ScriptValueP toScript(const shared_ptr<T>& v) { return new_intrusive1<Scr
* context.setVariable("my_function", script_my_function);
* context.setVariable("my_function", script_my_function);
* @endcode
* @endcode
*/
*/
#define SCRIPT_FUNCTION(name) SCRIPT_FUNCTION_AUX(name,
virtual
)
#define SCRIPT_FUNCTION(name) SCRIPT_FUNCTION_AUX(name,
;
)
/// Macro to declare a new script function with custom dependency handling
/// Macro to declare a new script function with custom dependency handling
#define SCRIPT_FUNCTION_DEP(name) SCRIPT_FUNCTION_AUX(name,
virtual) //TODO
#define SCRIPT_FUNCTION_DEP(name) SCRIPT_FUNCTION_AUX(name,
virtual ScriptValueP dependencies(Context&, const Dependency&) const;)
// helper for SCRIPT_FUNCTION and SCRIPT_FUNCTION_DEP
// helper for SCRIPT_FUNCTION and SCRIPT_FUNCTION_DEP
#define SCRIPT_FUNCTION_AUX(name,dep) \
#define SCRIPT_FUNCTION_AUX(name,dep) \
class
ScriptBuildin_
##
name
:
public
ScriptValue
{
\
class
ScriptBuildin_
##
name
:
public
ScriptValue
{
\
dep
\
dep
\
/* virtual */
ScriptType
type
()
const
\
virtual
ScriptType
type
()
const
\
{
return
SCRIPT_FUNCTION
;
}
\
{
return
SCRIPT_FUNCTION
;
}
\
virtual
String
typeName
()
const
\
virtual
String
typeName
()
const
\
{
return
_
(
"build in function '"
)
_
(
#
name
)
_
(
"'"
);
}
\
{
return
_
(
"build in function '"
)
_
(
#
name
)
_
(
"'"
);
}
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment