Skip to content

Commit

Permalink
ns4: Add data stores, cursor, player events.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Feb 3, 2024
1 parent 31d35f3 commit 0b693c9
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 1 deletion.
65 changes: 65 additions & 0 deletions ns/v4/eval/github_com-noxworld-dev-noxscript-ns-v4.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions ns/v4/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ type Obj interface {
Z() float32
// SetZ sets Z offset for the object.
SetZ(z float32)
// Vel returns current velocity of the object.
Vel() Pointf
// IsEnabled checks if object is currently enabled.
IsEnabled() bool
// Enable or disable the object.
Expand Down Expand Up @@ -270,6 +272,12 @@ type Obj interface {
// See LookWithAngle.
Direction() Direction

// CursorPos returns aim cursor position for the object. Only valid for players.
CursorPos() types.Pointf

// CursorObj returns target under the aim cursor for the object. Only valid for players.
CursorObj() Obj

// CurrentHealth gets object's health.
CurrentHealth() int

Expand Down
13 changes: 12 additions & 1 deletion ns/v4/player.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package ns

import "github.com/noxworld-dev/opennox-lib/player"
import (
"github.com/noxworld-dev/opennox-lib/player"
"github.com/noxworld-dev/opennox-lib/types"
)

type PlayerDeathFunc func(p Player, killer Obj)
type PlayerJoinFunc func(p Player) bool
type PlayerLeaveFunc func(p Player)

type Player interface {
// Name returns player's name.
Expand All @@ -23,6 +30,10 @@ type Player interface {
HasTeam(t Team) bool
// Team returns current team of a player, if any.
Team() Team
// CursorPos returns aim cursor position for the player.
CursorPos() types.Pointf
// Store returns a player storage with a given type.
Store(typ StorageType) Storage
}

// GetHost gets host's player object.
Expand Down
4 changes: 4 additions & 0 deletions ns/v4/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Game interface {
type Implementation interface {
TimeSource
FrameRate() int
Store(typ StorageType) Storage

TimerByHandle(h TimerHandle) Timer
NewTimer(dt Duration, fnc Func, args ...any) Timer
Expand Down Expand Up @@ -146,6 +147,9 @@ type Implementation interface {
OnFrame(fnc FrameFunc)
OnMapEvent(typ MapEvent, fnc MapEventFunc)
OnChat(fnc ChatFunc)
OnPlayerJoin(fnc PlayerJoinFunc)
OnPlayerLeave(fnc PlayerLeaveFunc)
OnPlayerDeath(fnc PlayerDeathFunc)

Unused1f(id int)
Unused20(id int)
Expand Down
35 changes: 35 additions & 0 deletions ns/v4/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ns

type StorageType interface {
isStorageType()
}

// Session is a game session storage with a given name. It will persist as long as a single game session runs.
type Session struct {
Name string
}

func (Session) isStorageType() {}

// Persistent returns a persistent storage with a given name. It will persist between OpenNox restarts.
type Persistent struct {
Name string
}

func (Persistent) isStorageType() {}

// Store returns a global storage with a given type.
func Store(typ StorageType) Storage {
if impl == nil {
return nil
}
return impl.Store(typ)
}

type Storage interface {
// Get fetches a custom object or value from the storage with a given key.
// Argument must be a pointer to a value of the same type as used during Set.
Get(key string, obj any) error
// Set stores a custom object or value into the storage with a given key.
Set(key string, obj any) error
}

0 comments on commit 0b693c9

Please sign in to comment.