Mythruna
September 19, 2025, 09:55:05 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: My Mythruna Mods  (Read 19676 times)
pspeed
Administrator
Hero Member
*****
Posts: 5613



View Profile
« Reply #15 on: October 06, 2012, 06:20:28 PM »

Hey Paul, I have a quick question.
If I wanted to make a mod for Mythruna, would it have to be written in Groovy or could I choose between using Groovy or Java?

Groovy can call Java... so you'd have to at least have a groovy stub to get it to load using the standard mod mechanism.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5613



View Profile
« Reply #16 on: October 06, 2012, 08:29:07 PM »

Hey Paul, I have a quick question.
If I wanted to make a mod for Mythruna, would it have to be written in Groovy or could I choose between using Groovy or Java?

Groovy can call Java... so you'd have to at least have a groovy stub to get it to load using the standard mod mechanism.

Just to clarify this further because I saw some less-than-correct information flying around on the chat.

Groovy and Java are a natural fit because groovy compiles are runtime to byte code essentially.  Groovy is written in Java and essentially is calling Java classes to do anything significant.  You can even pre-compile groovy to Java .class files (though it will still do some stuff at runtime because of the dynamic typing).

Mythruna's game engine is nearly 100% Java.  It's the game specific stuff on top that has a large percentage of groovy code and it was a natural fit for mods.

Most of the mods are calling the groovy-exposed API to register callback objects with the engine... either hooks for shell commands or hooks for tools or hooks for context menus, etc..  These APIs generally take Java objects... but since Groovy objects are also Java objects, it just works.

You can just as easily register real Java objects implementing the appropriate interfaces.  You still need the groovy script to hook them into the engine... but that's because I search for and run groovy scripts at startup.

In fact, many of the standard console commands are Java objects.  Maybe half or less are configured in groovy scripts that are run during startup.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5613



View Profile
« Reply #17 on: October 06, 2012, 08:33:27 PM »

But also note: Groovy is a lot easier to use for some purposes and most Java syntax will work fine there.  The dynamic typing, ability to easily setup DSL-like constructs, and short-cuts really make it nice for scripting mods.

For example, in Groovy:
Code:
// Pull the player's name component from the entity system and derefernece
// it's string value.
name = player[Name.class]?.name

Versus in Java:
Code:
Name n = entitySystem.getComponent( player, Name.class );
String name = n == null ? null : n.getName();

And actually, "name" is such a common thing to get from an entity that I went ahead and made a short-cut so:
Code:
name = player.name
...will work just as well.
Logged
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« Reply #18 on: October 06, 2012, 08:46:19 PM »

It was Sean and I talking about that Smiley
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!