more mod restructuring
This commit is contained in:
parent
ae94151fb6
commit
f97b0a6562
9 changed files with 34 additions and 35 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import {Serdes} from "../events/serdes";
|
||||
import {Converters} from "../events/converters";
|
||||
|
||||
export function convertPrototypes (): FactorioPrototype[] {
|
||||
let prototypes = new Array<FactorioPrototype>()
|
||||
|
|
@ -19,7 +19,7 @@ function getMapTilePrototypes(): FactorioMapTilePrototype[] {
|
|||
order: tile.order,
|
||||
layer: tile.layer,
|
||||
collisionMasks: convertCollisionMaskToNames(tile.collision_mask),
|
||||
mapColor: Serdes.mapColour(tile.map_color),
|
||||
mapColor: Converters.mapColour(tile.map_color),
|
||||
canBeMined: tile.mineable_properties.minable,
|
||||
}
|
||||
)
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
import {emitPacket} from "../emitKafkatorioPacket";
|
||||
import {convertPrototypes} from "../../prototypes/emitPrototypes";
|
||||
import {convertPrototypes} from "./convertPrototypes";
|
||||
import {updateGlobal} from "./updateGlobal";
|
||||
|
||||
export function handleConfigurationUpdate(changeData: ConfigurationChangedData) {
|
||||
updateGlobal()
|
||||
|
||||
emitPacket<FactorioConfigurationUpdate>({
|
||||
modVersion: global.MOD_VERSION,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export namespace Serdes {
|
||||
export namespace Converters {
|
||||
|
||||
export function playerToTable(player: LuaPlayer): PlayerData {
|
||||
let charIds = entitiesToUnitNumbers(player.get_associated_characters())
|
||||
|
|
@ -37,7 +37,7 @@ export namespace Serdes {
|
|||
}
|
||||
}
|
||||
|
||||
export function entitiesToUnitNumbers(entities: LuaEntity[]): uint[] {
|
||||
function entitiesToUnitNumbers(entities: LuaEntity[]): uint[] {
|
||||
let result: (uint) [] = []
|
||||
for (let entity of entities) {
|
||||
if (entity.unit_number != null) {
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
// const SERVER_ID: uint = 0
|
||||
// const EVENT_FILE_DIR: string = "events"
|
||||
|
||||
import {emitPacket} from "../emitKafkatorioPacket";
|
||||
|
||||
/** Emit a serialised event */
|
||||
export function emitEvent<T extends FactorioObjectData>(eventData: T, tick: uint, eventType: string) {
|
||||
emitPacket({
|
||||
data: eventData,
|
||||
eventType: eventType,
|
||||
modVersion: global.MOD_VERSION,
|
||||
tick: tick
|
||||
})
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
export const MOD_VERSION = script.active_mods["@mod.name@"] ?? "UNKNOWN"
|
||||
export const FACTORIO_VERSION = script.active_mods["base"] ?? "UNKNOWN"
|
||||
|
||||
// const SERVER_ID: uint = 0
|
||||
// const EVENT_FILE_DIR: string = "events"
|
||||
|
||||
/** Emit a serialised event */
|
||||
export function emitEvent<T extends FactorioObjectData>(eventData: T, tick: uint, eventType: string) {
|
||||
|
||||
let event: FactorioEvent<T> = {
|
||||
data: eventData,
|
||||
eventType: eventType,
|
||||
modVersion: MOD_VERSION,
|
||||
tick: tick
|
||||
}
|
||||
|
||||
let data = game.table_to_json(event)
|
||||
|
||||
localised_print(`FactorioEvent: ${data}`)
|
||||
}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
import {Serdes} from "./serdes"
|
||||
import {emitEvent} from "./emitter";
|
||||
import {Converters} from "./converters"
|
||||
import {emitEvent} from "./emitEvent";
|
||||
|
||||
export function handlePlayerUpdate(tick: uint, playerIndex: uint, eventType: string) {
|
||||
let player: LuaPlayer = game.players[playerIndex]
|
||||
let table = Serdes.playerToTable(player)
|
||||
let table = Converters.playerToTable(player)
|
||||
|
||||
|
||||
emitEvent(table, tick, eventType)
|
||||
|
||||
handleCharactersEvent(tick, playerIndex, eventType)
|
||||
|
|
@ -24,7 +26,7 @@ export function handleCharactersEvent(tick: uint, playerIndex: uint, eventType:
|
|||
}
|
||||
|
||||
export function handleEntityUpdate(tick: uint, entity: LuaEntity, eventType: string) {
|
||||
let table = Serdes.entityToTable(entity)
|
||||
let table = Converters.entityToTable(entity)
|
||||
emitEvent(table, tick, eventType)
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +35,7 @@ export function handleSurfaceUpdate(
|
|||
surface: LuaSurface,
|
||||
eventType: string
|
||||
) {
|
||||
let table = Serdes.surfaceToTable(surface)
|
||||
let table = Converters.surfaceToTable(surface)
|
||||
emitEvent(table, tick, eventType)
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +46,7 @@ export function handleConsoleChat(
|
|||
message: string,
|
||||
eventType: string,
|
||||
) {
|
||||
let table = Serdes.consoleChat(message, playerIndex)
|
||||
let table = Converters.consoleChat(message, playerIndex)
|
||||
emitEvent(table, tick, eventType)
|
||||
}
|
||||
|
||||
|
|
@ -71,8 +73,8 @@ export function handleChunkUpdate(
|
|||
|
||||
let tilePositionMap = new Map<PositionData, FactorioTile>();
|
||||
for (let tile of tiles) {
|
||||
let position = Serdes.convertMapPosition(tile.position)
|
||||
tilePositionMap.set(position, Serdes.convertTile(tile))
|
||||
let position = Converters.convertMapPosition(tile.position)
|
||||
tilePositionMap.set(position, Converters.convertTile(tile))
|
||||
}
|
||||
let mapChunk: FactorioTilesMap = {
|
||||
objectName: "FactorioTilesMap",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import {
|
|||
handleEntityUpdate,
|
||||
handlePlayerUpdate,
|
||||
handleSurfaceUpdate
|
||||
} from "./events/handlers";
|
||||
} from "./handlers";
|
||||
|
||||
const mapEventIdToName = new LuaTable<defines.Events, keyof typeof defines.events>()
|
||||
for (const [k, v] of pairs(defines.events)) {
|
||||
|
|
@ -27,6 +27,7 @@ data class Colour(
|
|||
val blue: Float = 0f,
|
||||
val alpha: Float = 1f,
|
||||
) {
|
||||
|
||||
/** True if any value is greater than 1, so the values are hexadecimal. */
|
||||
fun isDecimal(): Boolean {
|
||||
return red > 1f
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable
|
|||
data class FactorioEvent<out T : FactorioObjectData>(
|
||||
override val modVersion: String,
|
||||
|
||||
/** the initial Factorio event ({defines.events}) trigger */
|
||||
/** the initial Factorio event (`defines.events`) trigger */
|
||||
val eventType: String,
|
||||
/** game time */
|
||||
val tick: UInt,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue