Subclassing Projectile

Moderator: Moderator

Post Reply
Message
Author
Castler
Thalore
Posts: 153
Joined: Mon Mar 25, 2013 10:09 pm

Subclassing Projectile

#1 Post by Castler »

Subclassing Projectile doesn't seem to work as intended.

If I do the following:
  • In Actor.lua, set _M.projectile_class = "mod.class.Projectile"
  • Create a Projectile.lua file in the class directory that inherits from engine.Projectile
  • Define a makeProjectile method that invoke engine.projectile.makeProjectile and then does a bit of its own processing.
  • Define an act method
Then my makeProjectile is called as expected, but act is not.

From what I can tell, this is because engine.Projectile:makeProject calls _M.new, which creates an instance of engine.Projectile instead of my mod.class.Projectile.

It seems to me that makeProject and makeHoming should instead call self.new to make it possible to properly subclass Projectile.

Am I understanding this correctly?

As a side question, is there an easy way to test engine modifications of this sort, short of building the entire ToME project from scratch?
Qi Daozei (QDZ) - an Oriental-themed fantasy game for T-Engine. ToME Tips - auto-generated spoilers for ToME.

0player
Uruivellas
Posts: 717
Joined: Fri May 24, 2013 4:27 pm

Re: Subclassing Projectile

#2 Post by 0player »

Yeah, just unpack engine into an appropriate dir and do whatever changes you need. You will disable your online profile, but it'll work.

Castler
Thalore
Posts: 153
Joined: Mon Mar 25, 2013 10:09 pm

Re: Subclassing Projectile

#3 Post by Castler »

Thanks. I had tried unpacking the engine and was simply using the wrong directory name.

In case anyone else is interested, here are step-by-step instructions:
  1. Unpack game/engines/te4-1.0.4.teae to the directory game/engines/te4-1.0.4. (For example, if using 7-zip, you can just right-click on te4-1.0.4.teae in Windows Explorer and choose 7-zip -> Extract to "te4-1.0.4\")
  2. Unpack game/modules/tome-1.0.4.team to the directory game/modules/tome-1.0.4. (Again, if using 7-zip, you can right-click on tome-1.0.4.team in Windows Explorer and choose 7-zip -> Extract to "tome-1.0.4\").
  3. The directory layout of tome-1.0.4 won't match what ToME is expecting. Go under tome-1.0.4\mod and move all files and directories from there to tome-1.0.4.
After I did this, I was able to confirm that changing engine.Projectile:makeProject and engine.Projectile:makeHoming to call self.new instead of _M.new fixes this problem.

I also discovered that ToME itself is affected by this bug. ToME's Projectile.lua includes code to animate projectiles and to show internal information in the tooltip if a projectile is hovered over and cheating is enabled, and that code doesn't work. To demonstrate, create a new archmage, go to the Abashed Expanse (which will have lots of projectiles flying around), turn on cheating, and set "smooth creatures movement" all the way up to 60. Projectile movement will animate much, much faster than character movement (because it's ignoring ToME's customization of animation speed), and the projectile tooltip contains no additional information. (ToME's Projectile:tooltip contains a different, unrelated bug: tstring() should be tstring{}.)
Qi Daozei (QDZ) - an Oriental-themed fantasy game for T-Engine. ToME Tips - auto-generated spoilers for ToME.

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Subclassing Projectile

#4 Post by darkgod »

Ohoh yes indeed!

Fixed thanks :)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Post Reply