Skip to content

Commit 1cd9653

Browse files
committed
sendtables: make property type public via Property.Type()
1 parent 5b974d7 commit 1cd9653

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

pkg/demoinfocs/sendtables/entity.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,16 @@ func (pe *property) Name() string {
314314
return pe.entry.name
315315
}
316316

317-
// Value returns current value of the property.
317+
// Value returns the current value of the property.
318318
func (pe *property) Value() PropertyValue {
319319
return pe.value
320320
}
321321

322+
// Type returns the data type of the property.
323+
func (pe *property) Type() PropertyType {
324+
return PropertyType(pe.entry.prop.rawType)
325+
}
326+
322327
// PropertyValueType specifies the type of a PropertyValue
323328
type PropertyValueType int
324329

pkg/demoinfocs/sendtables/entity_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ func TestProperty_Name(t *testing.T) {
6868

6969
assert.Equal(t, "test", prop.Name())
7070
}
71+
72+
func TestProperty_Type(t *testing.T) {
73+
prop := property{entry: &flattenedPropEntry{prop: &sendTableProperty{rawType: 1}}}
74+
75+
assert.Equal(t, PropTypeFloat, prop.Type())
76+
}

pkg/demoinfocs/sendtables/fake/property.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ func (p *Property) Value() st.PropertyValue {
2323
return p.Called().Get(0).(st.PropertyValue)
2424
}
2525

26+
// Type is a mock-implementation of Property.Type().
27+
func (p *Property) Type() st.PropertyType {
28+
return p.Called().Get(0).(st.PropertyType)
29+
}
30+
2631
// OnUpdate is a mock-implementation of Property.OnUpdate().
2732
func (p *Property) OnUpdate(handler st.PropertyUpdateHandler) {
2833
p.Called(handler)

pkg/demoinfocs/sendtables/propdecoder.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ const (
2121
propTypeInt64
2222
)
2323

24+
// PropertyType identifies the data type of a property.
25+
type PropertyType int
26+
27+
// PropType constants are duplicated as publics so we don't have to convert ints to PropertyType for normal use.
28+
29+
const (
30+
PropTypeInt PropertyType = iota
31+
PropTypeFloat
32+
PropTypeVector
33+
PropTypeVectorXY
34+
PropTypeString
35+
PropTypeArray
36+
PropTypeDataTable
37+
PropTypeInt64
38+
)
39+
2440
const (
2541
coordFractionalBitsMp = 5
2642
coordFractionalBitsMpLowPrecision = 3

pkg/demoinfocs/sendtables/property_interface.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ package sendtables
88
type Property interface {
99
// Name returns the property's name.
1010
Name() string
11-
// Value returns current value of the property.
11+
// Value returns the current value of the property.
1212
Value() PropertyValue
13+
// Type returns the data type of the property.
14+
Type() PropertyType
1315
// OnUpdate registers a handler for updates of the property's value.
1416
//
1517
// The handler will be called with the current value upon registration.

0 commit comments

Comments
 (0)