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 +4 -4
- data/README.md +46 -35
- data/ext/wow_dbc/wow_dbc.c +35 -0
- data/lib/wow_dbc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e4f7517b04352b878923798bcff55dc7bdfacb73b314fae1daf16bf3ede9574
|
4
|
+
data.tar.gz: 5cbbf02b3e37a9fdd1e8ad1a8c9b471ff73e6eb658cd7a38207e7e1f68386852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
#
|
40
|
-
field_names = [:id, :
|
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
|
43
|
-
dbc = WowDBC::DBCFile.new('path/to/your/
|
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
|
-
#
|
47
|
-
|
48
|
-
puts "
|
49
|
-
|
50
|
-
# Update a single field
|
51
|
-
dbc.update_record(
|
52
|
-
|
53
|
-
# Update multiple fields
|
54
|
-
dbc.update_record_multi(
|
55
|
-
|
56
|
-
# Create a new empty record
|
57
|
-
|
58
|
-
puts "New empty
|
59
|
-
|
60
|
-
# Create a new record with initial values
|
61
|
-
initial_values = {
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
78
|
-
puts "Fields per
|
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
|
-
|
81
|
-
|
82
|
-
|
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
|
|
data/ext/wow_dbc/wow_dbc.c
CHANGED
@@ -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
|
}
|
data/lib/wow_dbc/version.rb
CHANGED