diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..d12ca2f --- /dev/null +++ b/changelog.md @@ -0,0 +1,30 @@ + + +# changelog 1.3.0 +* #### Established Versioning system +* #### moved the following fields + * `inventory_image_magless` -> `inventory.inventory_image_magless` + * `inventory_image_magless` -> `inventory.inventory_image_magless` + * `firemode_inventory_overlays` - > `inventory.firemode_inventory_overlays` + * `ammo_handler` -> `subclasses.ammo_handler` + * `sprite_scope` -> `subclasses.sprite_scope` + * `crosshair` -> `subclasses.crosshair` +* #### create the following classes + * `Part_handler` + * completed (expansion later) + * facilitates attachments + * `Physics_system` + * inactive + * future implementation for automatic translation + * `Reflector_sight` + * work in progress + * simulates a reflector sight with an entity +* #### added the following changes to the gun class + * made `consts` and `properties` proxy tables for protection of data (and reworked the LEEF class lib for this) + * created a system for property modification + * added `subclasses` property to replace hardcoded subclasses with modular system + * added `subclass_instances` field (see above). These will be automatically updated if their index is in the subclasses list. + * added `visuals.attached_objects` property to define attached entities + * added `attached_objects` field + * made `get_pos` capable of accounting for animation translations + diff --git a/classes/Gun-construct.lua b/classes/Gun-construct.lua index 466364f..16b28ff 100644 --- a/classes/Gun-construct.lua +++ b/classes/Gun-construct.lua @@ -296,25 +296,32 @@ local function reregister_item(self, props) end --accept a chain of indices where the value from old_index overrides new_index local function warn_deprecation(gun, field, new_field) - minetest.log("warning", "Guns4d: `"..gun.."` deprecated use of field `"..field.."` use `"..new_field.."` instead.") + minetest.log("warning", "Guns4d: `"..gun.."` deprecated use of field `"..field.."` in properties. Use `"..new_field.."` instead.") end -local function patch_old_gun(self, minor_version) +local function patch_deprecated(self, minor_version) local props = self.properties - --minor version 2 changes... - if minor_version==2 then - if props.firemode_inventory_overlays then - warn_deprecation(self.name, "firemode_inventory_overlays", "inventory.firemode_inventory_overlays") - for i, _ in pairs(props.firemode_inventory_overlays) do - props.inventory.firemode_inventory_overlays[i] = props.firemode_inventory_overlays[i] - end + --1.2->1.3 (probably missing some.) + if props.firemode_inventory_overlays then + warn_deprecation(self.name, "firemode_inventory_overlays", "inventory.firemode_inventory_overlays") + for i, _ in pairs(props.firemode_inventory_overlays) do + props.inventory.firemode_inventory_overlays[i] = props.firemode_inventory_overlays[i] end - for _, i in pairs {"ammo_handler", "part_handler", "crosshair", "sprite_scope"} do - if props[i] then - warn_deprecation(self.name, i, "subclasses."..i) - props.subclasses[i] = props[i] - end + end + for _, i in pairs {"ammo_handler", "part_handler", "crosshair", "sprite_scope"} do + if props[i] then + warn_deprecation(self.name, i, "subclasses."..i) + props.subclasses[i] = props[i] end end + if self.properties.inventory_image then + self.properties.inventory.inventory_image = self.properties.inventory_image + warn_deprecation(self.name, "inventory_image", "inventory.inventory_image") + end + if self.properties.inventory_image_magless then + self.properties.inventory.inventory_image_magless = self.properties.inventory_image_magless + warn_deprecation(self.name, "inventory_image_magless", "inventory.inventory_image_magless") + end + end --========================== MAIN CLASS CONSTRUCTOR =============================== @@ -352,7 +359,7 @@ function gun_default:construct_base_class() end if self.consts.VERSION[2] < 3 then minetest.log("error", "Guns4d: `"..self.name.."` had minor version before `1.3.0` indicating that this gun likely has no versioning. Attempting patches for `1.2.0`...") - patch_old_gun(self, 2) + patch_deprecated(self, 2) end self.properties = leef.class.proxy_table.new(self.properties) diff --git a/classes/Gun-methods.lua b/classes/Gun-methods.lua index 1f4d700..b8a46d9 100644 --- a/classes/Gun-methods.lua +++ b/classes/Gun-methods.lua @@ -194,13 +194,13 @@ function gun_default:update_image_and_text_meta(meta) end end --pick the image - local image = self.properties.inventory_image + local image = self.properties.inventory.inventory_image if (ammo.total_bullets > 0) and not ammo.magazine_psuedo_empty then - image = self.properties.inventory_image - elseif self.properties.inventory_image_magless and ( (ammo.loaded_mag == "empty") or (ammo.loaded_mag == "") or ammo.magazine_psuedo_empty) then - image = self.properties.inventory_image_magless - elseif self.properties.inventory_image_empty then - image = self.properties.inventory_image_empty + image = self.properties.inventory.inventory_image + elseif self.properties.inventory.inventory_image_magless and ( (ammo.loaded_mag == "empty") or (ammo.loaded_mag == "") or ammo.magazine_psuedo_empty) then + image = self.properties.inventory.inventory_image_magless + elseif self.properties.inventory.inventory_image_empty then + image = self.properties.inventory.inventory_image_empty end --add the firemode overlay to the image local firemodes = 0 diff --git a/classes/Gun.lua b/classes/Gun.lua index 173ddb4..31d17d8 100644 --- a/classes/Gun.lua +++ b/classes/Gun.lua @@ -1,8 +1,6 @@ ---- Gun class - local Vec = vector ---- Gun class fields +--- class fields -- -- ## Defining a gun: -- @@ -82,16 +80,17 @@ local gun_default = { -- @field hip `table` @{gun.properties.hip|hipfire properties} -- @field ads `table` @{gun.properties.ads|aiming ("aiming down sights") properties} -- @field firemodes `table` @{gun.properties.firemodes|list of firemodes} - -- @field firemode_inventory_overlays `table` @{gun.properties.firemode_inventory_overlays|list of corresponding images for firemodes} -- @field recoil `table` @{gun.properties.recoil|defines the guns recoil} -- @field sway `table` @{gun.properties.sway|defines the guns idle sway} -- @field wag `table` @{gun.properties.wag|defines the movement of the gun while walking} -- @field charging `table` @{gun.properties.charging|defines how rounds are chambered into the gun} -- @field ammo `table` @{gun.properties.ammo|defines what ammo the gun uses} -- @field visuals `table` @{gun.properties.visuals|defines visual attributes of the gun} + -- @field sounds `table` @{gun.properties.sounds|defines sounds to be used by functions of the gun} + -- @field inventory `table` @{gun.properties.inventory|inventory related attributes} -- @compact properties = { - --- starting vertical rotation of the gun + --- `float` starting vertical rotation of the gun initial_vertical_rotation = -60, --- `float`=.5 max angular deviation (vertical) from breathing breathing_scale = .5, @@ -99,10 +98,6 @@ local gun_default = { flash_offset = Vec.new(), --- `int`=600 The number of rounds (cartidges) this gun can throw per minute. Used by update(), fire() and default controls firerateRPM = 600, - --- `string` inventory image for when the gun has no magazine - inventory_image_magless = nil, - --- `string` inventory image for when the gun is loaded. This is added automatically during construction. - inventory_image = nil, --- an ordered list of reloading states used by @{default_controls}. -- -- the default reload states for a magazine operated weapon, copied from the m4. @@ -113,7 +108,7 @@ local gun_default = { -- {action="load", time=.5, anim="load", sounds = {sound="ar_mag_load", delay = .25}}, -- {action="charge", time=.5, anim="charge", sounds={sound="ar_charge", delay = .2}} reload = {}, - --- a table {x1,y1,z1,x2,y2,z2} specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts. This is autogenerated if not present. + --- `table` (optional) a table `{x1,y1,z1, x2,y2,z2}` specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts. This is autogenerated from the model when not present, reccomended that you leave nil. model_bounding_box = nil, --- `string` overlay on the item to use when infinite ammo is on infinite_inventory_overlay = "inventory_overlay_inf_ammo.png", @@ -137,19 +132,15 @@ local gun_default = { firemode = Guns4d.default_touch_controls.firemode, jump_cancel_ads = Guns4d.default_touch_controls.jump_cancel_ads }, + --- properties.inventory + -- + -- @table gun.properties.inventory + -- @see lvl1_fields.properties|properties + -- @compact inventory = { - --[[part_slots = { - underbarrel = { - formspec_inventory_location = {x=0, y=1} - slots = 2, - rail = "picatinny" --only attachments fit for this type will be usable. - allowed = { - "group:guns4d_underbarrel" - }, - bone = "" --the bone both to attach to and to display at on the menu. - } - },]] + --- the size in meters to render the gun in it's inventory opened with /guns4d_inv render_size = 2, --length (in meters) which is visible accross the z/forward axis at y/up=0, x=0. For orthographic this will be the scale of the orthographic camera. Default 2 + --- the image of the gun in it's inventory opened with /guns4d_inv render_image = "m4_ortho.png", --expects an image of the right side of the gun, where the gun is facing the right. Default "m4_ortho.png" --- table of firemodes and their overlays in the player's inventory when the gun is on that firemode firemode_inventory_overlays = { --#4 @@ -162,8 +153,23 @@ local gun_default = { --safe default: "inventory_overlay_safe.png" (unimplemented firemode) safe = "inventory_overlay_safe.png" }, + --- `string` (optional) inventory image for when the gun has no magazine + inventory_image_magless = nil, + --- `string` inventory image for when the gun is loaded. This is added automatically during construction. + inventory_image = nil, + --[[part_slots = { + underbarrel = { + formspec_inventory_location = {x=0, y=1} + slots = 2, + rail = "picatinny" --only attachments fit for this type will be usable. + allowed = { + "group:guns4d_underbarrel" + }, + bone = "" --the bone both to attach to and to display at on the menu. + } + },]] }, - --- `table` a list of subclasses to create on construct and update. Note special fields `ammo_handler` and `part_handler`. + --- properties.subclasses -- -- @table gun.properties.subclsses -- @see lvl1_fields.properties|properties @@ -394,8 +400,15 @@ local gun_default = { fire = {x=0,y=0}, }, }, - --- a table of @{guns4d_soundspec|soundspecs} to be referenced by other functions + --- properties.sounds + -- + -- other fields are defined by other properties such as @{gun.properties.charging.draw_sound|properties.charging.draw_sound} and @{lvl1_fields.properties.reload|properties.reload} + -- @table gun.properties.sounds + -- @see lvl1_fields.properties|properties + -- @see guns4d_soundspec|soundspec + -- @compact sounds = { --this does not contain reload sound effects. + --- sound player when firing the weapon fire = { { __replace_old_table=true, diff --git a/docs/class/Gun.html b/docs/class/Gun.html index 695fa32..86cd328 100644 --- a/docs/class/Gun.html +++ b/docs/class/Gun.html @@ -6,7 +6,7 @@
gun
properties
properties.inventory
+properties.subclasses
+properties.ads
properties.hip
properties.firemodes
properties.firemode_inventory_overlays
-properties.recoil
properties.sway
@@ -49,12 +52,20 @@properties.visuals
properties.sounds
+offsets
consts
gun
¶
Gun class fields
+class fields
method documentation coming soon (or never...)
The appearance and handling of guns by default are defined by two table fields: their consts and their properties. @@ -92,6 +103,8 @@
Guns4d uses a class system for most moving parts- including the gun. New guns therefore are created with the :inherit(def) method, where def is the definition of your new gun- or rather the changed parts of it. So to make a new gun you can run Guns4d.gun:inherit() or you can do the same thing with a seperate class of weapons. Set name to "__template" for template classes of guns.
+for properties: for tables where you wish to delete the parent class's fields altogether (since inheritence prevents this) you can set the field "__replace_old_table=true" +additionally
Please note: there are likey undocumented fields that are used in internal functions. If you find one, please make an issue on Github.
table
indexed list of modifiers not set by the gun but to be applied to the gun. After changing, gun:update_modifiers() must be called to update it. Also may contain lists of modifiers.
table
indexed list of functions which are called when the gun's properties need to be built. This is used for things like attachments, etc.
a table of soundspecs to be referenced by other functions
+table
a list of ObjRefs that are attached to the gun as a result of attached_objects
table
list of subclass instances (i.e. Sprite_scope)
vector
containing the offset from animations, this will be generated if {@consts.ANIMATIONS_OFFSET_AIM}=true
vector
containing the rotation offset from the current frame, this will be factored into the gun's direction if {@consts.ANIMATIONS_OFFSET_AIM}=true
vector
containing the translational/positional offset from the current frame
Ammo_handler
the class (based on) ammo_handler to create an instance of and use. Default is Guns4d.ammo_handler
Part_handler
Part_handler class to use. Default is Guns4d.part_handler
Sprite_scope
sprite scope class to use
Dynamic_crosshair
crosshair class to use
starting vertical rotation of the gun
+float
starting vertical rotation of the gun
string
inventory image for when the gun has no magazine
string
inventory image for when the gun is loaded. This is added automatically during construction.
an ordered list of reloading states used by default_controls.
the default reload states for a magazine operated weapon, copied from the m4.
@@ -356,7 +354,7 @@a table {x1,y1,z1,x2,y2,z2} specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts. This is autogenerated if not present.
+table
(optional) a table {x1,y1,z1, x2,y2,z2}
specifying the bounding box of the model. The first 3 (x1,y1,z1) are the lower of their counterparts. This is autogenerated from the model when not present, reccomended that you leave nil.
offset¶ | -
| render_size¶ | +the size in meters to render the gun in it's inventory opened with /guns4d_inv |
horizontal_offset¶ | -
| render_image¶ | +the image of the gun in it's inventory opened with /guns4d_inv |
aim_time¶ | -the time it takes to go into full aim + | firemode_inventory_overlays¶ | +table of firemodes and their overlays in the player's inventory when the gun is on that firemode + |
+
inventory_image_magless¶ | +
|
+||
inventory_image¶ | +
|
offset¶ | -
| ammo_handler¶ | +
|
axis_rotation_ratio¶ | -the ratio that the look rotation is expressed through player_axial (rotated around the viewport) rotation as opposed to gun_axial (rotating the entity). + | part_handler¶ | +
|
sway_vel_mul¶ | -sway speed multiplier while at hip + | sprite_scope¶ | +
|
sway_angle_mul¶ | -sway angle multiplier while at hip + | crosshair¶ | +
|
list containing the firemodes of the gun. Default only contains "single". Strings allowed by default:
Defines the overlay on the gun item for each firemode. These are selected automatically by firemode string. Defaults are as follows:
single¶ | -singlefire default: "inventory_overlay_single.png" + | offset¶ | +
|
auto¶ | -automatic default: "inventory_overlay_auto.png" + | axis_rotation_ratio¶ | +the ratio that the look rotation is expressed through player_axial (rotated around the viewport) rotation as opposed to gun_axial (rotating the entity). |
burst¶ | -burstfire default: "inventory_overlay_burst.png" + | sway_vel_mul¶ | +sway speed multiplier while at hip |
safe¶ | -safe default: "inventory_overlay_safe.png" (unimplemented firemode) + | sway_angle_mul¶ | +sway angle multiplier while at hip |
list containing the firemodes of the gun. Default only contains "single". Strings allowed by default: +
string
name of the sound to play from sounds. Default "draw"
string
name of the sound to play from sounds. Default "draw"
objects that are attached to the gun. This is especially useful for attachments
+my_object = {
+ textures = {"blank.png"},
+ visual_size = {x=1,y=1,z=1},
+ offset = {x=0,y=0,z=0},
+ bone = "main",
+ backface_culling = false,
+ glow = 0
+}
+
+toggles backface culling. Default true
other fields are defined by other properties such as properties.charging.draw_sound and properties.reload +
fire¶ | +sound player when firing the weapon + |
+
string
="left_aimpoint", the bone which the left arm aims at to
table
version of 4dguns this gun is made for. If left empty it will be assumed it is before 1.3.
Gun
+¶
+Gun
+ +