Files
UnityUDP/lib/models/project.dart
2025-10-15 15:22:51 +02:00

65 lines
1.6 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
import 'udp_package.dart';
part 'project.g.dart';
@JsonSerializable()
class Project {
final String id;
final String name;
// Support for multiple IP addresses at project level
final List<String> ipAddresses;
// Broadcast mode flag for project
@JsonKey(defaultValue: false)
final bool isBroadcast;
final int port;
final List<UdpPackage> packages;
// Legacy field for backward compatibility
@JsonKey(includeFromJson: true, includeToJson: false)
final String? ipAddress;
Project({
required this.id,
required this.name,
List<String>? ipAddresses,
this.isBroadcast = false,
required this.port,
required this.packages,
this.ipAddress,
}) : ipAddresses = ipAddresses ?? (ipAddress != null ? [ipAddress] : ['127.0.0.1']);
factory Project.fromJson(Map<String, dynamic> json) {
// Handle migration from old format
if (json.containsKey('ipAddress') && !json.containsKey('ipAddresses')) {
json['ipAddresses'] = [json['ipAddress']];
}
return _$ProjectFromJson(json);
}
Map<String, dynamic> toJson() => _$ProjectToJson(this);
Project copyWith({
String? id,
String? name,
List<String>? ipAddresses,
bool? isBroadcast,
int? port,
List<UdpPackage>? packages,
}) {
return Project(
id: id ?? this.id,
name: name ?? this.name,
ipAddresses: ipAddresses ?? this.ipAddresses,
isBroadcast: isBroadcast ?? this.isBroadcast,
port: port ?? this.port,
packages: packages ?? this.packages,
);
}
}