wow_dbc 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5eb07f8d26336f262320b25aab7b855e1054a650e0ff608f938a7cd9075a3d1e
4
- data.tar.gz: fdb1049503d8ec18d1508fc6f0ec88510a6db8624432143430cf4f62453a75b0
3
+ metadata.gz: 2e4f7517b04352b878923798bcff55dc7bdfacb73b314fae1daf16bf3ede9574
4
+ data.tar.gz: 5cbbf02b3e37a9fdd1e8ad1a8c9b471ff73e6eb658cd7a38207e7e1f68386852
5
5
  SHA512:
6
- metadata.gz: b0db030d3fd74442621189f5bc02490b6431c0f05210e058a0a663f642df16b80c7b9a416d540431598117fd0c3cf706d89ce663f55b20b1b2b0535f97e562da
7
- data.tar.gz: d09f892af804f48e0cfe01077c1c30791a8fb3c761ed6e7f9cd7268b67680fc7c86c5bf48689c1200c5a3efdc1482b3d8307fa5e29e08e819b2504c81f77512b
6
+ metadata.gz: 98f2574fb77720fc4aed8655f9efdd3eea1116dfff9103be1628adb32961eaabcac13f652331083274dd8fe249e2015a5752efd4d87d01db89efc25c5d805338
7
+ data.tar.gz: f4865eac2f7d5c12b1d5c800651ced0a8983432f35a807b317a81cde7985565ad5c1a12de33a0d60116ba9eaf0f59931bc1cc8f1c9ffcc5da6551df429e460e8
data/README.md CHANGED
@@ -36,51 +36,62 @@ Here's a quick example of how to use WowDBC:
36
36
  ```ruby
37
37
  require 'wow_dbc'
38
38
 
39
- # Define field names for your DBC file
40
- field_names = [:id, :name, :description, :icon, :category, :subcategory]
39
+ # Correct field names for the Item.dbc file
40
+ field_names = [:id, :class, :subclass, :sound_override_subclass, :material, :displayid, :inventory_type, :sheath_type]
41
41
 
42
- # Open a DBC file
43
- dbc = WowDBC::DBCFile.new('path/to/your/file.dbc', field_names)
42
+ # Open the Item.dbc file
43
+ dbc = WowDBC::DBCFile.new('path/to/your/Item.dbc', field_names)
44
44
  dbc.read
45
45
 
46
- # Read a record
47
- record = dbc.get_record(0)
48
- puts "First record: #{record}"
49
-
50
- # Update a single field in a record
51
- dbc.update_record(0, :name, "New Name")
52
-
53
- # Update multiple fields in a record
54
- dbc.update_record_multi(0, { name: "Newer Name", category: 5, subcategory: 10 })
55
-
56
- # Create a new empty record
57
- new_record_index = dbc.create_record
58
- puts "New empty record index: #{new_record_index}"
59
-
60
- # Create a new record with initial values
61
- initial_values = { id: 1000, name: "New Item", category: 3, subcategory: 7 }
62
- new_record_with_values_index = dbc.create_record_with_values(initial_values)
63
- puts "New record with values index: #{new_record_with_values_index}"
64
-
65
- # Read the newly created record
66
- new_record = dbc.get_record(new_record_with_values_index)
67
- puts "Newly created record: #{new_record}"
68
-
69
- # Delete a record
70
- dbc.delete_record(new_record_index)
46
+ # Find a specific item (e.g., Warglaive of Azzinoth, ID: 32837)
47
+ warglaive = dbc.find_by(:id, 32837).first
48
+ puts "Warglaive of Azzinoth: #{warglaive}"
49
+
50
+ # Update a single field of the Warglaive
51
+ dbc.update_record(warglaive[:id], :sheath_type, 3) # Assuming 3 represents a different sheath type
52
+
53
+ # Update multiple fields of the Warglaive
54
+ dbc.update_record_multi(warglaive[:id], { material: 5, inventory_type: 17 }) # Assuming 5 is a different material and 17 is Two-Hand
55
+
56
+ # Create a new empty item record
57
+ new_item_index = dbc.create_record
58
+ puts "New empty item index: #{new_item_index}"
59
+
60
+ # Create a new item record with initial values
61
+ initial_values = {
62
+ id: 99999,
63
+ class: 2, # Weapon
64
+ subclass: 7, # Warglaives
65
+ sound_override_subclass: -1, # No override
66
+ material: warglaive[:material],
67
+ displayid: warglaive[:displayid],
68
+ inventory_type: 17, # Two-Hand
69
+ sheath_type: 3
70
+ }
71
+ new_item_index = dbc.create_record_with_values(initial_values)
72
+ puts "New custom item index: #{new_item_index}"
73
+
74
+ # Read the newly created item
75
+ new_item = dbc.get_record(new_item_index)
76
+ puts "Newly created item: #{new_item}"
77
+
78
+ # Delete an item (be careful with this!)
79
+ # dbc.delete_record(new_item_index)
71
80
 
72
81
  # Write changes back to the file
73
82
  dbc.write
74
83
 
75
84
  # Reading header information
76
85
  header = dbc.header
77
- puts "Total records: #{header[:record_count]}"
78
- puts "Fields per record: #{header[:field_count]}"
86
+ puts "Total items: #{header[:record_count]}"
87
+ puts "Fields per item: #{header[:field_count]}"
88
+
89
+ # Finding all two-handed weapons
90
+ two_handed_weapons = dbc.find_by(:inventory_type, 17) # 17 represents Two-Hand weapons
79
91
 
80
- # Iterating through all records
81
- (0...header[:record_count]).each do |i|
82
- record = dbc.get_record(i)
83
- puts "Record #{i}: #{record}"
92
+ puts "Two-handed weapons:"
93
+ two_handed_weapons.each do |item|
94
+ puts "Item ID: #{item[:id]}, Class: #{item[:class]}, Subclass: #{item[:subclass]}, Display ID: #{item[:displayid]}"
84
95
  end
85
96
  ```
86
97
 
@@ -310,6 +310,40 @@ static VALUE dbc_update_record_multi(VALUE self, VALUE index, VALUE updates) {
310
310
  return Qnil;
311
311
  }
312
312
 
313
+ static VALUE dbc_find_by(VALUE self, VALUE field, VALUE value) {
314
+ DBCFile *dbc;
315
+ TypedData_Get_Struct(self, DBCFile, &dbc_data_type, dbc);
316
+
317
+ long field_idx = -1;
318
+
319
+ // Find the index of the field name
320
+ for (long i = 0; i < RARRAY_LEN(dbc->field_names); i++) {
321
+ if (rb_eql(rb_ary_entry(dbc->field_names, i), field)) {
322
+ field_idx = i;
323
+ break;
324
+ }
325
+ }
326
+
327
+ if (field_idx < 0 || (uint32_t)field_idx >= dbc->header.field_count) {
328
+ rb_raise(rb_eArgError, "Invalid field name");
329
+ }
330
+
331
+ VALUE result = rb_ary_new();
332
+
333
+ for (uint32_t i = 0; i < dbc->header.record_count; i++) {
334
+ if (dbc->records[i][field_idx] == NUM2UINT(value)) {
335
+ VALUE record = rb_hash_new();
336
+ for (uint32_t j = 0; j < dbc->header.field_count; j++) {
337
+ VALUE field_name = rb_ary_entry(dbc->field_names, j);
338
+ rb_hash_aset(record, field_name, UINT2NUM(dbc->records[i][j]));
339
+ }
340
+ rb_ary_push(result, record);
341
+ }
342
+ }
343
+
344
+ return result;
345
+ }
346
+
313
347
  void Init_wow_dbc(void) {
314
348
  rb_mWowDBC = rb_define_module("WowDBC");
315
349
  rb_cDBCFile = rb_define_class_under(rb_mWowDBC, "DBCFile", rb_cObject);
@@ -324,4 +358,5 @@ void Init_wow_dbc(void) {
324
358
  rb_define_method(rb_cDBCFile, "delete_record", dbc_delete_record, 1);
325
359
  rb_define_method(rb_cDBCFile, "get_record", dbc_get_record, 1);
326
360
  rb_define_method(rb_cDBCFile, "header", dbc_get_header, 0);
361
+ rb_define_method(rb_cDBCFile, "find_by", dbc_find_by, 2);
327
362
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WowDBC
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wow_dbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sebi