mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add a plugin which allows creating mixins for Mobs
Adds a mob-extension plugin, which allows creating modules as mixins to be monkey-patched into the Mob class. Having a standard method of doing this prevents confusing problems with mixin name conflicts, by allowing the plugin to raise an error that 2 mixins with the same name exist.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.model.entity.Mob'
|
||||
|
||||
module MobExtension
|
||||
MOB_EXTENSIONS = []
|
||||
|
||||
def self.register(extension)
|
||||
fail 'Provided extension object is not a module' unless extension.is_a?(Module)
|
||||
|
||||
new_mixins = extension.public_instance_methods
|
||||
current_mixins = MOB_EXTENSIONS.map { |e| {e.to_s => e.public_instance_methods} }
|
||||
|
||||
current_mixins.each do |ext, methods|
|
||||
methods.each {|m| fail "Extension #{ext} already provides method #{m}" if new_mixins.include?(m) }
|
||||
end
|
||||
|
||||
Mob.include(extension)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<plugin>
|
||||
<id>mob-extension</id>
|
||||
<version>0.1</version>
|
||||
<name>Mob Extensions</name>
|
||||
<description>Adds support for extending Mobs with new functionality</description>
|
||||
<authors>
|
||||
<author>Gary Tierney</author>
|
||||
</authors>
|
||||
<scripts>
|
||||
<script>extension.rb</script>
|
||||
</scripts>
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
Reference in New Issue
Block a user