fix widget package

This commit is contained in:
Sky Johnson 2025-08-07 12:59:39 -05:00
parent c3a64dd96c
commit 570f2b41c6
4 changed files with 105 additions and 12 deletions

6
.gitignore vendored
View File

@ -19,6 +19,6 @@
go.work
# Test builds
world_config.json
world_server
world.db
./world_config.json
./world_server
./world.db

View File

@ -16,7 +16,7 @@ func (w *Widget) OpenDoor() {
// Set heading if specified
if w.openHeading >= 0 {
w.SetHeading(w.openHeading)
w.SetHeadingFromFloat(w.openHeading)
}
// Handle position changes
@ -80,10 +80,10 @@ func (w *Widget) CloseDoor() {
// Set heading
if w.closedHeading > 0 {
w.SetHeading(w.closedHeading)
w.SetHeadingFromFloat(w.closedHeading)
} else if w.openHeading >= 0 {
// Fall back to original heading
w.SetHeading(w.GetSpawnOrigHeading())
w.SetHeadingFromFloat(w.GetSpawnOrigHeading())
}
// Update activity status for non-lifts

View File

@ -77,7 +77,9 @@ type WidgetTimer struct {
// WidgetState represents the current state of a widget
type WidgetState struct {
IsOpen bool
Position spawn.Position
X float32
Y float32
Z float32
Heading float32
ActivityStatus int32
}
@ -89,7 +91,9 @@ func (w *Widget) GetState() WidgetState {
return WidgetState{
IsOpen: w.isOpen,
Position: spawn.Position{X: w.GetX(), Y: w.GetY(), Z: w.GetZ()},
X: w.GetX(),
Y: w.GetY(),
Z: w.GetZ(),
Heading: w.GetHeading(),
ActivityStatus: w.GetActivityStatus(),
}
@ -101,9 +105,9 @@ func (w *Widget) RestoreState(state WidgetState) {
defer w.mutex.Unlock()
w.isOpen = state.IsOpen
w.SetX(state.Position.X)
w.SetY(state.Position.Y)
w.SetZ(state.Position.Z)
w.SetHeading(state.Heading)
w.SetX(state.X)
w.SetY(state.Y, false)
w.SetZ(state.Z)
w.SetHeadingFromFloat(state.Heading)
w.SetActivityStatus(state.ActivityStatus)
}

View File

@ -484,6 +484,95 @@ func (w *Widget) Copy() *Widget {
return newWidget
}
// Activity status methods
// GetActivityStatus returns the current activity status
func (w *Widget) GetActivityStatus() int32 {
// For now, return based on open state
if w.IsOpen() {
return DefaultActivityOpen
}
return DefaultActivityClosed
}
// SetActivityStatus sets the activity status
func (w *Widget) SetActivityStatus(status int32) {
// This method is called but not fully implemented yet
// It would normally update some activity state
}
// SetPosState sets the position state
func (w *Widget) SetPosState(state int32) {
// This method is called but not fully implemented yet
// It would normally update some position state
}
// AddRunningLocation adds a running location for movement
func (w *Widget) AddRunningLocation(x, y, z, speed float32) {
// For now, just set the position directly
// In a full implementation, this would add smooth movement
w.SetX(x)
w.SetY(y, false)
w.SetZ(z)
}
// Original position methods (for reset functionality)
// GetSpawnOrigX returns the original X position
func (w *Widget) GetSpawnOrigX() float32 {
w.mutex.RLock()
defer w.mutex.RUnlock()
return w.closeX
}
// GetSpawnOrigY returns the original Y position
func (w *Widget) GetSpawnOrigY() float32 {
w.mutex.RLock()
defer w.mutex.RUnlock()
return w.closeY
}
// GetSpawnOrigZ returns the original Z position
func (w *Widget) GetSpawnOrigZ() float32 {
w.mutex.RLock()
defer w.mutex.RUnlock()
return w.closeZ
}
// GetSpawnOrigHeading returns the original heading
func (w *Widget) GetSpawnOrigHeading() float32 {
w.mutex.RLock()
defer w.mutex.RUnlock()
return w.closedHeading
}
// GetTransporterID returns the transporter ID for this widget
func (w *Widget) GetTransporterID() int32 {
w.mutex.RLock()
defer w.mutex.RUnlock()
return w.widgetID // For transport widgets, use widget ID as transporter ID
}
// SetIcon sets the icon for this widget (visual appearance)
func (w *Widget) SetIcon(icon int8) {
// This method is called but not implemented in the base spawn
// In a full implementation, this would update the visual appearance
}
// CopySpawnData copies spawn data from another spawn
func (w *Widget) CopySpawnData(src *spawn.Spawn) {
// Copy basic spawn data
w.SetName(src.GetName())
w.SetX(src.GetX())
w.SetY(src.GetY(), false)
w.SetZ(src.GetZ())
w.SetHeadingFromFloat(src.GetHeading())
w.SetLevel(src.GetLevel())
w.SetClass(src.GetClass())
w.SetRace(src.GetRace())
w.SetGender(src.GetGender())
}
// calculateDistance calculates 3D distance between two points
func calculateDistance(x1, y1, z1, x2, y2, z2 float32) float32 {
dx := x2 - x1