Skip to content

Commit

Permalink
Merge pull request #65 from gabber235/develop
Browse files Browse the repository at this point in the history
V0.3.1 Simple Bugfixes
  • Loading branch information
gabber235 authored Aug 10, 2023
2 parents d79dcde + 39ffdc6 commit 7837238
Show file tree
Hide file tree
Showing 26 changed files with 485 additions and 210 deletions.
2 changes: 1 addition & 1 deletion adapters/BasicAdapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repositories {

dependencies {
compileOnly(kotlin("stdlib"))
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")

compileOnly("me.gabber235:typewriter:$version")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import me.gabber235.typewriter.utils.GenericPlayerStateProvider.LOCATION
import org.bukkit.GameMode
import org.bukkit.entity.Player
import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffect.INFINITE_DURATION
import org.bukkit.potion.PotionEffectType.BLINDNESS

@Entry("blinding_cinematic", "Blind the player so the screen looks black", Colors.CYAN, Icons.SOLID_EYE_SLASH)
Expand Down Expand Up @@ -64,10 +65,10 @@ class BlindingCinematicAction(

override suspend fun startSegment(segment: BlindingSegment) {
super.startSegment(segment)
state = player.state(LOCATION, GAME_MODE)
state = player.state(LOCATION, GAME_MODE, EffectStateProvider(BLINDNESS))

withContext(plugin.minecraftDispatcher) {
player.addPotionEffect(PotionEffect(BLINDNESS, Int.MAX_VALUE, 0, false, false, false))
player.addPotionEffect(PotionEffect(BLINDNESS, INFINITE_DURATION, 0, false, false, false))

if (segment.teleport) {
/// Teleport the player high up to prevent them from seeing the world
Expand All @@ -85,9 +86,7 @@ class BlindingCinematicAction(
val state = state ?: return
this.state = null
withContext(plugin.minecraftDispatcher) {
player.removePotionEffect(BLINDNESS)
player.restore(state)
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import me.gabber235.typewriter.utils.GenericPlayerStateProvider.*
import org.bukkit.Location
import org.bukkit.entity.EntityType
import org.bukkit.entity.Player
import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffect.INFINITE_DURATION
import org.bukkit.potion.PotionEffectType.INVISIBILITY

@Entry("camera_cinematic", "Create a cinematic camera path", Colors.CYAN, Icons.VIDEO)
/**
Expand Down Expand Up @@ -86,11 +89,19 @@ class CameraCinematicAction(
}
segments.forEach { it.setup() }

originalState = player.state(LOCATION, ALLOW_FLIGHT, FLYING, VISIBLE_PLAYERS, SHOWING_PLAYER)
originalState = player.state(
LOCATION,
ALLOW_FLIGHT,
FLYING,
VISIBLE_PLAYERS,
SHOWING_PLAYER,
EffectStateProvider(INVISIBILITY)
)

withContext(plugin.minecraftDispatcher) {
player.allowFlight = true
player.isFlying = true
player.addPotionEffect(PotionEffect(INVISIBILITY, INFINITE_DURATION, 0, false, false))
server.onlinePlayers.forEach {
it.hidePlayer(plugin, player)
player.hidePlayer(plugin, it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package me.gabber235.typewriter.entries.cinematic

import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher
import kotlinx.coroutines.withContext
import me.gabber235.typewriter.adapters.modifiers.Colored
import me.gabber235.typewriter.adapters.modifiers.Help
import me.gabber235.typewriter.adapters.modifiers.Placeholder
import me.gabber235.typewriter.entry.dialogue.playSpeakerSound
import me.gabber235.typewriter.entry.entries.*
import me.gabber235.typewriter.extensions.placeholderapi.parsePlaceholders
import me.gabber235.typewriter.utils.GenericPlayerStateProvider
import me.gabber235.typewriter.plugin
import me.gabber235.typewriter.utils.GenericPlayerStateProvider.EXP
import me.gabber235.typewriter.utils.GenericPlayerStateProvider.LEVEL
import me.gabber235.typewriter.utils.PlayerState
import me.gabber235.typewriter.utils.restore
import me.gabber235.typewriter.utils.state
Expand Down Expand Up @@ -52,7 +56,7 @@ class DisplayDialogueCinematicAction(

override suspend fun setup() {
super.setup()
state = player.state(GenericPlayerStateProvider.EXP, GenericPlayerStateProvider.LEVEL)
state = player.state(EXP, LEVEL)
player.exp = 0f
player.level = 0
setup?.invoke(player)
Expand Down Expand Up @@ -91,9 +95,11 @@ class DisplayDialogueCinematicAction(

override suspend fun teardown() {
super.teardown()
player.restore(state)
teardown?.invoke(player)
reset?.invoke(player)
withContext(plugin.minecraftDispatcher) {
player.restore(state)
}
}

override fun canFinish(frame: Int): Boolean = segments canFinishAt frame
Expand Down
2 changes: 1 addition & 1 deletion adapters/CitizensAdapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {

dependencies {
compileOnly(kotlin("stdlib"))
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")

compileOnly("me.gabber235:typewriter:$version")

Expand Down
2 changes: 1 addition & 1 deletion adapters/CombatLogXAdapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {

dependencies {
compileOnly(kotlin("stdlib"))
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")

compileOnly("me.gabber235:typewriter:$version")

Expand Down
6 changes: 6 additions & 0 deletions app/lib/models/adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ extension FieldTypeExtension on FieldInfo {

/// If the [ObjectEditor] needs to show a default layout or if a field declares a custom layout.
bool get hasCustomLayout {
if (this is CustomField) {
final editor = (this as CustomField).editor;
if (editor == "optional") {
return true;
}
}
if (this is ObjectField) {
return true;
}
Expand Down
25 changes: 25 additions & 0 deletions app/lib/utils/color_filter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "package:flutter/material.dart";

// https://api.flutter.dev/flutter/dart-ui/ColorFilter/ColorFilter.matrix.html
const ColorFilter greyscale = ColorFilter.matrix(<double>[
0.2126,
0.7152,
0.0722,
0,
0,
0.2126,
0.7152,
0.0722,
0,
0,
0.2126,
0.7152,
0.0722,
0,
0,
0,
0,
0,
1,
0,
]);
5 changes: 5 additions & 0 deletions app/lib/widgets/components/general/toasts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class ToastDisplay extends HookConsumerWidget {
bottom: 0,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (final toast in toasts)
if (toast is TemporaryToast)
Expand Down Expand Up @@ -259,6 +260,10 @@ class _TemporaryToast extends HookConsumerWidget {
return Card(
color: toast.color,
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
clipBehavior: Clip.antiAlias,
child: SizedBox(
width: width,
child: Column(
Expand Down
120 changes: 96 additions & 24 deletions app/lib/widgets/inspector/editors/optional.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import "package:flutter/material.dart";
import "package:typewriter/utils/color_filter.dart";
import "package:flutter_animate/flutter_animate.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:typewriter/models/adapter.dart";
import "package:typewriter/utils/passing_reference.dart";
import "package:typewriter/widgets/inspector/editors.dart";
import "package:typewriter/widgets/inspector/editors/field.dart";
import "package:typewriter/widgets/inspector/header.dart";
import "package:typewriter/widgets/inspector/inspector.dart";

class OptionalEditorFilter extends EditorFilter {
@override
bool canEdit(FieldInfo info) => info is CustomField && info.editor == "optional";
bool canEdit(FieldInfo info) =>
info is CustomField && info.editor == "optional";

@override
Widget build(String path, FieldInfo info) => OptionalEditor(path: path, field: info as CustomField);
Widget build(String path, FieldInfo info) =>
OptionalEditor(path: path, field: info as CustomField);
}

class OptionalEditor extends HookConsumerWidget {
Expand Down Expand Up @@ -44,32 +48,100 @@ class OptionalEditor extends HookConsumerWidget {
);
}

return Row(
children: [
Checkbox(
value: enabled,
onChanged: (value) {
ref.read(inspectingEntryDefinitionProvider)?.updateField(ref.passing, "$path.enabled", value ?? false);
},
),
Expanded(
child: AnimatedOpacity(
opacity: enabled ? 1 : 0.6,
duration: 200.ms,
curve: Curves.easeOut,
child: MouseRegion(
cursor: enabled ? MouseCursor.defer : SystemMouseCursors.forbidden,
child: AbsorbPointer(
absorbing: !enabled,
child: FieldEditor(
path: "$path.value",
type: subField,
final subPath = "$path.value";
final headerActionFilters = ref.watch(headerActionFiltersProvider);
final subFieldActions = headerActionFilters
.where((filter) => filter.shouldShow(subPath, subField))
.toList();

return FieldHeader(
field: field,
path: path,
leading: _buildActions(
HeaderActionLocation.leading,
subFieldActions,
subPath,
subField,
enabled: enabled,
),
trailing: _buildActions(
HeaderActionLocation.trailing,
subFieldActions,
subPath,
subField,
enabled: enabled,
),
actions: _buildActions(
HeaderActionLocation.actions,
subFieldActions,
subPath,
subField,
enabled: enabled,
),
child: Row(
children: [
Checkbox(
value: enabled,
onChanged: (value) {
ref
.read(inspectingEntryDefinitionProvider)
?.updateField(ref.passing, "$path.enabled", value ?? false);
},
),
Expanded(
child: AnimatedOpacity(
opacity: enabled ? 1 : 0.6,
duration: 200.ms,
curve: Curves.easeOut,
child: MouseRegion(
cursor:
enabled ? MouseCursor.defer : SystemMouseCursors.forbidden,
child: AbsorbPointer(
absorbing: !enabled,
child: FieldEditor(
path: "$path.value",
type: subField,
),
),
),
),
),
),
],
],
),
);
}

List<Widget> _buildActions(
HeaderActionLocation location,
List<HeaderActionFilter> actions,
String path,
FieldInfo field, {
bool enabled = true,
}) {
final children = actions
.where((action) => action.location(path, field) == location)
.map((action) => action.build(path, field))
.toList();
if (enabled) {
return children;
}

return [
for (final child in children)
MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: AbsorbPointer(
child: AnimatedOpacity(
opacity: 0.6,
duration: 200.ms,
curve: Curves.easeOut,
child: ColorFiltered(
colorFilter: greyscale,
child: child,
),
),
),
),
];
}
}
4 changes: 2 additions & 2 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ packages:
dependency: "direct main"
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
collection_ext:
dependency: "direct main"
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.gabber235.typewriter.adapters
import com.google.gson.GsonBuilder
import com.google.gson.JsonArray
import com.google.gson.reflect.TypeToken
import me.gabber235.typewriter.adapters.editors.LocationFieldCapturer
import me.gabber235.typewriter.capture.Capturer
import me.gabber235.typewriter.capture.CapturerCreator
import me.gabber235.typewriter.entry.dialogue.DialogueMessenger
Expand Down Expand Up @@ -35,6 +36,12 @@ private val gson =
).enableComplexMapKeySerialization()
.create()

val staticCaptureClasses by lazy {
listOf(
LocationFieldCapturer::class,
)
}

interface AdapterLoader {
val adapters: List<AdapterData>
val adaptersJson: JsonArray
Expand Down Expand Up @@ -173,7 +180,7 @@ class AdapterLoaderImpl : AdapterLoader, KoinComponent {
private fun constructCapturers(captureClasses: List<Class<*>>) =
captureClasses.map { captureClass ->
captureClass.kotlin as KClass<out Capturer<*>>
}
} + staticCaptureClasses

//TODO: Make compatible with java.
private fun findFilterForMessenger(messengerClass: Class<*>) =
Expand Down
Loading

0 comments on commit 7837238

Please sign in to comment.