Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/const/placed_classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ class TextContentAction extends WidgetAction {

@JsonSerializable()
class PlacedUtility extends PlacedWidget {
@UtilityTypeCompatConverter()
final UtilityType type;

double rotation = 0;
Expand All @@ -1011,7 +1012,10 @@ class PlacedUtility extends PlacedWidget {
return UtilityData.isViewCone(type);
}

Offset _getEffectiveUtilitySize({required double mapScale}) {
Offset _getEffectiveUtilitySize({
required double mapScale,
required double abilitySize,
}) {
final utility = UtilityData.utilityWidgets[type]!;
if (type == UtilityType.customCircle) {
assert(customDiameter != null,
Expand All @@ -1034,13 +1038,17 @@ class PlacedUtility extends PlacedWidget {
mapScale: mapScale,
);
}
return utility.getSize();
return utility.getSize(abilitySize: abilitySize);
}

void switchSides({
required double mapScale,
required double abilitySize,
}) {
final size = _getEffectiveUtilitySize(mapScale: mapScale);
final size = _getEffectiveUtilitySize(
mapScale: mapScale,
abilitySize: abilitySize,
);
final scaledSize = size.scale(CoordinateSystem.instance.scaleFactor,
CoordinateSystem.instance.scaleFactor);
final flippedPosition = getFlippedPosition(
Expand Down Expand Up @@ -1232,10 +1240,14 @@ class PlacedUtility extends PlacedWidget {
@JsonKey(defaultValue: null)
int? customOpacityPercent;
Comment thread
SunkenInTime marked this conversation as resolved.

@JsonKey(defaultValue: true)
final bool isAlly;

PlacedUtility({
required this.type,
required super.position,
required super.id,
this.isAlly = true,
this.angle = 0.0,
this.customDiameter,
this.customWidth,
Expand Down Expand Up @@ -1263,12 +1275,14 @@ class PlacedUtility extends PlacedWidget {
Object? customOpacityPercent = _noChange,
double? rotation,
double? length,
bool? isAlly,
bool? isDeleted,
}) {
final copied = PlacedUtility(
type: type ?? this.type,
position: position ?? this.position,
id: id ?? this.id,
isAlly: isAlly ?? this.isAlly,
angle: angle ?? this.angle,
customDiameter: identical(customDiameter, _noChange)
? this.customDiameter
Expand Down
15 changes: 4 additions & 11 deletions lib/const/placed_classes.g.dart

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

133 changes: 133 additions & 0 deletions lib/const/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:icarus/const/agents.dart';
import 'package:icarus/widgets/draggable_widgets/utilities/custom_circle_utility_widget.dart';
import 'package:icarus/widgets/draggable_widgets/utilities/custom_rectangle_utility_widget.dart';
import 'package:icarus/widgets/draggable_widgets/utilities/image_utility_widget.dart';
import 'package:icarus/widgets/draggable_widgets/utilities/role_icon_utility_widget.dart';
import 'package:icarus/widgets/draggable_widgets/utilities/view_cone_widget.dart';

enum UtilityType {
Expand All @@ -12,6 +13,10 @@ enum UtilityType {
viewCone40,
customCircle,
customRectangle,
controller,
duelist,
initiator,
sentinel,
}

class UtilityData {
Expand All @@ -26,6 +31,18 @@ class UtilityData {
UtilityType.viewCone40: ViewConeUtility(angle: 20, defaultLength: 50),
UtilityType.customCircle: CustomCircleUtility(),
UtilityType.customRectangle: CustomRectangleUtility(),
UtilityType.controller: RoleIconUtility(
imagePath: 'assets/agents/controller.webp',
),
UtilityType.duelist: RoleIconUtility(
imagePath: 'assets/agents/duelist.webp',
),
UtilityType.initiator: RoleIconUtility(
imagePath: 'assets/agents/initiator.webp',
),
UtilityType.sentinel: RoleIconUtility(
imagePath: 'assets/agents/sentinel.webp',
),
};

/// Helper to check if a utility type is a view cone
Expand Down Expand Up @@ -56,6 +73,13 @@ class UtilityData {
type == UtilityType.customRectangle;
}

static bool isRoleIcon(UtilityType type) {
return type == UtilityType.controller ||
type == UtilityType.duelist ||
type == UtilityType.initiator ||
type == UtilityType.sentinel;
}

static bool isAgentAttachable(UtilityType type) {
return isViewCone(type) || type == UtilityType.customCircle;
}
Expand Down Expand Up @@ -191,6 +215,38 @@ class CustomShapeToolData implements DraggableData {
}
}

class RoleIconToolData implements DraggableData {
final UtilityType type;
final Offset centerPoint;

const RoleIconToolData({
required this.type,
required this.centerPoint,
});

factory RoleIconToolData.fromType({
required UtilityType type,
required double abilitySize,
}) {
return RoleIconToolData(
type: type,
centerPoint: UtilityData.utilityWidgets[type]!.getAnchorPoint(
abilitySize: abilitySize,
),
);
}

Offset getScaledCenterPoint({
required double scaleFactor,
required double screenZoom,
}) {
return centerPoint.scale(
scaleFactor * screenZoom,
scaleFactor * screenZoom,
);
}
}

class TextToolData implements DraggableData {
final Offset centerPoint;
final double width;
Expand Down Expand Up @@ -230,15 +286,18 @@ sealed class Utilities {
double? length,
double? rotation,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters});

Widget createWidget(
{String? id,
bool isAlly = true,
double? rotation,
double? length,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
Expand All @@ -249,6 +308,7 @@ sealed class Utilities {
{double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
double? abilitySize,
double? mapScale});
}

Expand All @@ -261,9 +321,11 @@ class ImageUtility extends Utilities {
@override
Widget createWidget(
{String? id,
bool isAlly = true,
double? rotation,
double? length,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
Expand All @@ -279,6 +341,7 @@ class ImageUtility extends Utilities {
double? length,
double? rotation,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters}) {
Expand All @@ -290,6 +353,7 @@ class ImageUtility extends Utilities {
{double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
double? abilitySize,
double? mapScale}) {
return Offset(size, size);
}
Expand All @@ -312,9 +376,11 @@ class ViewConeUtility extends Utilities {
@override
Widget createWidget(
{String? id,
bool isAlly = true,
double? rotation,
double? length,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
Expand All @@ -338,6 +404,7 @@ class ViewConeUtility extends Utilities {
double? length,
double? rotation,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters}) {
Expand All @@ -363,6 +430,7 @@ class ViewConeUtility extends Utilities {
{double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
double? abilitySize,
double? mapScale}) {
return Offset(
ViewConeWidget.totalWidthVirtual,
Expand Down Expand Up @@ -403,9 +471,11 @@ class CustomCircleUtility extends Utilities {
@override
Widget createWidget(
{String? id,
bool isAlly = true,
double? rotation,
double? length,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
Expand All @@ -432,6 +502,7 @@ class CustomCircleUtility extends Utilities {
double? length,
double? rotation,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters}) {
Expand All @@ -445,6 +516,7 @@ class CustomCircleUtility extends Utilities {
{double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
double? abilitySize,
double? mapScale}) {
assert(mapScale != null, 'mapScale must be provided');
final diameter = maxDiameterInVirtual(mapScale!);
Expand All @@ -456,9 +528,11 @@ class CustomRectangleUtility extends Utilities {
@override
Widget createWidget(
{String? id,
bool isAlly = true,
double? rotation,
double? length,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
Expand Down Expand Up @@ -486,6 +560,7 @@ class CustomRectangleUtility extends Utilities {
double? length,
double? rotation,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters}) {
Expand All @@ -503,6 +578,7 @@ class CustomRectangleUtility extends Utilities {
{double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
double? abilitySize,
double? mapScale}) {
assert(widthMeters != null, 'widthMeters must be provided');
assert(rectLengthMeters != null, 'rectLengthMeters must be provided');
Expand All @@ -513,3 +589,60 @@ class CustomRectangleUtility extends Utilities {
return Offset(rectLength, width);
}
}

class RoleIconUtility extends Utilities {
final String imagePath;

RoleIconUtility({required this.imagePath});

@override
Widget createWidget({
String? id,
bool isAlly = true,
double? rotation,
double? length,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
bool showCenterMarker = true,
int? colorValue,
int? opacityPercent,
}) {
assert(abilitySize != null, 'abilitySize must be provided');
return RoleIconUtilityWidget(
imagePath: imagePath,
isAlly: isAlly,
size: abilitySize!,
Comment thread
SunkenInTime marked this conversation as resolved.
id: id,
);
}

@override
Offset getAnchorPoint({
String? id,
double? length,
double? rotation,
double? mapScale,
double? abilitySize,
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
}) {
assert(abilitySize != null, 'abilitySize must be provided');
return Offset(abilitySize! / 2, abilitySize / 2);
}

@override
Offset getSize({
double? diameterMeters,
double? widthMeters,
double? rectLengthMeters,
double? abilitySize,
double? mapScale,
}) {
assert(abilitySize != null, 'abilitySize must be provided');
return Offset(abilitySize!, abilitySize);
}
Comment thread
SunkenInTime marked this conversation as resolved.
}
Loading
Loading