using System;
namespace ClassicalSharp {
public sealed class Events {
/// Raised when an entity is spawned in the current world.
public event EventHandler EntityAdded;
internal void RaiseEntityAdded( byte id ) { idArgs.Id = id; Raise( EntityAdded, idArgs ); }
/// Raised when an entity is despawned from the current world.
public event EventHandler EntityRemoved;
internal void RaiseEntityRemoved( byte id ) { idArgs.Id = id; Raise( EntityRemoved, idArgs ); }
/// Raised when a new CPE player list entry is created.
public event EventHandler CpeListInfoAdded;
internal void RaiseCpeListInfoAdded( byte id ) { idArgs.Id = id; Raise( CpeListInfoAdded, idArgs ); }
/// Raised when a CPE player list entry is modified.
public event EventHandler CpeListInfoChanged;
internal void RaiseCpeListInfoChanged( byte id ) { idArgs.Id = id; Raise( CpeListInfoChanged, idArgs ); }
/// Raised when a CPE player list entry is removed.
public event EventHandler CpeListInfoRemoved;
internal void RaiseCpeListInfoRemoved( byte id ) { idArgs.Id = id; Raise( CpeListInfoRemoved, idArgs ); }
/// Raised when the client joins and begins loading a new map.
public event EventHandler OnNewMap;
internal void RaiseOnNewMap() { Raise( OnNewMap ); }
/// Raised when a portion of the map is read and decompressed by the client.
public event EventHandler MapLoading;
internal void RaiseMapLoading( byte progress ) { loadingArgs.Progress = progress; Raise( MapLoading, loadingArgs ); }
/// Raised when the client has finished loading a new map and can now interact with it.
public event EventHandler OnNewMapLoaded;
internal void RaiseOnNewMapLoaded() { Raise( OnNewMapLoaded ); }
/// Raised when the terrain atlas ("terrain.png") is changed.
public event EventHandler TerrainAtlasChanged;
internal void RaiseTerrainAtlasChanged() { Raise( TerrainAtlasChanged ); }
/// Raised when an environment variable is changed by the user, CPE, or WoM config.
public event EventHandler EnvVariableChanged;
internal void RaiseEnvVariableChanged( EnvVar envVar ) { envArgs.Var = envVar; Raise( EnvVariableChanged, envArgs ); }
/// Raised when the user changed their view/fog distance.
public event EventHandler ViewDistanceChanged;
internal void RaiseViewDistanceChanged() { Raise( ViewDistanceChanged ); }
/// Raised when the held block is changed by the user or by CPE.
public event EventHandler HeldBlockChanged;
internal void RaiseHeldBlockChanged() { Raise( HeldBlockChanged ); }
/// Raised when the client's block permissions(can place or delete a block) change.
public event EventHandler BlockPermissionsChanged;
internal void RaiseBlockPermissionsChanged() { Raise( BlockPermissionsChanged ); }
/// Raised when the a block definition is changed.
public event EventHandler BlockDefinitionChanged;
internal void RaiseBlockDefinitionChanged() { Raise( BlockDefinitionChanged ); }
/// Raised when the server or a client-side command sends a message.
public event EventHandler ChatReceived;
internal void RaiseChatReceived( string text, CpeMessage type ) { chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); }
/// Raised when the user changes chat font to arial or back to bitmapped font,
/// also raised when the bitmapped font changes.
public event EventHandler ChatFontChanged;
internal void RaiseChatFontChanged() { Raise( ChatFontChanged ); }
// Cache event instances so we don't create needless new objects.
IdEventArgs idArgs = new IdEventArgs();
MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs();
EnvVarEventArgs envArgs = new EnvVarEventArgs();
ChatEventArgs chatArgs = new ChatEventArgs();
void Raise( EventHandler handler ) {
if( handler != null ) {
handler( this, EventArgs.Empty );
}
}
void Raise( EventHandler handler, T args ) where T : EventArgs {
if( handler != null ) {
handler( this, args );
}
}
}
public sealed class IdEventArgs : EventArgs {
public byte Id;
}
public sealed class ChatEventArgs : EventArgs {
/// Where this chat message should appear on the screen.
public CpeMessage Type;
/// Raw text of the message (including colour codes),
/// with code page 437 indices converted to their unicode representations.
public string Text;
}
public sealed class MapLoadingEventArgs : EventArgs {
/// Percentage of the map that has been fully decompressed by the client.
public int Progress;
}
public sealed class EnvVarEventArgs : EventArgs {
/// Map environment variable that was changed.
public EnvVar Var;
}
public enum EnvVar {
SidesBlock,
EdgeBlock,
EdgeLevel,
CloudsLevel,
Weather,
SkyColour,
CloudsColour,
FogColour,
SunlightColour,
ShadowlightColour,
}
public enum Weather {
Sunny,
Rainy,
Snowy,
}
}