Simple scripting/templates with Inkscape

Post questions on how to use or achieve an effect in Inkscape.
agamemnus
Posts: 5
Joined: Wed Apr 28, 2010 7:24 am

Simple scripting/templates with Inkscape

Postby agamemnus » Wed Apr 28, 2010 7:55 am

Hello,

I would like to make Inkscape the editor for the game I'm making. At the moment, however, it's not very easy to do without a "template" or some sort of variable scripting:

I found out about the SVG "use" tag yesterday, but I need something more powerful. Here's my current setup:

Code: Select all

<defs id="templates">
 <g id="template_area_capital">

   <path id="template_area_capital_crosshair"
    d="m -7.5,0 15,0 -7.5,0 0,-7.5 0,15 0,-7.5"
    style="stroke:#000000;stroke-width:0.05012808;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />

   <circle id="template_area_capital_circle" cx = "0" cy = "0" r = "7.5"
    style="fill:#003f7f;fill-opacity:0.49803922;stroke:#000000;stroke-width:0.05012808;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />

   <rect id="template_area_capital_port" width = ".5" height = ".5" x = "-.25" y = "-.25"
    style="fill:none; stroke:#0000ff; stroke-width:0.025; stroke-miterlimit:4; stroke-opacity:1; stroke-dasharray:none" />
 </g>
</defs>


And the use command:

Code: Select all

<use id="city_E_Syracuse_L_Syracusae" xlink:href="#template_area_capital"
x="1145.5" y="1399" height="1" width="1" />


---------------

This is the hypothetical ideal:


Code: Select all

<defs id="templates">
 <g id="template_point">
   switch ($subtype) {
   case "empire capital": ("template_point_circle").fill = "red"; // Or use a hex value..
   case "capital": ("template_point_circle").fill = "blue";
   case "city": ("template_point_circle").fill = "green";
   case "fort": ("template_point_circle").fill = "purple";
   }

   <path id="template_point_crosshair"
    d="m -7.5,0 15,0 -7.5,0 0,-7.5 0,15 0,-7.5"
    style="stroke:#000000;stroke-width:0.05012808;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />

   <circle id="template_point_circle" cx = "0" cy = "0" r = $size
    style="fill:#003f7f;fill-opacity:0.49803922;stroke:#000000;stroke-width:0.05012808;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />

   <rect id="template_point_port" width = ".5" height = ".5" x = (-.25+$portx) y = (-.25+$porty)
    style="fill:none; stroke:#0000ff; stroke-width:0.025; stroke-miterlimit:4; stroke-opacity:1; stroke-dasharray:none" />
 </g>
</defs>


Code: Select all

<use id="city_E_Syracuse_L_Syracusae" xlink:href="#template_point"
x="1145.5"
y="1399"
size = "7.5"
subtype = "capital"
portx = "5"
porty = "10"
/>


I'd also like to be able to move the rectangle (id="template_point_port") using the inkscape GUI move command and have it update portx and porty. Similarly with circle size and color-- if the GUI changes those properties, the subtype and width would be affected as well.

Any way to do this or anything close to it in Inkscape? Many thanks.

agamemnus
Posts: 5
Joined: Wed Apr 28, 2010 7:24 am

Re: Simple scripting/templates with Inkscape

Postby agamemnus » Wed Apr 28, 2010 1:38 pm

As an example to how you'd go from inkscape GUI movement to changing the data:

Code: Select all

switch (event) {
case "stretched_evenly": cancel_regular_action(); instance.size = new_size;
case "color_changed":
 switch toInt(color):
 case "red": cancel_regular_action(); subtype = "empire capital";
 case "blue": cancel_regular_action(); subtype = "capital";
 case "green": cancel_regular_action(); subtype = "city";
 case "fort": cancel_regular_action(); subtype = "purple";
}
case "childrenMoved":
 cancel_regular_action();
 portx = dx("template_point_port");
 portx = dy("template_point_port");

}

User avatar
RobA
Posts: 335
Joined: Fri Aug 10, 2007 1:22 am

Re: Simple scripting/templates with Inkscape

Postby RobA » Thu Apr 29, 2010 2:15 am

Xmoto uses inkscape as a level editor.

Take a look at that.

http://wiki.xmoto.tuxfamily.org/index.p ... g_Inkscape

-Rob A>

agamemnus
Posts: 5
Joined: Wed Apr 28, 2010 7:24 am

Re: Simple scripting/templates with Inkscape

Postby agamemnus » Thu Apr 29, 2010 3:20 pm

Doesn't appear to be at all similar. :\


Return to “Help with using Inkscape”