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
de72b872
Commit
de72b872
authored
Oct 31, 2006
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
naming style (variable_to_string); nicer error messages for problems during dependency checking
parent
87f61e27
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
37 additions
and
21 deletions
+37
-21
src/data/field/choice.cpp
src/data/field/choice.cpp
+1
-0
src/data/stylesheet.cpp
src/data/stylesheet.cpp
+5
-5
src/main.cpp
src/main.cpp
+1
-0
src/script/context.cpp
src/script/context.cpp
+4
-4
src/script/context.hpp
src/script/context.hpp
+1
-1
src/script/dependency.cpp
src/script/dependency.cpp
+15
-1
src/script/parser.cpp
src/script/parser.cpp
+5
-5
src/script/script.cpp
src/script/script.cpp
+3
-3
src/script/script.hpp
src/script/script.hpp
+2
-2
No files found.
src/data/field/choice.cpp
View file @
de72b872
...
@@ -171,6 +171,7 @@ IMPLEMENT_REFLECTION_ENUM(ChoiceRenderStyle) {
...
@@ -171,6 +171,7 @@ IMPLEMENT_REFLECTION_ENUM(ChoiceRenderStyle) {
}
}
IMPLEMENT_REFLECTION
(
ChoiceStyle
)
{
IMPLEMENT_REFLECTION
(
ChoiceStyle
)
{
tag
.
addAlias
(
300
,
_
(
"card list colors"
),
_
(
"colors card list"
));
REFLECT_BASE
(
Style
);
REFLECT_BASE
(
Style
);
REFLECT
(
popup_style
);
REFLECT
(
popup_style
);
REFLECT
(
render_style
);
REFLECT
(
render_style
);
...
...
src/data/stylesheet.cpp
View file @
de72b872
...
@@ -38,11 +38,11 @@ InputStreamP StyleSheet::openIconFile() {
...
@@ -38,11 +38,11 @@ InputStreamP StyleSheet::openIconFile() {
}
}
IMPLEMENT_REFLECTION
(
StyleSheet
)
{
IMPLEMENT_REFLECTION
(
StyleSheet
)
{
// < 0.3.0 didn't use card_ prefix
// < 0.3.0 didn't use card_ prefix
tag
.
addAlias
(
300
,
_
(
"width"
),
_
(
"card
_
width"
));
tag
.
addAlias
(
300
,
_
(
"width"
),
_
(
"card
width"
));
tag
.
addAlias
(
300
,
_
(
"height"
),
_
(
"card
_
height"
));
tag
.
addAlias
(
300
,
_
(
"height"
),
_
(
"card
height"
));
tag
.
addAlias
(
300
,
_
(
"dpi"
),
_
(
"card
_
dpi"
));
tag
.
addAlias
(
300
,
_
(
"dpi"
),
_
(
"card
dpi"
));
tag
.
addAlias
(
300
,
_
(
"background"
),
_
(
"card
_
background"
));
tag
.
addAlias
(
300
,
_
(
"background"
),
_
(
"card
background"
));
tag
.
addAlias
(
300
,
_
(
"info
_style"
),
_
(
"set_info_
style"
));
tag
.
addAlias
(
300
,
_
(
"info
style"
),
_
(
"set info
style"
));
tag
.
addAlias
(
300
,
_
(
"align"
),
_
(
"alignment"
));
tag
.
addAlias
(
300
,
_
(
"align"
),
_
(
"alignment"
));
REFLECT
(
game
);
REFLECT
(
game
);
...
...
src/main.cpp
View file @
de72b872
...
@@ -37,6 +37,7 @@ IMPLEMENT_APP(MSE)
...
@@ -37,6 +37,7 @@ IMPLEMENT_APP(MSE)
bool
MSE
::
OnInit
()
{
bool
MSE
::
OnInit
()
{
try
{
try
{
SetAppName
(
_
(
"Magic Set Editor"
));
wxInitAllImageHandlers
();
wxInitAllImageHandlers
();
init_file_formats
();
init_file_formats
();
settings
.
read
();
settings
.
read
();
...
...
src/script/context.cpp
View file @
de72b872
...
@@ -72,7 +72,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
...
@@ -72,7 +72,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
// Get a variable
// Get a variable
case
I_GET_VAR
:
{
case
I_GET_VAR
:
{
ScriptValueP
value
=
variables
[
i
.
data
].
value
;
ScriptValueP
value
=
variables
[
i
.
data
].
value
;
if
(
!
value
)
throw
ScriptError
(
_
(
"Variable not set: "
)
+
variable
ToS
tring
(
i
.
data
));
if
(
!
value
)
throw
ScriptError
(
_
(
"Variable not set: "
)
+
variable
_to_s
tring
(
i
.
data
));
stack
.
push_back
(
value
);
stack
.
push_back
(
value
);
break
;
break
;
}
}
...
@@ -163,7 +163,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
...
@@ -163,7 +163,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
}
}
void
Context
::
setVariable
(
const
String
&
name
,
const
ScriptValueP
&
value
)
{
void
Context
::
setVariable
(
const
String
&
name
,
const
ScriptValueP
&
value
)
{
setVariable
(
string
ToV
ariable
(
name
),
value
);
setVariable
(
string
_to_v
ariable
(
name
),
value
);
}
}
void
Context
::
setVariable
(
int
name
,
const
ScriptValueP
&
value
)
{
void
Context
::
setVariable
(
int
name
,
const
ScriptValueP
&
value
)
{
...
@@ -178,13 +178,13 @@ void Context::setVariable(int name, const ScriptValueP& value) {
...
@@ -178,13 +178,13 @@ void Context::setVariable(int name, const ScriptValueP& value) {
}
}
ScriptValueP
Context
::
getVariable
(
const
String
&
name
)
{
ScriptValueP
Context
::
getVariable
(
const
String
&
name
)
{
ScriptValueP
value
=
variables
[
string
ToV
ariable
(
name
)].
value
;
ScriptValueP
value
=
variables
[
string
_to_v
ariable
(
name
)].
value
;
if
(
!
value
)
throw
ScriptError
(
_
(
"Variable not set: "
)
+
name
);
if
(
!
value
)
throw
ScriptError
(
_
(
"Variable not set: "
)
+
name
);
return
value
;
return
value
;
}
}
ScriptValueP
Context
::
getVariableOpt
(
const
String
&
name
)
{
ScriptValueP
Context
::
getVariableOpt
(
const
String
&
name
)
{
return
variables
[
string
ToV
ariable
(
name
)].
value
;
return
variables
[
string
_to_v
ariable
(
name
)].
value
;
}
}
...
...
src/script/context.hpp
View file @
de72b872
...
@@ -69,7 +69,7 @@ class Context {
...
@@ -69,7 +69,7 @@ class Context {
Variable
value
;
///< Old value of that variable.
Variable
value
;
///< Old value of that variable.
};
};
private:
private:
/// Variables, indexed by integer naem (using string
ToV
ariable)
/// Variables, indexed by integer naem (using string
_to_v
ariable)
VectorIntMap
<
unsigned
int
,
Variable
>
variables
;
VectorIntMap
<
unsigned
int
,
Variable
>
variables
;
/// Shadowed variable bindings
/// Shadowed variable bindings
vector
<
Binding
>
shadowed
;
vector
<
Binding
>
shadowed
;
...
...
src/script/dependency.cpp
View file @
de72b872
...
@@ -64,6 +64,20 @@ ScriptValueP unified(const ScriptValueP& a, const ScriptValueP& b) {
...
@@ -64,6 +64,20 @@ ScriptValueP unified(const ScriptValueP& a, const ScriptValueP& b) {
else
return
new_intrusive2
<
DependencyUnion
>
(
a
,
b
);
else
return
new_intrusive2
<
DependencyUnion
>
(
a
,
b
);
}
}
/// Behaves like script_nil, but with a name
class
ScriptMissingVariable
:
public
ScriptValue
{
public:
ScriptMissingVariable
(
const
String
&
name
)
:
name
(
name
)
{}
virtual
ScriptType
type
()
const
{
return
SCRIPT_NIL
;
}
virtual
String
typeName
()
const
{
return
_
(
"missing variable '"
)
+
name
+
_
(
"'"
);
}
virtual
operator
String
()
const
{
return
wxEmptyString
;
}
virtual
operator
double
()
const
{
return
0.0
;
}
virtual
operator
int
()
const
{
return
0
;
}
virtual
ScriptValueP
eval
(
Context
&
)
const
{
return
script_nil
;
}
// nil() == nil
private:
String
name
;
///< Name of the variable
};
// ----------------------------------------------------------------------------- : Jump record
// ----------------------------------------------------------------------------- : Jump record
// Utility class: a jump that has been postponed
// Utility class: a jump that has been postponed
...
@@ -245,7 +259,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
...
@@ -245,7 +259,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
// Get a variable (almost as normal)
// Get a variable (almost as normal)
case
I_GET_VAR
:
{
case
I_GET_VAR
:
{
ScriptValueP
value
=
variables
[
i
.
data
].
value
;
ScriptValueP
value
=
variables
[
i
.
data
].
value
;
if
(
!
value
)
value
=
script_nil
;
// no errors here
if
(
!
value
)
value
=
new_intrusive1
<
ScriptMissingVariable
>
(
variable_to_string
(
i
.
data
))
;
// no errors here
stack
.
push_back
(
value
);
stack
.
push_back
(
value
);
break
;
break
;
}
}
...
...
src/script/parser.cpp
View file @
de72b872
...
@@ -355,7 +355,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
...
@@ -355,7 +355,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
script
.
addInstruction
(
I_LOOP
,
0xFFFF
);
// loop
script
.
addInstruction
(
I_LOOP
,
0xFFFF
);
// loop
expectToken
(
input
,
_
(
"do"
));
// do
expectToken
(
input
,
_
(
"do"
));
// do
script
.
addInstruction
(
I_SET_VAR
,
script
.
addInstruction
(
I_SET_VAR
,
string
ToVariable
(
name
.
value
));
// set name
string
_to_variable
(
name
.
value
));
// set name
script
.
addInstruction
(
I_POP
);
// pop
script
.
addInstruction
(
I_POP
);
// pop
parseOper
(
input
,
script
,
PREC_SET
,
I_BINARY
,
I_ADD
);
// CCC; add
parseOper
(
input
,
script
,
PREC_SET
,
I_BINARY
,
I_ADD
);
// CCC; add
script
.
addInstruction
(
I_JUMP
,
lblStart
);
// jump lbl_start
script
.
addInstruction
(
I_JUMP
,
lblStart
);
// jump lbl_start
...
@@ -373,7 +373,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
...
@@ -373,7 +373,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
script
.
addInstruction
(
I_LOOP
,
0xFFFF
);
// loop
script
.
addInstruction
(
I_LOOP
,
0xFFFF
);
// loop
expectToken
(
input
,
_
(
"do"
));
// do
expectToken
(
input
,
_
(
"do"
));
// do
script
.
addInstruction
(
I_SET_VAR
,
script
.
addInstruction
(
I_SET_VAR
,
string
ToVariable
(
name
.
value
));
// set name
string
_to_variable
(
name
.
value
));
// set name
script
.
addInstruction
(
I_POP
);
// pop
script
.
addInstruction
(
I_POP
);
// pop
parseOper
(
input
,
script
,
PREC_SET
,
I_BINARY
,
I_ADD
);
// DDD; add
parseOper
(
input
,
script
,
PREC_SET
,
I_BINARY
,
I_ADD
);
// DDD; add
script
.
addInstruction
(
I_JUMP
,
lblStart
);
// jump lbl_start
script
.
addInstruction
(
I_JUMP
,
lblStart
);
// jump lbl_start
...
@@ -391,7 +391,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
...
@@ -391,7 +391,7 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
script
.
addInstruction
(
I_TERNARY
,
I_RGB
);
script
.
addInstruction
(
I_TERNARY
,
I_RGB
);
}
else
{
}
else
{
// variable
// variable
unsigned
int
var
=
string
ToV
ariable
(
token
.
value
);
unsigned
int
var
=
string
_to_v
ariable
(
token
.
value
);
script
.
addInstruction
(
I_GET_VAR
,
var
);
script
.
addInstruction
(
I_GET_VAR
,
var
);
}
}
}
else
if
(
token
==
TOK_INT
)
{
}
else
if
(
token
==
TOK_INT
)
{
...
@@ -475,13 +475,13 @@ void parseOper(TokenIterator& input, Script& script, Precedence minPrec, Instruc
...
@@ -475,13 +475,13 @@ void parseOper(TokenIterator& input, Script& script, Precedence minPrec, Instruc
while
(
t
!=
_
(
")"
))
{
while
(
t
!=
_
(
")"
))
{
if
(
input
.
peek
(
2
)
==
_
(
":"
))
{
if
(
input
.
peek
(
2
)
==
_
(
":"
))
{
// name: ...
// name: ...
arguments
.
push_back
(
string
ToV
ariable
(
t
.
value
));
arguments
.
push_back
(
string
_to_v
ariable
(
t
.
value
));
input
.
read
();
// skip the name
input
.
read
();
// skip the name
input
.
read
();
// and the :
input
.
read
();
// and the :
parseOper
(
input
,
script
,
PREC_SEQ
);
parseOper
(
input
,
script
,
PREC_SEQ
);
}
else
{
}
else
{
// implicit "input" argument
// implicit "input" argument
arguments
.
push_back
(
string
ToV
ariable
(
_
(
"input"
)));
arguments
.
push_back
(
string
_to_v
ariable
(
_
(
"input"
)));
parseOper
(
input
,
script
,
PREC_SEQ
);
parseOper
(
input
,
script
,
PREC_SEQ
);
}
}
t
=
input
.
peek
();
t
=
input
.
peek
();
...
...
src/script/script.cpp
View file @
de72b872
...
@@ -17,7 +17,7 @@ Variables variables;
...
@@ -17,7 +17,7 @@ Variables variables;
DECLARE_TYPEOF
(
Variables
);
DECLARE_TYPEOF
(
Variables
);
/// Return a unique name for a variable to allow for faster loopups
/// Return a unique name for a variable to allow for faster loopups
unsigned
int
string
ToV
ariable
(
const
String
&
s
)
{
unsigned
int
string
_to_v
ariable
(
const
String
&
s
)
{
map
<
String
,
unsigned
int
>::
iterator
it
=
variables
.
find
(
s
);
map
<
String
,
unsigned
int
>::
iterator
it
=
variables
.
find
(
s
);
if
(
it
==
variables
.
end
())
{
if
(
it
==
variables
.
end
())
{
unsigned
int
v
=
(
unsigned
int
)
variables
.
size
();
unsigned
int
v
=
(
unsigned
int
)
variables
.
size
();
...
@@ -31,7 +31,7 @@ unsigned int stringToVariable(const String& s) {
...
@@ -31,7 +31,7 @@ unsigned int stringToVariable(const String& s) {
/// Get the name of a vaiable
/// Get the name of a vaiable
/** Warning: this function is slow, it should only be used for error messages and such.
/** Warning: this function is slow, it should only be used for error messages and such.
*/
*/
String
variable
ToS
tring
(
unsigned
int
v
)
{
String
variable
_to_s
tring
(
unsigned
int
v
)
{
FOR_EACH
(
vi
,
variables
)
{
FOR_EACH
(
vi
,
variables
)
{
if
(
vi
.
second
==
v
)
return
vi
.
first
;
if
(
vi
.
second
==
v
)
return
vi
.
first
;
}
}
...
@@ -159,7 +159,7 @@ String Script::dumpInstr(unsigned int pos, Instruction i) const {
...
@@ -159,7 +159,7 @@ String Script::dumpInstr(unsigned int pos, Instruction i) const {
ret += "\t" + lexical_cast<String>(i.data);
ret += "\t" + lexical_cast<String>(i.data);
break;
break;
case I_GET_VAR: case I_SET_VAR: case I_NOP: // variable
case I_GET_VAR: case I_SET_VAR: case I_NOP: // variable
ret += "\t" + variable
ToS
tring(i.data) + "\t$" + lexical_cast<String>(i.data);
ret += "\t" + variable
_to_s
tring(i.data) + "\t$" + lexical_cast<String>(i.data);
break;
break;
}
}
return ret;
return ret;
...
...
src/script/script.hpp
View file @
de72b872
...
@@ -93,12 +93,12 @@ struct Instruction {
...
@@ -93,12 +93,12 @@ struct Instruction {
// ----------------------------------------------------------------------------- : Variables
// ----------------------------------------------------------------------------- : Variables
/// Return a unique name for a variable to allow for faster loopups
/// Return a unique name for a variable to allow for faster loopups
unsigned
int
string
ToV
ariable
(
const
String
&
s
);
unsigned
int
string
_to_v
ariable
(
const
String
&
s
);
/// Get the name of a vaiable
/// Get the name of a vaiable
/** Warning: this function is slow, it should only be used for error messages and such.
/** Warning: this function is slow, it should only be used for error messages and such.
*/
*/
String
variable
ToS
tring
(
unsigned
int
v
);
String
variable
_to_s
tring
(
unsigned
int
v
);
// ----------------------------------------------------------------------------- : Script
// ----------------------------------------------------------------------------- : Script
...
...
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