class Element include MicroChunkUser Ruleset_CUSX_base = $ruleset_CUSX_base Ruleset_GRPX = $ruleset_GRPX mcAccessorsFromRuleset(Ruleset_CUSX_base) mcAccessorsFromRuleset(Ruleset_GRPX) # TODO merge ruleset_GRPX and ElementGroupInfo with Element properly # IMPORTANT TODO the attribute list of elements in group element should be "gelement" # instead of "element" def tokenName # element token used in config files EL.token_name(@id) end def className # element class used in config files EL.class_name(@id) end def editorDescription(@id) # pre-defined description for level editor EL.editor_description(@id) end # char *custom_description; /* alternative description from config file */ # # /* ---------- graphic and sound definitions ---------- */ # # int graphic[NUM_ACTIONS]; /* default graphics for several actions */ # int direction_graphic[NUM_ACTIONS][NUM_DIRECTIONS_FULL]; # /* special graphics for left/right/up/down */ # # int crumbled[NUM_ACTIONS]; /* crumbled graphics for several actions */ # int direction_crumbled[NUM_ACTIONS][NUM_DIRECTIONS_FULL]; # /* crumbled graphics for left/right/up/down */ # # int special_graphic[NUM_SPECIAL_GFX_ARGS]; # /* special graphics for certain screens */ # # int sound[NUM_ACTIONS]; /* default sounds for several actions */ # # /* ---------- special element property values ---------- */ # # unsigned long properties[NUM_EP_BITFIELDS]; /* element base properties */ # # struct ElementChangeInfo *change_page; /* actual list of change pages */ # struct ElementChangeInfo *change; /* pointer to current change page */ # # int num_change_pages; /* actual number of change pages */ # int current_change_page; /* currently edited change page */ # # struct ElementGroupInfo *group; /* pointer to element group info */ # # /* ---------- internal values used in level editor ---------- */ # # int access_type; /* walkable or passable */ # int access_layer; /* accessible over/inside/under */ # int access_protected; /* protection against deadly elements */ # int walk_to_action; /* diggable/collectible/pushable */ # int smash_targets; /* can smash player/enemies/everything */ # int deadliness; /* deadly when running/colliding/touching */ # # boolean can_explode_by_fire; /* element explodes by fire */ # boolean can_explode_smashed; /* element explodes when smashed */ # boolean can_explode_impact; /* element explodes on impact */ # # boolean modified_settings; /* set for all modified custom elements */ def defaultDescription @custom_description ? @custom_description : @editor_description end def copyTo(ei_to) # TODO: probably use '@' instead of 'self' (where possible) mcCopyValuesTo(ei_to, Ruleset_CUSX_base) # ---------- reinitialize and copy change pages ---------- ei_to.numChangePages = self.numChangePages ei_to.currentChangePage = self.currentChangePage ei_to.numChangePages.times do |i| ei_to.changePage[i] = self.changePage[i].dup end # mark this custom element as modified ei_to.modifiedSettings = true ei_to end def copy copyTo(Element.new) end # FIXME @deprecated! Use changePage.length instead. def numChangePages=(val) @changePage.length = val end def numChangePages @changePage.length end def currentChangePage @currentChangePage = 0 if !@currentChangePage @currentChangePage = @changePage.length-1 if @currentChangePage >= @changePage.length @currentChangePage end # TODO this should probably be renamed def change @changePage[currentChangePage] end def initialize(elementId) mcSetToDefaults(Ruleset_CUSX_base) mcSetToDefaults(Ruleset_GRPX) if IS_CUSTOM_ELEMENT(elementId) || IS_GROUP_ELEMENT(elementId) || IS_INTERNAL_ELEMENT(elementId) mcSetToDefaults(Ruleset_CUSX_base) end @changePage = Array.new @changePage.setDefault { ChangePage.new } @changePage.length = 1 if IS_CUSTOM_ELEMENT(elementId) || IS_GROUP_ELEMENT(elementId) || IS_INTERNAL_ELEMENT(elementId) @description = defaultDescription @modified_settings = false end if IS_CUSTOM_ELEMENT(elementId) || IS_INTERNAL_ELEMENT(elementId) # internal values used in level editor # TODO: maybe these aren't needed? (And virtual attributes can be used instead?) @access_type = 0 @access_layer = 0 @access_protected = 0 @walk_to_action = 0 @smash_targets = 0 @deadliness = 0 @can_explode_by_fire = false @can_explode_smashed = false @can_explode_impact = false @current_change_page = 0 end end # # 'content' is stored as TYPE_CONTENT_LIST (struct Content[] in C) in # ruleset_CUSX_base. That's because microchunks don't have a 'TYPE_CONTENT'. # In C, it didn't make any difference, because a pointer to array of structs # Content ('struct Content*') is the same as a pointer to one struct Content # ('struct Content*'). However, in Ruby it does make a difference. So I'm # using these helper functions. If the program tries to set content to array # of Contents, it uses only the first (and probably only) item from it, and # similarly if the program tries to get the array of contents, it returns an # array that contains only @content. # def mcGet_content(index) return @content if index return [@content] end def mcSet_content(val,index) @content = val if index @content = val[0] if !index end def defaultDescription @customDescription ? @customDescription : editorDescription end end