-
Notifications
You must be signed in to change notification settings - Fork 41
developers todo javascript
This is the proposed design for supporting JavaScript for Definition
values and reference values.
This functionality would be an alternative to the existing scripting functionality.
Key points:
- ClearScript will be used to execute the JavaScript
- Incept is the name given to the original scripting system used by CardMaker (made this up just now)
- JavaScript and Incept will co-exist
For simplicity (any my sanity) a project will either be in JavaScript or Incept. This will be a setting on the project and CardMaker will have a default setting for all new projects so users do not have to set it each time they create a new project.
The Definition
value will be a script intended to be executed without the creation of a
JavaScript function. The last executed line determines the final output value. There is no need to return.
'hello world'
Result hello world
x = 20;
if(x > 15) 'wow';
if(x > 25) 'great';
Result wow
Variable | Description |
---|---|
deckIndex | The overall index of the card in the Layout
|
cardIndex | The index of the card based on the current card's count column |
(likely more!)
Reference variables will be accessible by the column name (lower case!). The only exception is if the column
name includes a space. In this case an underscore(_
) will be used to replace any spaces in the name.
Defines will be accessible via the same naming scheme.
A reference value can itself be a fully defined function with or without parameters.
Likely the standard replacements like newlines etc.
As with JavaScript a raw string must be quoted. This quoting only applies to values specified in the CardMaker Definition value so it can be interpreted as a raw string when passed into the JavaScript interpreter.
Current row values:
Reference | Value |
---|---|
name | William |
The Definition
required for the name reference is name
Current row values:
Reference | Value |
---|---|
name | William |
color | function(){ if(name == 'William') return 'red'; } |
The Definition
required for the color reference is color()
Internally CardMaker would generate a script that looks like the following.
name = 'William';
color = function(){ if (name == 'William') return 'red'; }
color()
A complex reference is one that combines
~
is used as a special case to avoid Excel/Calc breaking entries that start with a single quote ('
). Normally Excel/Calc would interpret these as special characters and potentially trash the value specified by the user. By entering a ~
as the first character before a single quote Calc/Excel leave the value as-is. CardMaker will detect and remove the ~
if it is the first character and immediately followed by a single quote.
CardMaker should help users that make mistakes. For example if the user accidentally
enters color
instead of color()
the returned type is not an int/string/float and
a log message should indicate this.
parseInt
and parseFloat
will be required for numeric operations involving values
assigned from references. This is necessary because the value pulled from the reference
is always assumed to be a string.
Example:
Reference | Value |
---|---|
points | 45 |
color | function(){ if(parseInt(points) > 30) return 'awesome'; } |
The application has always had a no-multiline Definition
field to avoid confusing users. When a project
is in JavaScript mode the Definition
control should allow multiline input.